Skip to content

Commit b84bdf1

Browse files
committed
Access attrs directly from HirId in rustc_lint::late.
1 parent 4a21af6 commit b84bdf1

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

compiler/rustc_lint/src/late.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
5353
/// Merge the lints specified by any lint attributes into the
5454
/// current lint context, call the provided function, then reset the
5555
/// 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)
5757
where
5858
F: FnOnce(&mut Self),
5959
{
60+
let attrs = self.context.tcx.hir().attrs(id);
6061
let prev = self.context.last_node_with_lint_attrs;
6162
self.context.last_node_with_lint_attrs = id;
6263
self.enter_attrs(attrs);
@@ -125,7 +126,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
125126
}
126127

127128
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| {
129130
lint_callback!(cx, check_param, param);
130131
hir_visit::walk_param(cx, param);
131132
});
@@ -142,7 +143,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
142143
self.context.generics = it.kind.generics();
143144
let old_cached_typeck_results = self.context.cached_typeck_results.take();
144145
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| {
146147
cx.with_param_env(it.hir_id(), |cx| {
147148
lint_callback!(cx, check_item, it);
148149
hir_visit::walk_item(cx, it);
@@ -155,7 +156,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
155156
}
156157

157158
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| {
159160
cx.with_param_env(it.hir_id(), |cx| {
160161
lint_callback!(cx, check_foreign_item, it);
161162
hir_visit::walk_foreign_item(cx, it);
@@ -170,19 +171,17 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
170171
}
171172

172173
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| {
174175
lint_callback!(cx, check_expr, e);
175176
hir_visit::walk_expr(cx, e);
176177
lint_callback!(cx, check_expr_post, e);
177178
})
178179
}
179180

180181
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);
183182
// See `EarlyContextAndPass::visit_stmt` for an explanation
184183
// 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| {
186185
lint_callback!(cx, check_stmt, s);
187186
});
188187
hir_visit::walk_stmt(self, s);
@@ -222,7 +221,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
222221
}
223222

224223
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| {
226225
lint_callback!(cx, check_struct_field, s);
227226
hir_visit::walk_struct_field(cx, s);
228227
})
@@ -234,7 +233,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
234233
g: &'tcx hir::Generics<'tcx>,
235234
item_id: hir::HirId,
236235
) {
237-
self.with_lint_attrs(v.id, &v.attrs, |cx| {
236+
self.with_lint_attrs(v.id, |cx| {
238237
lint_callback!(cx, check_variant, v);
239238
hir_visit::walk_variant(cx, v, g, item_id);
240239
lint_callback!(cx, check_variant_post, v);
@@ -257,7 +256,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
257256
}
258257

259258
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| {
261260
lint_callback!(cx, check_local, l);
262261
hir_visit::walk_local(cx, l);
263262
})
@@ -301,7 +300,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
301300
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
302301
let generics = self.context.generics.take();
303302
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| {
305304
cx.with_param_env(trait_item.hir_id(), |cx| {
306305
lint_callback!(cx, check_trait_item, trait_item);
307306
hir_visit::walk_trait_item(cx, trait_item);
@@ -314,7 +313,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
314313
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
315314
let generics = self.context.generics.take();
316315
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| {
318317
cx.with_param_env(impl_item.hir_id(), |cx| {
319318
lint_callback!(cx, check_impl_item, impl_item);
320319
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)
440439
let mut cx = LateContextAndPass { context, pass };
441440

442441
// 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| {
444443
// since the root module isn't visited as an item (because it isn't an
445444
// item), warn for it here.
446445
lint_callback!(cx, check_crate, krate);

0 commit comments

Comments
 (0)