2016-02-16 10:36:47 -08:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2017-08-29 09:25:25 -07:00
|
|
|
use super::OverlapError;
|
2016-02-16 10:36:47 -08:00
|
|
|
|
2016-03-29 12:54:26 +03:00
|
|
|
use hir::def_id::DefId;
|
2017-08-14 18:19:42 +02:00
|
|
|
use ich::{self, StableHashingContext};
|
|
|
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
|
|
|
|
StableHasherResult};
|
2017-05-23 04:19:47 -04:00
|
|
|
use traits;
|
2017-05-11 16:01:19 +02:00
|
|
|
use ty::{self, TyCtxt, TypeFoldable};
|
2016-04-05 08:38:48 -07:00
|
|
|
use ty::fast_reject::{self, SimplifiedType};
|
2018-02-27 17:11:14 +01:00
|
|
|
use rustc_data_structures::sync::Lrc;
|
2018-06-10 22:24:24 +03:00
|
|
|
use syntax::ast::Ident;
|
2018-03-15 16:17:27 -04:00
|
|
|
use util::captures::Captures;
|
2016-11-08 14:02:55 +11:00
|
|
|
use util::nodemap::{DefIdMap, FxHashMap};
|
2016-02-16 10:36:47 -08:00
|
|
|
|
|
|
|
/// A per-trait graph of impls in specialization order. At the moment, this
|
|
|
|
/// graph forms a tree rooted with the trait itself, with all other nodes
|
|
|
|
/// representing impls, and parent-child relationships representing
|
|
|
|
/// specializations.
|
|
|
|
///
|
|
|
|
/// The graph provides two key services:
|
|
|
|
///
|
|
|
|
/// - Construction, which implicitly checks for overlapping impls (i.e., impls
|
|
|
|
/// that overlap but where neither specializes the other -- an artifact of the
|
|
|
|
/// simple "chain" rule.
|
|
|
|
///
|
|
|
|
/// - Parent extraction. In particular, the graph can give you the *immediate*
|
|
|
|
/// parents of a given specializing impl, which is needed for extracting
|
2017-08-11 00:16:18 +02:00
|
|
|
/// default items amongst other things. In the simple "chain" rule, every impl
|
2016-02-16 10:36:47 -08:00
|
|
|
/// has at most one parent.
|
2018-03-13 21:36:49 -04:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2016-02-16 10:36:47 -08:00
|
|
|
pub struct Graph {
|
|
|
|
// all impls have a parent; the "root" impls have as their parent the def_id
|
|
|
|
// of the trait
|
|
|
|
parent: DefIdMap<DefId>,
|
|
|
|
|
|
|
|
// the "root" impls are found by looking up the trait's def_id.
|
2016-04-05 08:38:48 -07:00
|
|
|
children: DefIdMap<Children>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Children of a given impl, grouped into blanket/non-blanket varieties as is
|
|
|
|
/// done in `TraitDef`.
|
2018-03-13 21:36:49 -04:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2016-04-05 08:38:48 -07:00
|
|
|
struct Children {
|
|
|
|
// Impls of a trait (or specializations of a given impl). To allow for
|
|
|
|
// quicker lookup, the impls are indexed by a simplified version of their
|
|
|
|
// `Self` type: impls with a simplifiable `Self` are stored in
|
|
|
|
// `nonblanket_impls` keyed by it, while all other impls are stored in
|
|
|
|
// `blanket_impls`.
|
|
|
|
//
|
|
|
|
// A similar division is used within `TraitDef`, but the lists there collect
|
|
|
|
// together *all* the impls for a trait, and are populated prior to building
|
|
|
|
// the specialization graph.
|
|
|
|
|
|
|
|
/// Impls of the trait.
|
2016-11-08 14:02:55 +11:00
|
|
|
nonblanket_impls: FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>,
|
2016-04-05 08:38:48 -07:00
|
|
|
|
|
|
|
/// Blanket impls associated with the trait.
|
|
|
|
blanket_impls: Vec<DefId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The result of attempting to insert an impl into a group of children.
|
2016-03-25 05:22:44 +02:00
|
|
|
enum Inserted {
|
2016-04-05 08:38:48 -07:00
|
|
|
/// The impl was inserted as a new child in this group of children.
|
2017-11-23 19:05:23 +02:00
|
|
|
BecameNewSibling(Option<OverlapError>),
|
2016-04-05 08:38:48 -07:00
|
|
|
|
|
|
|
/// The impl replaced an existing impl that specializes it.
|
|
|
|
Replaced(DefId),
|
|
|
|
|
|
|
|
/// The impl is a specialization of an existing child.
|
|
|
|
ShouldRecurseOn(DefId),
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
impl<'a, 'gcx, 'tcx> Children {
|
2016-04-05 08:38:48 -07:00
|
|
|
fn new() -> Children {
|
|
|
|
Children {
|
2016-11-08 14:02:55 +11:00
|
|
|
nonblanket_impls: FxHashMap(),
|
2016-04-05 08:38:48 -07:00
|
|
|
blanket_impls: vec![],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Insert an impl into this set of children without comparing to any existing impls
|
2016-05-03 05:23:22 +03:00
|
|
|
fn insert_blindly(&mut self,
|
2016-04-29 06:00:23 +03:00
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
2016-05-03 05:23:22 +03:00
|
|
|
impl_def_id: DefId) {
|
2016-04-05 08:38:48 -07:00
|
|
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
|
|
|
if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) {
|
|
|
|
self.nonblanket_impls.entry(sty).or_insert(vec![]).push(impl_def_id)
|
|
|
|
} else {
|
|
|
|
self.blanket_impls.push(impl_def_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Attempt to insert an impl into this set of children, while comparing for
|
2017-08-11 20:34:14 +02:00
|
|
|
/// specialization relationships.
|
2016-05-03 04:56:42 +03:00
|
|
|
fn insert(&mut self,
|
2016-04-29 06:00:23 +03:00
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
2016-05-03 04:56:42 +03:00
|
|
|
impl_def_id: DefId,
|
|
|
|
simplified_self: Option<SimplifiedType>)
|
2016-03-25 05:22:44 +02:00
|
|
|
-> Result<Inserted, OverlapError>
|
2016-04-05 08:38:48 -07:00
|
|
|
{
|
2017-11-23 19:05:23 +02:00
|
|
|
let mut last_lint = None;
|
|
|
|
|
2016-04-05 08:38:48 -07:00
|
|
|
for slot in match simplified_self {
|
|
|
|
Some(sty) => self.filtered_mut(sty),
|
|
|
|
None => self.iter_mut(),
|
|
|
|
} {
|
|
|
|
let possible_sibling = *slot;
|
|
|
|
|
2017-11-23 19:05:23 +02:00
|
|
|
let overlap_error = |overlap: traits::coherence::OverlapResult| {
|
|
|
|
// overlap, but no specialization; error out
|
|
|
|
let trait_ref = overlap.impl_header.trait_ref.unwrap();
|
|
|
|
let self_ty = trait_ref.self_ty();
|
|
|
|
OverlapError {
|
|
|
|
with_impl: possible_sibling,
|
|
|
|
trait_desc: trait_ref.to_string(),
|
|
|
|
// only report the Self type if it has at least
|
|
|
|
// some outer concrete shell; otherwise, it's
|
|
|
|
// not adding much information.
|
|
|
|
self_desc: if self_ty.has_concrete_skeleton() {
|
|
|
|
Some(self_ty.to_string())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
|
|
|
intercrate_ambiguity_causes: overlap.intercrate_ambiguity_causes,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
let tcx = tcx.global_tcx();
|
2018-01-29 17:40:13 -05:00
|
|
|
let (le, ge) = traits::overlapping_impls(
|
|
|
|
tcx,
|
|
|
|
possible_sibling,
|
|
|
|
impl_def_id,
|
|
|
|
traits::IntercrateMode::Issue43355,
|
|
|
|
|overlap| {
|
|
|
|
if tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) {
|
|
|
|
return Ok((false, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
let le = tcx.specializes((impl_def_id, possible_sibling));
|
|
|
|
let ge = tcx.specializes((possible_sibling, impl_def_id));
|
|
|
|
|
|
|
|
if le == ge {
|
|
|
|
Err(overlap_error(overlap))
|
|
|
|
} else {
|
|
|
|
Ok((le, ge))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|| Ok((false, false)),
|
|
|
|
)?;
|
2016-04-05 08:38:48 -07:00
|
|
|
|
2016-03-25 05:22:44 +02:00
|
|
|
if le && !ge {
|
|
|
|
debug!("descending as child of TraitRef {:?}",
|
|
|
|
tcx.impl_trait_ref(possible_sibling).unwrap());
|
2016-04-05 08:38:48 -07:00
|
|
|
|
2016-03-25 05:22:44 +02:00
|
|
|
// the impl specializes possible_sibling
|
|
|
|
return Ok(Inserted::ShouldRecurseOn(possible_sibling));
|
|
|
|
} else if ge && !le {
|
|
|
|
debug!("placing as parent of TraitRef {:?}",
|
|
|
|
tcx.impl_trait_ref(possible_sibling).unwrap());
|
2016-04-05 08:38:48 -07:00
|
|
|
|
|
|
|
// possible_sibling specializes the impl
|
|
|
|
*slot = impl_def_id;
|
2016-03-25 05:22:44 +02:00
|
|
|
return Ok(Inserted::Replaced(possible_sibling));
|
|
|
|
} else {
|
2017-11-23 19:05:23 +02:00
|
|
|
if !tcx.impls_are_allowed_to_overlap(impl_def_id, possible_sibling) {
|
2018-01-29 17:40:13 -05:00
|
|
|
traits::overlapping_impls(
|
|
|
|
tcx,
|
|
|
|
possible_sibling,
|
|
|
|
impl_def_id,
|
|
|
|
traits::IntercrateMode::Fixed,
|
|
|
|
|overlap| last_lint = Some(overlap_error(overlap)),
|
|
|
|
|| (),
|
|
|
|
);
|
2017-11-23 19:05:23 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 05:22:44 +02:00
|
|
|
// no overlap (error bailed already via ?)
|
2016-04-05 08:38:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no overlap with any potential siblings, so add as a new sibling
|
|
|
|
debug!("placing as new sibling");
|
|
|
|
self.insert_blindly(tcx, impl_def_id);
|
2017-11-23 19:05:23 +02:00
|
|
|
Ok(Inserted::BecameNewSibling(last_lint))
|
2016-04-05 08:38:48 -07:00
|
|
|
}
|
|
|
|
|
2018-02-23 09:53:00 -08:00
|
|
|
fn iter_mut(&'a mut self) -> Box<dyn Iterator<Item = &'a mut DefId> + 'a> {
|
2016-04-05 08:38:48 -07:00
|
|
|
let nonblanket = self.nonblanket_impls.iter_mut().flat_map(|(_, v)| v.iter_mut());
|
|
|
|
Box::new(self.blanket_impls.iter_mut().chain(nonblanket))
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:56:42 +03:00
|
|
|
fn filtered_mut(&'a mut self, sty: SimplifiedType)
|
2018-02-23 09:53:00 -08:00
|
|
|
-> Box<dyn Iterator<Item = &'a mut DefId> + 'a> {
|
2016-04-05 08:38:48 -07:00
|
|
|
let nonblanket = self.nonblanket_impls.entry(sty).or_insert(vec![]).iter_mut();
|
|
|
|
Box::new(self.blanket_impls.iter_mut().chain(nonblanket))
|
|
|
|
}
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
impl<'a, 'gcx, 'tcx> Graph {
|
2016-02-16 10:36:47 -08:00
|
|
|
pub fn new() -> Graph {
|
|
|
|
Graph {
|
|
|
|
parent: Default::default(),
|
|
|
|
children: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Insert a local impl into the specialization graph. If an existing impl
|
|
|
|
/// conflicts with it (has overlap, but neither specializes the other),
|
|
|
|
/// information about the area of overlap is returned in the `Err`.
|
2016-05-03 04:56:42 +03:00
|
|
|
pub fn insert(&mut self,
|
2016-04-29 06:00:23 +03:00
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
2016-05-03 04:56:42 +03:00
|
|
|
impl_def_id: DefId)
|
2017-11-23 19:05:23 +02:00
|
|
|
-> Result<Option<OverlapError>, OverlapError> {
|
2016-02-16 10:36:47 -08:00
|
|
|
assert!(impl_def_id.is_local());
|
|
|
|
|
|
|
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
|
|
|
let trait_def_id = trait_ref.def_id;
|
|
|
|
|
2016-03-08 15:23:52 -08:00
|
|
|
debug!("insert({:?}): inserting TraitRef {:?} into specialization graph",
|
|
|
|
impl_def_id, trait_ref);
|
2016-02-22 22:21:37 -08:00
|
|
|
|
2016-02-16 10:36:47 -08:00
|
|
|
// if the reference itself contains an earlier error (e.g., due to a
|
|
|
|
// resolution failure), then we just insert the impl at the top level of
|
2017-08-11 20:34:14 +02:00
|
|
|
// the graph and claim that there's no overlap (in order to suppress
|
2016-02-16 10:36:47 -08:00
|
|
|
// bogus errors).
|
|
|
|
if trait_ref.references_error() {
|
2016-03-08 15:23:52 -08:00
|
|
|
debug!("insert: inserting dummy node for erroneous TraitRef {:?}, \
|
2016-02-16 10:36:47 -08:00
|
|
|
impl_def_id={:?}, trait_def_id={:?}",
|
|
|
|
trait_ref, impl_def_id, trait_def_id);
|
|
|
|
|
|
|
|
self.parent.insert(impl_def_id, trait_def_id);
|
2016-04-05 08:38:48 -07:00
|
|
|
self.children.entry(trait_def_id).or_insert(Children::new())
|
|
|
|
.insert_blindly(tcx, impl_def_id);
|
2017-11-23 19:05:23 +02:00
|
|
|
return Ok(None);
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut parent = trait_def_id;
|
2017-11-23 19:05:23 +02:00
|
|
|
let mut last_lint = None;
|
2016-04-05 08:38:48 -07:00
|
|
|
let simplified = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false);
|
|
|
|
|
|
|
|
// Descend the specialization tree, where `parent` is the current parent node
|
|
|
|
loop {
|
2016-03-25 05:22:44 +02:00
|
|
|
use self::Inserted::*;
|
2016-02-16 10:36:47 -08:00
|
|
|
|
2016-04-05 08:38:48 -07:00
|
|
|
let insert_result = self.children.entry(parent).or_insert(Children::new())
|
2016-03-25 05:22:44 +02:00
|
|
|
.insert(tcx, impl_def_id, simplified)?;
|
2016-04-05 08:38:48 -07:00
|
|
|
|
|
|
|
match insert_result {
|
2017-11-23 19:05:23 +02:00
|
|
|
BecameNewSibling(opt_lint) => {
|
|
|
|
last_lint = opt_lint;
|
2016-04-05 08:38:48 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Replaced(new_child) => {
|
|
|
|
self.parent.insert(new_child, impl_def_id);
|
|
|
|
let mut new_children = Children::new();
|
|
|
|
new_children.insert_blindly(tcx, new_child);
|
|
|
|
self.children.insert(impl_def_id, new_children);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ShouldRecurseOn(new_parent) => {
|
|
|
|
parent = new_parent;
|
|
|
|
}
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 08:38:48 -07:00
|
|
|
self.parent.insert(impl_def_id, parent);
|
2017-11-23 19:05:23 +02:00
|
|
|
Ok(last_lint)
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Insert cached metadata mapping from a child impl back to its parent.
|
2016-05-03 05:23:22 +03:00
|
|
|
pub fn record_impl_from_cstore(&mut self,
|
2016-04-29 06:00:23 +03:00
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
2016-05-03 05:23:22 +03:00
|
|
|
parent: DefId,
|
|
|
|
child: DefId) {
|
2016-02-16 10:36:47 -08:00
|
|
|
if self.parent.insert(child, parent).is_some() {
|
2016-03-26 19:59:04 +01:00
|
|
|
bug!("When recording an impl from the crate store, information about its parent \
|
|
|
|
was already present.");
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
|
2016-04-05 08:38:48 -07:00
|
|
|
self.children.entry(parent).or_insert(Children::new()).insert_blindly(tcx, child);
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The parent of a given impl, which is the def id of the trait when the
|
|
|
|
/// impl is a "specialization root".
|
|
|
|
pub fn parent(&self, child: DefId) -> DefId {
|
|
|
|
*self.parent.get(&child).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A node in the specialization graph is either an impl or a trait
|
|
|
|
/// definition; either can serve as a source of item definitions.
|
|
|
|
/// There is always exactly one trait definition node: the root.
|
2016-03-08 15:23:52 -08:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
2016-02-16 10:36:47 -08:00
|
|
|
pub enum Node {
|
|
|
|
Impl(DefId),
|
|
|
|
Trait(DefId),
|
|
|
|
}
|
|
|
|
|
2016-04-29 06:00:23 +03:00
|
|
|
impl<'a, 'gcx, 'tcx> Node {
|
2016-02-16 10:36:47 -08:00
|
|
|
pub fn is_from_trait(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
Node::Trait(..) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Iterate over the items defined directly by the given (impl or trait) node.
|
2018-03-15 16:17:27 -04:00
|
|
|
pub fn items(
|
|
|
|
&self,
|
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
|
|
|
) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
|
2016-11-10 02:06:34 +02:00
|
|
|
tcx.associated_items(self.def_id())
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn def_id(&self) -> DefId {
|
|
|
|
match *self {
|
|
|
|
Node::Impl(did) => did,
|
|
|
|
Node::Trait(did) => did,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 16:01:19 +02:00
|
|
|
pub struct Ancestors {
|
|
|
|
trait_def_id: DefId,
|
2018-02-27 17:11:14 +01:00
|
|
|
specialization_graph: Lrc<Graph>,
|
2016-02-16 10:36:47 -08:00
|
|
|
current_source: Option<Node>,
|
|
|
|
}
|
|
|
|
|
2017-05-11 16:01:19 +02:00
|
|
|
impl Iterator for Ancestors {
|
2016-02-16 10:36:47 -08:00
|
|
|
type Item = Node;
|
|
|
|
fn next(&mut self) -> Option<Node> {
|
|
|
|
let cur = self.current_source.take();
|
|
|
|
if let Some(Node::Impl(cur_impl)) = cur {
|
2017-05-11 16:01:19 +02:00
|
|
|
let parent = self.specialization_graph.parent(cur_impl);
|
|
|
|
if parent == self.trait_def_id {
|
2016-02-16 10:36:47 -08:00
|
|
|
self.current_source = Some(Node::Trait(parent));
|
|
|
|
} else {
|
|
|
|
self.current_source = Some(Node::Impl(parent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct NodeItem<T> {
|
|
|
|
pub node: Node,
|
|
|
|
pub item: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> NodeItem<T> {
|
|
|
|
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> NodeItem<U> {
|
|
|
|
NodeItem {
|
|
|
|
node: self.node,
|
|
|
|
item: f(self.item),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 16:01:19 +02:00
|
|
|
impl<'a, 'gcx, 'tcx> Ancestors {
|
2016-11-10 02:06:34 +02:00
|
|
|
/// Search the items from the given ancestors, returning each definition
|
|
|
|
/// with the given name and the given kind.
|
|
|
|
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
|
2018-03-15 16:17:27 -04:00
|
|
|
pub fn defs(
|
|
|
|
self,
|
|
|
|
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
2018-06-10 22:24:24 +03:00
|
|
|
trait_item_name: Ident,
|
2018-03-15 16:17:27 -04:00
|
|
|
trait_item_kind: ty::AssociatedKind,
|
|
|
|
trait_def_id: DefId,
|
|
|
|
) -> impl Iterator<Item = NodeItem<ty::AssociatedItem>> + Captures<'gcx> + Captures<'tcx> + 'a {
|
2016-11-10 02:06:34 +02:00
|
|
|
self.flat_map(move |node| {
|
2017-09-26 02:49:34 +03:00
|
|
|
node.items(tcx).filter(move |impl_item| {
|
|
|
|
impl_item.kind == trait_item_kind &&
|
2018-06-10 22:24:24 +03:00
|
|
|
tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id)
|
2017-09-26 02:49:34 +03:00
|
|
|
}).map(move |item| NodeItem { node: node, item: item })
|
2016-11-10 02:06:34 +02:00
|
|
|
})
|
2016-02-16 10:36:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Walk up the specialization ancestors of a given impl, starting with that
|
|
|
|
/// impl itself.
|
2017-05-11 16:01:19 +02:00
|
|
|
pub fn ancestors(tcx: TyCtxt,
|
|
|
|
trait_def_id: DefId,
|
|
|
|
start_from_impl: DefId)
|
|
|
|
-> Ancestors {
|
|
|
|
let specialization_graph = tcx.specialization_graph_of(trait_def_id);
|
2016-02-16 10:36:47 -08:00
|
|
|
Ancestors {
|
2017-05-11 16:01:19 +02:00
|
|
|
trait_def_id,
|
|
|
|
specialization_graph,
|
2016-02-16 10:36:47 -08:00
|
|
|
current_source: Some(Node::Impl(start_from_impl)),
|
|
|
|
}
|
|
|
|
}
|
2017-08-14 18:19:42 +02:00
|
|
|
|
2018-01-16 10:16:38 +01:00
|
|
|
impl<'a> HashStable<StableHashingContext<'a>> for Children {
|
2017-08-14 18:19:42 +02:00
|
|
|
fn hash_stable<W: StableHasherResult>(&self,
|
2018-01-16 10:16:38 +01:00
|
|
|
hcx: &mut StableHashingContext<'a>,
|
2017-08-14 18:19:42 +02:00
|
|
|
hasher: &mut StableHasher<W>) {
|
|
|
|
let Children {
|
|
|
|
ref nonblanket_impls,
|
|
|
|
ref blanket_impls,
|
|
|
|
} = *self;
|
|
|
|
|
|
|
|
ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, nonblanket_impls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 18:20:27 +02:00
|
|
|
impl_stable_hash_for!(struct self::Graph {
|
|
|
|
parent,
|
|
|
|
children
|
|
|
|
});
|