@@ -19,7 +19,6 @@ use rustc_span::symbol::{kw, sym, Ident};
19
19
use rustc_span:: { Span , Symbol } ;
20
20
use rustc_target:: spec:: abi;
21
21
use smallvec:: { smallvec, SmallVec } ;
22
- use std:: iter;
23
22
use thin_vec:: ThinVec ;
24
23
25
24
pub ( super ) struct ItemLowerer < ' a , ' hir > {
@@ -179,36 +178,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
179
178
let mut node_ids =
180
179
smallvec ! [ hir:: ItemId { owner_id: hir:: OwnerId { def_id: self . local_def_id( i. id) } } ] ;
181
180
if let ItemKind :: Use ( use_tree) = & i. kind {
182
- self . lower_item_id_use_tree ( use_tree, i . id , & mut node_ids) ;
181
+ self . lower_item_id_use_tree ( use_tree, & mut node_ids) ;
183
182
}
184
183
node_ids
185
184
}
186
185
187
- fn lower_item_id_use_tree (
188
- & mut self ,
189
- tree : & UseTree ,
190
- base_id : NodeId ,
191
- vec : & mut SmallVec < [ hir:: ItemId ; 1 ] > ,
192
- ) {
186
+ fn lower_item_id_use_tree ( & mut self , tree : & UseTree , vec : & mut SmallVec < [ hir:: ItemId ; 1 ] > ) {
193
187
match & tree. kind {
194
188
UseTreeKind :: Nested ( nested_vec) => {
195
189
for & ( ref nested, id) in nested_vec {
196
190
vec. push ( hir:: ItemId {
197
191
owner_id : hir:: OwnerId { def_id : self . local_def_id ( id) } ,
198
192
} ) ;
199
- self . lower_item_id_use_tree ( nested, id, vec) ;
200
- }
201
- }
202
- UseTreeKind :: Glob => { }
203
- UseTreeKind :: Simple ( _, id1, id2) => {
204
- for ( _, id) in
205
- iter:: zip ( self . expect_full_res_from_use ( base_id) . skip ( 1 ) , [ * id1, * id2] )
206
- {
207
- vec. push ( hir:: ItemId {
208
- owner_id : hir:: OwnerId { def_id : self . local_def_id ( id) } ,
209
- } ) ;
193
+ self . lower_item_id_use_tree ( nested, vec) ;
210
194
}
211
195
}
196
+ UseTreeKind :: Simple ( ..) | UseTreeKind :: Glob => { }
212
197
}
213
198
}
214
199
@@ -489,7 +474,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
489
474
let segments = prefix. segments . iter ( ) . chain ( path. segments . iter ( ) ) . cloned ( ) . collect ( ) ;
490
475
491
476
match tree. kind {
492
- UseTreeKind :: Simple ( rename, id1 , id2 ) => {
477
+ UseTreeKind :: Simple ( rename) => {
493
478
* ident = tree. ident ( ) ;
494
479
495
480
// First, apply the prefix to the path.
@@ -505,66 +490,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
505
490
}
506
491
}
507
492
508
- let mut resolutions = self . expect_full_res_from_use ( id) . fuse ( ) ;
509
- // We want to return *something* from this function, so hold onto the first item
510
- // for later.
511
- let ret_res = self . lower_res ( resolutions. next ( ) . unwrap_or ( Res :: Err ) ) ;
512
-
513
- // Here, we are looping over namespaces, if they exist for the definition
514
- // being imported. We only handle type and value namespaces because we
515
- // won't be dealing with macros in the rest of the compiler.
516
- // Essentially a single `use` which imports two names is desugared into
517
- // two imports.
518
- for new_node_id in [ id1, id2] {
519
- let new_id = self . local_def_id ( new_node_id) ;
520
- let Some ( res) = resolutions. next ( ) else {
521
- debug_assert ! ( self . children. iter( ) . find( |( id, _) | id == & new_id) . is_none( ) ) ;
522
- // Associate an HirId to both ids even if there is no resolution.
523
- self . children . push ( (
524
- new_id,
525
- hir:: MaybeOwner :: NonOwner ( hir:: HirId :: make_owner ( new_id) ) ) ,
526
- ) ;
527
- continue ;
528
- } ;
529
- let ident = * ident;
530
- let mut path = path. clone ( ) ;
531
- for seg in & mut path. segments {
532
- // Give the cloned segment the same resolution information
533
- // as the old one (this is needed for stability checking).
534
- let new_id = self . next_node_id ( ) ;
535
- self . resolver . clone_res ( seg. id , new_id) ;
536
- seg. id = new_id;
537
- }
538
- let span = path. span ;
539
-
540
- self . with_hir_id_owner ( new_node_id, |this| {
541
- let res = this. lower_res ( res) ;
542
- let path = this. lower_path_extra ( res, & path, ParamMode :: Explicit ) ;
543
- let kind = hir:: ItemKind :: Use ( path, hir:: UseKind :: Single ) ;
544
- if let Some ( attrs) = attrs {
545
- this. attrs . insert ( hir:: ItemLocalId :: new ( 0 ) , attrs) ;
546
- }
547
-
548
- let item = hir:: Item {
549
- owner_id : hir:: OwnerId { def_id : new_id } ,
550
- ident : this. lower_ident ( ident) ,
551
- kind,
552
- vis_span,
553
- span : this. lower_span ( span) ,
554
- } ;
555
- hir:: OwnerNode :: Item ( this. arena . alloc ( item) )
556
- } ) ;
557
- }
558
-
559
- let path = self . lower_path_extra ( ret_res, & path, ParamMode :: Explicit ) ;
493
+ let res =
494
+ self . expect_full_res_from_use ( id) . map ( |res| self . lower_res ( res) ) . collect ( ) ;
495
+ let path = self . lower_use_path ( res, & path, ParamMode :: Explicit ) ;
560
496
hir:: ItemKind :: Use ( path, hir:: UseKind :: Single )
561
497
}
562
498
UseTreeKind :: Glob => {
563
- let path = self . lower_path (
564
- id,
565
- & Path { segments, span : path. span , tokens : None } ,
566
- ParamMode :: Explicit ,
567
- ) ;
499
+ let res = self . expect_full_res ( id) ;
500
+ let res = smallvec ! [ self . lower_res( res) ] ;
501
+ let path = Path { segments, span : path. span , tokens : None } ;
502
+ let path = self . lower_use_path ( res, & path, ParamMode :: Explicit ) ;
568
503
hir:: ItemKind :: Use ( path, hir:: UseKind :: Glob )
569
504
}
570
505
UseTreeKind :: Nested ( ref trees) => {
@@ -634,9 +569,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
634
569
} ) ;
635
570
}
636
571
637
- let res = self . expect_full_res_from_use ( id ) . next ( ) . unwrap_or ( Res :: Err ) ;
638
- let res = self . lower_res ( res) ;
639
- let path = self . lower_path_extra ( res, & prefix, ParamMode :: Explicit ) ;
572
+ let res =
573
+ self . expect_full_res_from_use ( id ) . map ( |res| self . lower_res ( res) ) . collect ( ) ;
574
+ let path = self . lower_use_path ( res, & prefix, ParamMode :: Explicit ) ;
640
575
hir:: ItemKind :: Use ( path, hir:: UseKind :: ListStem )
641
576
}
642
577
}
0 commit comments