@@ -15,8 +15,9 @@ use hir_expand::name::Name;
15
15
use triomphe:: Arc ;
16
16
17
17
use crate :: {
18
+ data:: adt:: VariantData ,
18
19
db:: DefDatabase ,
19
- item_scope:: BUILTIN_SCOPE ,
20
+ item_scope:: { ImportOrExternCrate , BUILTIN_SCOPE } ,
20
21
nameres:: { sub_namespace_match, BlockInfo , BuiltinShadowMode , DefMap , MacroSubNs } ,
21
22
path:: { ModPath , PathKind } ,
22
23
per_ns:: PerNs ,
@@ -196,15 +197,15 @@ impl DefMap {
196
197
PathKind :: DollarCrate ( krate) => {
197
198
if krate == self . krate {
198
199
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 )
200
201
} else {
201
202
let def_map = db. crate_def_map ( krate) ;
202
203
let module = def_map. module_id ( Self :: ROOT ) ;
203
204
cov_mark:: hit!( macro_dollar_crate_other) ;
204
- PerNs :: types ( module. into ( ) , Visibility :: Public )
205
+ PerNs :: types ( module. into ( ) , Visibility :: Public , None )
205
206
}
206
207
}
207
- PathKind :: Crate => PerNs :: types ( self . crate_root ( ) . into ( ) , Visibility :: Public ) ,
208
+ PathKind :: Crate => PerNs :: types ( self . crate_root ( ) . into ( ) , Visibility :: Public , None ) ,
208
209
// plain import or absolute path in 2015: crate-relative with
209
210
// fallback to extern prelude (with the simplification in
210
211
// rust-lang/rust#57745)
@@ -291,25 +292,29 @@ impl DefMap {
291
292
) ;
292
293
}
293
294
294
- PerNs :: types ( module. into ( ) , Visibility :: Public )
295
+ PerNs :: types ( module. into ( ) , Visibility :: Public , None )
295
296
}
296
297
PathKind :: Abs => {
297
298
// 2018-style absolute path -- only extern prelude
298
299
let segment = match segments. next ( ) {
299
300
Some ( ( _, segment) ) => segment,
300
301
None => return ResolvePathResult :: empty ( ReachedFixedPoint :: Yes ) ,
301
302
} ;
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) {
303
304
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
+ )
305
310
} else {
306
311
return ResolvePathResult :: empty ( ReachedFixedPoint :: No ) ; // extern crate declarations can add to the extern prelude
307
312
}
308
313
}
309
314
} ;
310
315
311
316
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 ( ) {
313
318
Some ( r) => r,
314
319
None => {
315
320
// we still have path segments left, but the path so far
@@ -364,18 +369,20 @@ impl DefMap {
364
369
Some ( local_id) => {
365
370
let variant = EnumVariantId { parent : e, local_id } ;
366
371
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 )
373
374
}
375
+ VariantData :: Tuple ( _) | VariantData :: Unit => PerNs :: both (
376
+ variant. into ( ) ,
377
+ variant. into ( ) ,
378
+ Visibility :: Public ,
379
+ None ,
380
+ ) ,
374
381
}
375
382
}
376
383
None => {
377
384
return ResolvePathResult :: with (
378
- PerNs :: types ( e. into ( ) , vis) ,
385
+ PerNs :: types ( e. into ( ) , vis, imp ) ,
379
386
ReachedFixedPoint :: Yes ,
380
387
Some ( i) ,
381
388
Some ( self . krate ) ,
@@ -393,7 +400,7 @@ impl DefMap {
393
400
) ;
394
401
395
402
return ResolvePathResult :: with (
396
- PerNs :: types ( s, vis) ,
403
+ PerNs :: types ( s, vis, imp ) ,
397
404
ReachedFixedPoint :: Yes ,
398
405
Some ( i) ,
399
406
Some ( self . krate ) ,
@@ -430,7 +437,7 @@ impl DefMap {
430
437
. filter ( |& id| {
431
438
sub_namespace_match ( Some ( MacroSubNs :: from_id ( db, id) ) , expected_macro_subns)
432
439
} )
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 ) ) ;
434
441
let from_scope = self [ module] . scope . get ( name) . filter_macro ( db, expected_macro_subns) ;
435
442
let from_builtin = match self . block {
436
443
Some ( _) => {
@@ -449,16 +456,26 @@ impl DefMap {
449
456
450
457
let extern_prelude = || {
451
458
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
453
461
return PerNs :: none ( ) ;
454
462
}
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
+ )
457
469
} )
458
470
} ;
459
471
let macro_use_prelude = || {
460
472
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
+ )
462
479
} )
463
480
} ;
464
481
let prelude = || self . resolve_in_prelude ( db, name) ;
@@ -487,13 +504,16 @@ impl DefMap {
487
504
// Don't resolve extern prelude in block `DefMap`s.
488
505
return PerNs :: none ( ) ;
489
506
}
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
+ )
497
517
} ;
498
518
499
519
from_crate_root. or_else ( from_extern_prelude)
0 commit comments