@@ -53,10 +53,11 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
53
53
/// Merge the lints specified by any lint attributes into the
54
54
/// current lint context, call the provided function, then reset the
55
55
/// lints in effect to their previous state.
56
- fn with_lint_attrs < F > ( & mut self , id : hir:: HirId , attrs : & ' tcx [ ast :: Attribute ] , f : F )
56
+ fn with_lint_attrs < F > ( & mut self , id : hir:: HirId , f : F )
57
57
where
58
58
F : FnOnce ( & mut Self ) ,
59
59
{
60
+ let attrs = self . context . tcx . hir ( ) . attrs ( id) ;
60
61
let prev = self . context . last_node_with_lint_attrs ;
61
62
self . context . last_node_with_lint_attrs = id;
62
63
self . enter_attrs ( attrs) ;
@@ -125,7 +126,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
125
126
}
126
127
127
128
fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
128
- self . with_lint_attrs ( param. hir_id , & param . attrs , |cx| {
129
+ self . with_lint_attrs ( param. hir_id , |cx| {
129
130
lint_callback ! ( cx, check_param, param) ;
130
131
hir_visit:: walk_param ( cx, param) ;
131
132
} ) ;
@@ -142,7 +143,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
142
143
self . context . generics = it. kind . generics ( ) ;
143
144
let old_cached_typeck_results = self . context . cached_typeck_results . take ( ) ;
144
145
let old_enclosing_body = self . context . enclosing_body . take ( ) ;
145
- self . with_lint_attrs ( it. hir_id ( ) , & it . attrs , |cx| {
146
+ self . with_lint_attrs ( it. hir_id ( ) , |cx| {
146
147
cx. with_param_env ( it. hir_id ( ) , |cx| {
147
148
lint_callback ! ( cx, check_item, it) ;
148
149
hir_visit:: walk_item ( cx, it) ;
@@ -155,7 +156,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
155
156
}
156
157
157
158
fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
158
- self . with_lint_attrs ( it. hir_id ( ) , & it . attrs , |cx| {
159
+ self . with_lint_attrs ( it. hir_id ( ) , |cx| {
159
160
cx. with_param_env ( it. hir_id ( ) , |cx| {
160
161
lint_callback ! ( cx, check_foreign_item, it) ;
161
162
hir_visit:: walk_foreign_item ( cx, it) ;
@@ -170,19 +171,17 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
170
171
}
171
172
172
173
fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
173
- self . with_lint_attrs ( e. hir_id , & e . attrs , |cx| {
174
+ self . with_lint_attrs ( e. hir_id , |cx| {
174
175
lint_callback ! ( cx, check_expr, e) ;
175
176
hir_visit:: walk_expr ( cx, e) ;
176
177
lint_callback ! ( cx, check_expr_post, e) ;
177
178
} )
178
179
}
179
180
180
181
fn visit_stmt ( & mut self , s : & ' tcx hir:: Stmt < ' tcx > ) {
181
- let get_item = |id : hir:: ItemId | self . context . tcx . hir ( ) . item ( id) ;
182
- let attrs = & s. kind . attrs ( get_item) ;
183
182
// See `EarlyContextAndPass::visit_stmt` for an explanation
184
183
// of why we call `walk_stmt` outside of `with_lint_attrs`
185
- self . with_lint_attrs ( s. hir_id , attrs , |cx| {
184
+ self . with_lint_attrs ( s. hir_id , |cx| {
186
185
lint_callback ! ( cx, check_stmt, s) ;
187
186
} ) ;
188
187
hir_visit:: walk_stmt ( self , s) ;
@@ -222,7 +221,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
222
221
}
223
222
224
223
fn visit_struct_field ( & mut self , s : & ' tcx hir:: StructField < ' tcx > ) {
225
- self . with_lint_attrs ( s. hir_id , & s . attrs , |cx| {
224
+ self . with_lint_attrs ( s. hir_id , |cx| {
226
225
lint_callback ! ( cx, check_struct_field, s) ;
227
226
hir_visit:: walk_struct_field ( cx, s) ;
228
227
} )
@@ -234,7 +233,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
234
233
g : & ' tcx hir:: Generics < ' tcx > ,
235
234
item_id : hir:: HirId ,
236
235
) {
237
- self . with_lint_attrs ( v. id , & v . attrs , |cx| {
236
+ self . with_lint_attrs ( v. id , |cx| {
238
237
lint_callback ! ( cx, check_variant, v) ;
239
238
hir_visit:: walk_variant ( cx, v, g, item_id) ;
240
239
lint_callback ! ( cx, check_variant_post, v) ;
@@ -257,7 +256,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
257
256
}
258
257
259
258
fn visit_local ( & mut self , l : & ' tcx hir:: Local < ' tcx > ) {
260
- self . with_lint_attrs ( l. hir_id , & l . attrs , |cx| {
259
+ self . with_lint_attrs ( l. hir_id , |cx| {
261
260
lint_callback ! ( cx, check_local, l) ;
262
261
hir_visit:: walk_local ( cx, l) ;
263
262
} )
@@ -301,7 +300,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
301
300
fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem < ' tcx > ) {
302
301
let generics = self . context . generics . take ( ) ;
303
302
self . context . generics = Some ( & trait_item. generics ) ;
304
- self . with_lint_attrs ( trait_item. hir_id ( ) , & trait_item . attrs , |cx| {
303
+ self . with_lint_attrs ( trait_item. hir_id ( ) , |cx| {
305
304
cx. with_param_env ( trait_item. hir_id ( ) , |cx| {
306
305
lint_callback ! ( cx, check_trait_item, trait_item) ;
307
306
hir_visit:: walk_trait_item ( cx, trait_item) ;
@@ -314,7 +313,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
314
313
fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
315
314
let generics = self . context . generics . take ( ) ;
316
315
self . context . generics = Some ( & impl_item. generics ) ;
317
- self . with_lint_attrs ( impl_item. hir_id ( ) , & impl_item . attrs , |cx| {
316
+ self . with_lint_attrs ( impl_item. hir_id ( ) , |cx| {
318
317
cx. with_param_env ( impl_item. hir_id ( ) , |cx| {
319
318
lint_callback ! ( cx, check_impl_item, impl_item) ;
320
319
hir_visit:: walk_impl_item ( cx, impl_item) ;
@@ -440,7 +439,7 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
440
439
let mut cx = LateContextAndPass { context, pass } ;
441
440
442
441
// Visit the whole crate.
443
- cx. with_lint_attrs ( hir:: CRATE_HIR_ID , & krate . item . attrs , |cx| {
442
+ cx. with_lint_attrs ( hir:: CRATE_HIR_ID , |cx| {
444
443
// since the root module isn't visited as an item (because it isn't an
445
444
// item), warn for it here.
446
445
lint_callback ! ( cx, check_crate, krate) ;
0 commit comments