@@ -4,7 +4,6 @@ use crate::ty::{self, TyCtxt};
44use rustc_data_structures:: fx:: FxIndexMap ;
55use rustc_errors:: ErrorReported ;
66use rustc_hir:: def_id:: { DefId , DefIdMap } ;
7- use rustc_span:: symbol:: Ident ;
87
98/// A per-trait graph of impls in specialization order. At the moment, this
109/// graph forms a tree rooted with the trait itself, with all other nodes
@@ -75,34 +74,28 @@ pub enum Node {
7574 Trait ( DefId ) ,
7675}
7776
78- impl < ' tcx > Node {
77+ impl Node {
7978 pub fn is_from_trait ( & self ) -> bool {
8079 matches ! ( self , Node :: Trait ( ..) )
8180 }
8281
83- /// Iterate over the items defined directly by the given (impl or trait) node.
84- pub fn items ( & self , tcx : TyCtxt < ' tcx > ) -> impl ' tcx + Iterator < Item = & ' tcx ty:: AssocItem > {
85- tcx. associated_items ( self . def_id ( ) ) . in_definition_order ( )
86- }
87-
88- /// Finds an associated item defined in this node.
82+ /// Trys to find the associated item that implements `trait_item_def_id`
83+ /// defined in this node.
8984 ///
9085 /// If this returns `None`, the item can potentially still be found in
9186 /// parents of this node.
92- pub fn item (
87+ pub fn item < ' tcx > (
9388 & self ,
9489 tcx : TyCtxt < ' tcx > ,
95- trait_item_name : Ident ,
96- trait_item_kind : ty:: AssocKind ,
97- trait_def_id : DefId ,
98- ) -> Option < ty:: AssocItem > {
99- tcx. associated_items ( self . def_id ( ) )
100- . filter_by_name_unhygienic ( trait_item_name. name )
101- . find ( move |impl_item| {
102- trait_item_kind == impl_item. kind
103- && tcx. hygienic_eq ( impl_item. ident , trait_item_name, trait_def_id)
104- } )
105- . copied ( )
90+ trait_item_def_id : DefId ,
91+ ) -> Option < & ' tcx ty:: AssocItem > {
92+ match * self {
93+ Node :: Trait ( _) => Some ( tcx. associated_item ( trait_item_def_id) ) ,
94+ Node :: Impl ( impl_def_id) => {
95+ let id = tcx. impl_item_implementor_ids ( impl_def_id) . get ( & trait_item_def_id) ?;
96+ Some ( tcx. associated_item ( * id) )
97+ }
98+ }
10699 }
107100
108101 pub fn def_id ( & self ) -> DefId {
@@ -181,17 +174,11 @@ impl LeafDef {
181174impl < ' tcx > Ancestors < ' tcx > {
182175 /// Finds the bottom-most (ie. most specialized) definition of an associated
183176 /// item.
184- pub fn leaf_def (
185- mut self ,
186- tcx : TyCtxt < ' tcx > ,
187- trait_item_name : Ident ,
188- trait_item_kind : ty:: AssocKind ,
189- ) -> Option < LeafDef > {
190- let trait_def_id = self . trait_def_id ;
177+ pub fn leaf_def ( mut self , tcx : TyCtxt < ' tcx > , trait_item_def_id : DefId ) -> Option < LeafDef > {
191178 let mut finalizing_node = None ;
192179
193180 self . find_map ( |node| {
194- if let Some ( item) = node. item ( tcx, trait_item_name , trait_item_kind , trait_def_id ) {
181+ if let Some ( item) = node. item ( tcx, trait_item_def_id ) {
195182 if finalizing_node. is_none ( ) {
196183 let is_specializable = item. defaultness . is_default ( )
197184 || tcx. impl_defaultness ( node. def_id ( ) ) . is_default ( ) ;
@@ -201,7 +188,7 @@ impl<'tcx> Ancestors<'tcx> {
201188 }
202189 }
203190
204- Some ( LeafDef { item, defining_node : node, finalizing_node } )
191+ Some ( LeafDef { item : * item , defining_node : node, finalizing_node } )
205192 } else {
206193 // Item not mentioned. This "finalizes" any defaulted item provided by an ancestor.
207194 finalizing_node = Some ( node) ;
0 commit comments