@@ -4,7 +4,6 @@ use crate::ty::{self, TyCtxt};
4
4
use rustc_data_structures:: fx:: FxIndexMap ;
5
5
use rustc_errors:: ErrorReported ;
6
6
use rustc_hir:: def_id:: { DefId , DefIdMap } ;
7
- use rustc_span:: symbol:: Ident ;
8
7
9
8
/// A per-trait graph of impls in specialization order. At the moment, this
10
9
/// graph forms a tree rooted with the trait itself, with all other nodes
@@ -75,34 +74,28 @@ pub enum Node {
75
74
Trait ( DefId ) ,
76
75
}
77
76
78
- impl < ' tcx > Node {
77
+ impl Node {
79
78
pub fn is_from_trait ( & self ) -> bool {
80
79
matches ! ( self , Node :: Trait ( ..) )
81
80
}
82
81
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.
89
84
///
90
85
/// If this returns `None`, the item can potentially still be found in
91
86
/// parents of this node.
92
- pub fn item (
87
+ pub fn item < ' tcx > (
93
88
& self ,
94
89
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
+ }
106
99
}
107
100
108
101
pub fn def_id ( & self ) -> DefId {
@@ -181,17 +174,11 @@ impl LeafDef {
181
174
impl < ' tcx > Ancestors < ' tcx > {
182
175
/// Finds the bottom-most (ie. most specialized) definition of an associated
183
176
/// 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 > {
191
178
let mut finalizing_node = None ;
192
179
193
180
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 ) {
195
182
if finalizing_node. is_none ( ) {
196
183
let is_specializable = item. defaultness . is_default ( )
197
184
|| tcx. impl_defaultness ( node. def_id ( ) ) . is_default ( ) ;
@@ -201,7 +188,7 @@ impl<'tcx> Ancestors<'tcx> {
201
188
}
202
189
}
203
190
204
- Some ( LeafDef { item, defining_node : node, finalizing_node } )
191
+ Some ( LeafDef { item : * item , defining_node : node, finalizing_node } )
205
192
} else {
206
193
// Item not mentioned. This "finalizes" any defaulted item provided by an ancestor.
207
194
finalizing_node = Some ( node) ;
0 commit comments