@@ -26,44 +26,43 @@ pub(super) struct ItemLowerer<'a, 'lowering, 'hir> {
26
26
}
27
27
28
28
impl ItemLowerer < ' _ , ' _ , ' _ > {
29
- fn with_trait_impl_ref ( & mut self , impl_ref : & Option < TraitRef > , f : impl FnOnce ( & mut Self ) ) {
29
+ fn with_trait_impl_ref < T > (
30
+ & mut self ,
31
+ impl_ref : & Option < TraitRef > ,
32
+ f : impl FnOnce ( & mut Self ) -> T ,
33
+ ) -> T {
30
34
let old = self . lctx . is_in_trait_impl ;
31
35
self . lctx . is_in_trait_impl = impl_ref. is_some ( ) ;
32
- f ( self ) ;
36
+ let ret = f ( self ) ;
33
37
self . lctx . is_in_trait_impl = old;
38
+ ret
34
39
}
35
40
}
36
41
37
42
impl < ' a > Visitor < ' a > for ItemLowerer < ' a , ' _ , ' _ > {
38
43
fn visit_item ( & mut self , item : & ' a Item ) {
39
- let mut item_hir_id = None ;
40
- self . lctx . with_hir_id_owner ( item. id , |lctx| {
44
+ let hir_id = self . lctx . with_hir_id_owner ( item. id , |lctx| {
41
45
lctx. without_in_scope_lifetime_defs ( |lctx| {
42
- if let Some ( hir_item) = lctx. lower_item ( item) {
43
- let id = lctx. insert_item ( hir_item) ;
44
- item_hir_id = Some ( id) ;
45
- }
46
+ let hir_item = lctx. lower_item ( item) ;
47
+ lctx. insert_item ( hir_item)
46
48
} )
47
49
} ) ;
48
50
49
- if let Some ( hir_id) = item_hir_id {
50
- self . lctx . with_parent_item_lifetime_defs ( hir_id, |this| {
51
- let this = & mut ItemLowerer { lctx : this } ;
52
- match item. kind {
53
- ItemKind :: Mod ( ..) => {
54
- let def_id = this. lctx . lower_node_id ( item. id ) . expect_owner ( ) ;
55
- let old_current_module =
56
- mem:: replace ( & mut this. lctx . current_module , def_id) ;
57
- visit:: walk_item ( this, item) ;
58
- this. lctx . current_module = old_current_module;
59
- }
60
- ItemKind :: Impl ( box ImplKind { ref of_trait, .. } ) => {
61
- this. with_trait_impl_ref ( of_trait, |this| visit:: walk_item ( this, item) ) ;
62
- }
63
- _ => visit:: walk_item ( this, item) ,
51
+ self . lctx . with_parent_item_lifetime_defs ( hir_id, |this| {
52
+ let this = & mut ItemLowerer { lctx : this } ;
53
+ match item. kind {
54
+ ItemKind :: Mod ( ..) => {
55
+ let def_id = this. lctx . lower_node_id ( item. id ) . expect_owner ( ) ;
56
+ let old_current_module = mem:: replace ( & mut this. lctx . current_module , def_id) ;
57
+ visit:: walk_item ( this, item) ;
58
+ this. lctx . current_module = old_current_module;
64
59
}
65
- } ) ;
66
- }
60
+ ItemKind :: Impl ( box ImplKind { ref of_trait, .. } ) => {
61
+ this. with_trait_impl_ref ( of_trait, |this| visit:: walk_item ( this, item) ) ;
62
+ }
63
+ _ => visit:: walk_item ( this, item) ,
64
+ }
65
+ } ) ;
67
66
}
68
67
69
68
fn visit_fn ( & mut self , fk : FnKind < ' a > , sp : Span , _: NodeId ) {
@@ -113,7 +112,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
113
112
fn with_parent_item_lifetime_defs < T > (
114
113
& mut self ,
115
114
parent_hir_id : hir:: ItemId ,
116
- f : impl FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
115
+ f : impl FnOnce ( & mut Self ) -> T ,
117
116
) -> T {
118
117
let old_len = self . in_scope_lifetimes . len ( ) ;
119
118
@@ -137,10 +136,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
137
136
// Clears (and restores) the `in_scope_lifetimes` field. Used when
138
137
// visiting nested items, which never inherit in-scope lifetimes
139
138
// from their surrounding environment.
140
- fn without_in_scope_lifetime_defs < T > (
141
- & mut self ,
142
- f : impl FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
143
- ) -> T {
139
+ fn without_in_scope_lifetime_defs < T > ( & mut self , f : impl FnOnce ( & mut Self ) -> T ) -> T {
144
140
let old_in_scope_lifetimes = mem:: replace ( & mut self . in_scope_lifetimes , vec ! [ ] ) ;
145
141
146
142
// this vector is only used when walking over impl headers,
@@ -208,19 +204,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
208
204
}
209
205
}
210
206
211
- pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item < ' hir > > {
207
+ pub fn lower_item ( & mut self , i : & Item ) -> hir:: Item < ' hir > {
212
208
let mut ident = i. ident ;
213
209
let mut vis = self . lower_visibility ( & i. vis , None ) ;
214
210
let hir_id = self . lower_node_id ( i. id ) ;
215
211
let attrs = self . lower_attrs ( hir_id, & i. attrs ) ;
216
212
let kind = self . lower_item_kind ( i. span , i. id , hir_id, & mut ident, attrs, & mut vis, & i. kind ) ;
217
- Some ( hir:: Item {
213
+ hir:: Item {
218
214
def_id : hir_id. expect_owner ( ) ,
219
215
ident : self . lower_ident ( ident) ,
220
216
kind,
221
217
vis,
222
218
span : self . lower_span ( i. span ) ,
223
- } )
219
+ }
224
220
}
225
221
226
222
fn lower_item_kind (
0 commit comments