@@ -3,10 +3,11 @@ use rustc_ast::ptr::P;
3
3
use rustc_ast:: visit:: AssocCtxt ;
4
4
use rustc_ast:: * ;
5
5
use rustc_errors:: ErrorGuaranteed ;
6
- use rustc_hir:: def:: { DefKind , Res } ;
6
+ use rustc_hir:: def:: { DefKind , PerNS , Res } ;
7
7
use rustc_hir:: def_id:: { CRATE_DEF_ID , LocalDefId } ;
8
8
use rustc_hir:: { self as hir, HirId , LifetimeSource , PredicateOrigin } ;
9
9
use rustc_index:: { IndexSlice , IndexVec } ;
10
+ use rustc_middle:: span_bug;
10
11
use rustc_middle:: ty:: { ResolverAstLowering , TyCtxt } ;
11
12
use rustc_span:: edit_distance:: find_best_match_for_name;
12
13
use rustc_span:: { DUMMY_SP , DesugaringKind , Ident , Span , Symbol , kw, sym} ;
@@ -527,7 +528,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
527
528
}
528
529
UseTreeKind :: Glob => {
529
530
let res = self . expect_full_res ( id) ;
530
- let res = smallvec ! [ self . lower_res( res) ] ;
531
+ let res = self . lower_res ( res) ;
532
+ // Put the result in the appropriate namespace.
533
+ let res = match res {
534
+ Res :: Def ( DefKind :: Mod | DefKind :: Trait , _) => {
535
+ PerNS { type_ns : Some ( res) , value_ns : None , macro_ns : None }
536
+ }
537
+ Res :: Def ( DefKind :: Enum , _) => {
538
+ PerNS { type_ns : None , value_ns : Some ( res) , macro_ns : None }
539
+ }
540
+ Res :: Err => {
541
+ // Propagate the error to all namespaces, just to be sure.
542
+ let err = Some ( Res :: Err ) ;
543
+ PerNS { type_ns : err, value_ns : err, macro_ns : err }
544
+ }
545
+ _ => span_bug ! ( path. span, "bad glob res {:?}" , res) ,
546
+ } ;
531
547
let path = Path { segments, span : path. span , tokens : None } ;
532
548
let path = self . lower_use_path ( res, & path, ParamMode :: Explicit ) ;
533
549
hir:: ItemKind :: Use ( path, hir:: UseKind :: Glob )
@@ -601,7 +617,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
601
617
} else {
602
618
// For non-empty lists we can just drop all the data, the prefix is already
603
619
// present in HIR as a part of nested imports.
604
- self . arena . alloc ( hir:: UsePath { res : smallvec ! [ ] , segments : & [ ] , span } )
620
+ self . arena . alloc ( hir:: UsePath { res : PerNS :: default ( ) , segments : & [ ] , span } )
605
621
} ;
606
622
hir:: ItemKind :: Use ( path, hir:: UseKind :: ListStem )
607
623
}
0 commit comments