88use RibKind :: * ;
99
1010use crate :: { path_names_to_string, BindingError , CrateLint , LexicalScopeBinding } ;
11- use crate :: { Module , ModuleOrUniformRoot , NameBindingKind , ParentScope , PathResult } ;
11+ use crate :: { Module , ModuleOrUniformRoot , ParentScope , PathResult } ;
1212use crate :: { ResolutionError , Resolver , Segment , UseError } ;
1313
1414use rustc_ast:: ptr:: P ;
@@ -24,7 +24,6 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
2424use rustc_hir:: TraitCandidate ;
2525use rustc_middle:: { bug, span_bug} ;
2626use rustc_session:: lint;
27- use rustc_span:: def_id:: LocalDefId ;
2827use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
2928use rustc_span:: Span ;
3029use smallvec:: { smallvec, SmallVec } ;
@@ -2342,95 +2341,31 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
23422341 ident. span = ident. span . normalize_to_macros_2_0 ( ) ;
23432342 let mut search_module = self . parent_scope . module ;
23442343 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+ ) ;
23462351 search_module =
23472352 unwrap_or ! ( self . r. hygienic_lexical_parent( search_module, & mut ident. span) , break ) ;
23482353 }
23492354
23502355 if let Some ( prelude) = self . r . prelude {
23512356 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+ ) ;
23532364 }
23542365 }
23552366
23562367 found_traits
23572368 }
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- }
24342369}
24352370
24362371impl < ' a > Resolver < ' a > {
0 commit comments