@@ -15,8 +15,9 @@ use hir_expand::name::Name;
1515use triomphe:: Arc ;
1616
1717use crate :: {
18+ data:: adt:: VariantData ,
1819 db:: DefDatabase ,
19- item_scope:: BUILTIN_SCOPE ,
20+ item_scope:: { ImportOrExternCrate , BUILTIN_SCOPE } ,
2021 nameres:: { sub_namespace_match, BlockInfo , BuiltinShadowMode , DefMap , MacroSubNs } ,
2122 path:: { ModPath , PathKind } ,
2223 per_ns:: PerNs ,
@@ -196,15 +197,15 @@ impl DefMap {
196197 PathKind :: DollarCrate ( krate) => {
197198 if krate == self . krate {
198199 cov_mark:: hit!( macro_dollar_crate_self) ;
199- PerNs :: types ( self . crate_root ( ) . into ( ) , Visibility :: Public )
200+ PerNs :: types ( self . crate_root ( ) . into ( ) , Visibility :: Public , None )
200201 } else {
201202 let def_map = db. crate_def_map ( krate) ;
202203 let module = def_map. module_id ( Self :: ROOT ) ;
203204 cov_mark:: hit!( macro_dollar_crate_other) ;
204- PerNs :: types ( module. into ( ) , Visibility :: Public )
205+ PerNs :: types ( module. into ( ) , Visibility :: Public , None )
205206 }
206207 }
207- PathKind :: Crate => PerNs :: types ( self . crate_root ( ) . into ( ) , Visibility :: Public ) ,
208+ PathKind :: Crate => PerNs :: types ( self . crate_root ( ) . into ( ) , Visibility :: Public , None ) ,
208209 // plain import or absolute path in 2015: crate-relative with
209210 // fallback to extern prelude (with the simplification in
210211 // rust-lang/rust#57745)
@@ -291,25 +292,29 @@ impl DefMap {
291292 ) ;
292293 }
293294
294- PerNs :: types ( module. into ( ) , Visibility :: Public )
295+ PerNs :: types ( module. into ( ) , Visibility :: Public , None )
295296 }
296297 PathKind :: Abs => {
297298 // 2018-style absolute path -- only extern prelude
298299 let segment = match segments. next ( ) {
299300 Some ( ( _, segment) ) => segment,
300301 None => return ResolvePathResult :: empty ( ReachedFixedPoint :: Yes ) ,
301302 } ;
302- if let Some ( & ( def, _extern_crate ) ) = self . data . extern_prelude . get ( segment) {
303+ if let Some ( & ( def, extern_crate ) ) = self . data . extern_prelude . get ( segment) {
303304 tracing:: debug!( "absolute path {:?} resolved to crate {:?}" , path, def) ;
304- PerNs :: types ( def. into ( ) , Visibility :: Public )
305+ PerNs :: types (
306+ def. into ( ) ,
307+ Visibility :: Public ,
308+ extern_crate. map ( ImportOrExternCrate :: ExternCrate ) ,
309+ )
305310 } else {
306311 return ResolvePathResult :: empty ( ReachedFixedPoint :: No ) ; // extern crate declarations can add to the extern prelude
307312 }
308313 }
309314 } ;
310315
311316 for ( i, segment) in segments {
312- let ( curr, vis) = match curr_per_ns. take_types_vis ( ) {
317+ let ( curr, vis, imp ) = match curr_per_ns. take_types_full ( ) {
313318 Some ( r) => r,
314319 None => {
315320 // we still have path segments left, but the path so far
@@ -364,18 +369,20 @@ impl DefMap {
364369 Some ( local_id) => {
365370 let variant = EnumVariantId { parent : e, local_id } ;
366371 match & * enum_data. variants [ local_id] . variant_data {
367- crate :: data:: adt:: VariantData :: Record ( _) => {
368- PerNs :: types ( variant. into ( ) , Visibility :: Public )
369- }
370- crate :: data:: adt:: VariantData :: Tuple ( _)
371- | crate :: data:: adt:: VariantData :: Unit => {
372- PerNs :: both ( variant. into ( ) , variant. into ( ) , Visibility :: Public )
372+ VariantData :: Record ( _) => {
373+ PerNs :: types ( variant. into ( ) , Visibility :: Public , None )
373374 }
375+ VariantData :: Tuple ( _) | VariantData :: Unit => PerNs :: both (
376+ variant. into ( ) ,
377+ variant. into ( ) ,
378+ Visibility :: Public ,
379+ None ,
380+ ) ,
374381 }
375382 }
376383 None => {
377384 return ResolvePathResult :: with (
378- PerNs :: types ( e. into ( ) , vis) ,
385+ PerNs :: types ( e. into ( ) , vis, imp ) ,
379386 ReachedFixedPoint :: Yes ,
380387 Some ( i) ,
381388 Some ( self . krate ) ,
@@ -393,7 +400,7 @@ impl DefMap {
393400 ) ;
394401
395402 return ResolvePathResult :: with (
396- PerNs :: types ( s, vis) ,
403+ PerNs :: types ( s, vis, imp ) ,
397404 ReachedFixedPoint :: Yes ,
398405 Some ( i) ,
399406 Some ( self . krate ) ,
@@ -430,7 +437,7 @@ impl DefMap {
430437 . filter ( |& id| {
431438 sub_namespace_match ( Some ( MacroSubNs :: from_id ( db, id) ) , expected_macro_subns)
432439 } )
433- . map_or_else ( PerNs :: none, |m| PerNs :: macros ( m, Visibility :: Public ) ) ;
440+ . map_or_else ( PerNs :: none, |m| PerNs :: macros ( m, Visibility :: Public , None ) ) ;
434441 let from_scope = self [ module] . scope . get ( name) . filter_macro ( db, expected_macro_subns) ;
435442 let from_builtin = match self . block {
436443 Some ( _) => {
@@ -449,16 +456,26 @@ impl DefMap {
449456
450457 let extern_prelude = || {
451458 if self . block . is_some ( ) {
452- // Don't resolve extern prelude in block `DefMap`s.
459+ // Don't resolve extern prelude in block `DefMap`s, defer it to the crate def map so
460+ // that blocks can properly shadow them
453461 return PerNs :: none ( ) ;
454462 }
455- self . data . extern_prelude . get ( name) . map_or ( PerNs :: none ( ) , |& ( it, _extern_crate) | {
456- PerNs :: types ( it. into ( ) , Visibility :: Public )
463+ self . data . extern_prelude . get ( name) . map_or ( PerNs :: none ( ) , |& ( it, extern_crate) | {
464+ PerNs :: types (
465+ it. into ( ) ,
466+ Visibility :: Public ,
467+ extern_crate. map ( ImportOrExternCrate :: ExternCrate ) ,
468+ )
457469 } )
458470 } ;
459471 let macro_use_prelude = || {
460472 self . macro_use_prelude . get ( name) . map_or ( PerNs :: none ( ) , |& ( it, _extern_crate) | {
461- PerNs :: macros ( it. into ( ) , Visibility :: Public )
473+ PerNs :: macros (
474+ it. into ( ) ,
475+ Visibility :: Public ,
476+ // FIXME?
477+ None , // extern_crate.map(ImportOrExternCrate::ExternCrate),
478+ )
462479 } )
463480 } ;
464481 let prelude = || self . resolve_in_prelude ( db, name) ;
@@ -487,13 +504,16 @@ impl DefMap {
487504 // Don't resolve extern prelude in block `DefMap`s.
488505 return PerNs :: none ( ) ;
489506 }
490- self . data
491- . extern_prelude
492- . get ( name)
493- . copied ( )
494- . map_or ( PerNs :: none ( ) , |( it, _extern_crate) | {
495- PerNs :: types ( it. into ( ) , Visibility :: Public )
496- } )
507+ self . data . extern_prelude . get ( name) . copied ( ) . map_or (
508+ PerNs :: none ( ) ,
509+ |( it, extern_crate) | {
510+ PerNs :: types (
511+ it. into ( ) ,
512+ Visibility :: Public ,
513+ extern_crate. map ( ImportOrExternCrate :: ExternCrate ) ,
514+ )
515+ } ,
516+ )
497517 } ;
498518
499519 from_crate_root. or_else ( from_extern_prelude)
0 commit comments