8
8
use RibKind :: * ;
9
9
10
10
use crate :: { path_names_to_string, BindingError , CrateLint , LexicalScopeBinding } ;
11
- use crate :: { Module , ModuleOrUniformRoot , NameBindingKind , ParentScope , PathResult } ;
11
+ use crate :: { Module , ModuleOrUniformRoot , ParentScope , PathResult } ;
12
12
use crate :: { ResolutionError , Resolver , Segment , UseError } ;
13
13
14
14
use rustc_ast:: ptr:: P ;
@@ -24,7 +24,6 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
24
24
use rustc_hir:: TraitCandidate ;
25
25
use rustc_middle:: { bug, span_bug} ;
26
26
use rustc_session:: lint;
27
- use rustc_span:: def_id:: LocalDefId ;
28
27
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
29
28
use rustc_span:: Span ;
30
29
use smallvec:: { smallvec, SmallVec } ;
@@ -2342,95 +2341,31 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2342
2341
ident. span = ident. span . normalize_to_macros_2_0 ( ) ;
2343
2342
let mut search_module = self . parent_scope . module ;
2344
2343
loop {
2345
- self . get_traits_in_module_containing_item ( ident, ns, search_module, & mut found_traits) ;
2344
+ self . r . get_traits_in_module_containing_item (
2345
+ ident,
2346
+ ns,
2347
+ search_module,
2348
+ & mut found_traits,
2349
+ & self . parent_scope ,
2350
+ ) ;
2346
2351
search_module =
2347
2352
unwrap_or ! ( self . r. hygienic_lexical_parent( search_module, & mut ident. span) , break ) ;
2348
2353
}
2349
2354
2350
2355
if let Some ( prelude) = self . r . prelude {
2351
2356
if !search_module. no_implicit_prelude {
2352
- self . get_traits_in_module_containing_item ( ident, ns, prelude, & mut found_traits) ;
2357
+ self . r . get_traits_in_module_containing_item (
2358
+ ident,
2359
+ ns,
2360
+ prelude,
2361
+ & mut found_traits,
2362
+ & self . parent_scope ,
2363
+ ) ;
2353
2364
}
2354
2365
}
2355
2366
2356
2367
found_traits
2357
2368
}
2358
-
2359
- fn get_traits_in_module_containing_item (
2360
- & mut self ,
2361
- ident : Ident ,
2362
- ns : Namespace ,
2363
- module : Module < ' a > ,
2364
- found_traits : & mut Vec < TraitCandidate > ,
2365
- ) {
2366
- assert ! ( ns == TypeNS || ns == ValueNS ) ;
2367
- let mut traits = module. traits . borrow_mut ( ) ;
2368
- if traits. is_none ( ) {
2369
- let mut collected_traits = Vec :: new ( ) ;
2370
- module. for_each_child ( self . r , |_, name, ns, binding| {
2371
- if ns != TypeNS {
2372
- return ;
2373
- }
2374
- match binding. res ( ) {
2375
- Res :: Def ( DefKind :: Trait | DefKind :: TraitAlias , _) => {
2376
- collected_traits. push ( ( name, binding) )
2377
- }
2378
- _ => ( ) ,
2379
- }
2380
- } ) ;
2381
- * traits = Some ( collected_traits. into_boxed_slice ( ) ) ;
2382
- }
2383
-
2384
- for & ( trait_name, binding) in traits. as_ref ( ) . unwrap ( ) . iter ( ) {
2385
- // Traits have pseudo-modules that can be used to search for the given ident.
2386
- if let Some ( module) = binding. module ( ) {
2387
- let mut ident = ident;
2388
- if ident. span . glob_adjust ( module. expansion , binding. span ) . is_none ( ) {
2389
- continue ;
2390
- }
2391
- if self
2392
- . r
2393
- . resolve_ident_in_module_unadjusted (
2394
- ModuleOrUniformRoot :: Module ( module) ,
2395
- ident,
2396
- ns,
2397
- & self . parent_scope ,
2398
- false ,
2399
- module. span ,
2400
- )
2401
- . is_ok ( )
2402
- {
2403
- let import_ids = self . find_transitive_imports ( & binding. kind , trait_name) ;
2404
- let trait_def_id = module. def_id ( ) . unwrap ( ) ;
2405
- found_traits. push ( TraitCandidate { def_id : trait_def_id, import_ids } ) ;
2406
- }
2407
- } else if let Res :: Def ( DefKind :: TraitAlias , _) = binding. res ( ) {
2408
- // For now, just treat all trait aliases as possible candidates, since we don't
2409
- // know if the ident is somewhere in the transitive bounds.
2410
- let import_ids = self . find_transitive_imports ( & binding. kind , trait_name) ;
2411
- let trait_def_id = binding. res ( ) . def_id ( ) ;
2412
- found_traits. push ( TraitCandidate { def_id : trait_def_id, import_ids } ) ;
2413
- } else {
2414
- bug ! ( "candidate is not trait or trait alias?" )
2415
- }
2416
- }
2417
- }
2418
-
2419
- fn find_transitive_imports (
2420
- & mut self ,
2421
- mut kind : & NameBindingKind < ' _ > ,
2422
- trait_name : Ident ,
2423
- ) -> SmallVec < [ LocalDefId ; 1 ] > {
2424
- let mut import_ids = smallvec ! [ ] ;
2425
- while let NameBindingKind :: Import { import, binding, .. } = kind {
2426
- let id = self . r . local_def_id ( import. id ) ;
2427
- self . r . maybe_unused_trait_imports . insert ( id) ;
2428
- self . r . add_to_glob_map ( & import, trait_name) ;
2429
- import_ids. push ( id) ;
2430
- kind = & binding. kind ;
2431
- }
2432
- import_ids
2433
- }
2434
2369
}
2435
2370
2436
2371
impl < ' a > Resolver < ' a > {
0 commit comments