Access attrs directly from HirId in rustc_lint::late.
This commit is contained in:
parent
4a21af67e3
commit
b84bdf1dae
1 changed files with 13 additions and 14 deletions
|
@ -53,10 +53,11 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
|||
/// Merge the lints specified by any lint attributes into the
|
||||
/// current lint context, call the provided function, then reset the
|
||||
/// lints in effect to their previous state.
|
||||
fn with_lint_attrs<F>(&mut self, id: hir::HirId, attrs: &'tcx [ast::Attribute], f: F)
|
||||
fn with_lint_attrs<F>(&mut self, id: hir::HirId, f: F)
|
||||
where
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
let attrs = self.context.tcx.hir().attrs(id);
|
||||
let prev = self.context.last_node_with_lint_attrs;
|
||||
self.context.last_node_with_lint_attrs = id;
|
||||
self.enter_attrs(attrs);
|
||||
|
@ -125,7 +126,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
}
|
||||
|
||||
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
|
||||
self.with_lint_attrs(param.hir_id, ¶m.attrs, |cx| {
|
||||
self.with_lint_attrs(param.hir_id, |cx| {
|
||||
lint_callback!(cx, check_param, param);
|
||||
hir_visit::walk_param(cx, param);
|
||||
});
|
||||
|
@ -142,7 +143,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
self.context.generics = it.kind.generics();
|
||||
let old_cached_typeck_results = self.context.cached_typeck_results.take();
|
||||
let old_enclosing_body = self.context.enclosing_body.take();
|
||||
self.with_lint_attrs(it.hir_id(), &it.attrs, |cx| {
|
||||
self.with_lint_attrs(it.hir_id(), |cx| {
|
||||
cx.with_param_env(it.hir_id(), |cx| {
|
||||
lint_callback!(cx, check_item, it);
|
||||
hir_visit::walk_item(cx, it);
|
||||
|
@ -155,7 +156,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
|
||||
self.with_lint_attrs(it.hir_id(), &it.attrs, |cx| {
|
||||
self.with_lint_attrs(it.hir_id(), |cx| {
|
||||
cx.with_param_env(it.hir_id(), |cx| {
|
||||
lint_callback!(cx, check_foreign_item, it);
|
||||
hir_visit::walk_foreign_item(cx, it);
|
||||
|
@ -170,7 +171,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
}
|
||||
|
||||
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
|
||||
self.with_lint_attrs(e.hir_id, &e.attrs, |cx| {
|
||||
self.with_lint_attrs(e.hir_id, |cx| {
|
||||
lint_callback!(cx, check_expr, e);
|
||||
hir_visit::walk_expr(cx, e);
|
||||
lint_callback!(cx, check_expr_post, e);
|
||||
|
@ -178,11 +179,9 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
}
|
||||
|
||||
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
|
||||
let get_item = |id: hir::ItemId| self.context.tcx.hir().item(id);
|
||||
let attrs = &s.kind.attrs(get_item);
|
||||
// See `EarlyContextAndPass::visit_stmt` for an explanation
|
||||
// of why we call `walk_stmt` outside of `with_lint_attrs`
|
||||
self.with_lint_attrs(s.hir_id, attrs, |cx| {
|
||||
self.with_lint_attrs(s.hir_id, |cx| {
|
||||
lint_callback!(cx, check_stmt, s);
|
||||
});
|
||||
hir_visit::walk_stmt(self, s);
|
||||
|
@ -222,7 +221,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) {
|
||||
self.with_lint_attrs(s.hir_id, &s.attrs, |cx| {
|
||||
self.with_lint_attrs(s.hir_id, |cx| {
|
||||
lint_callback!(cx, check_struct_field, s);
|
||||
hir_visit::walk_struct_field(cx, s);
|
||||
})
|
||||
|
@ -234,7 +233,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
g: &'tcx hir::Generics<'tcx>,
|
||||
item_id: hir::HirId,
|
||||
) {
|
||||
self.with_lint_attrs(v.id, &v.attrs, |cx| {
|
||||
self.with_lint_attrs(v.id, |cx| {
|
||||
lint_callback!(cx, check_variant, v);
|
||||
hir_visit::walk_variant(cx, v, g, item_id);
|
||||
lint_callback!(cx, check_variant_post, v);
|
||||
|
@ -257,7 +256,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
}
|
||||
|
||||
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
|
||||
self.with_lint_attrs(l.hir_id, &l.attrs, |cx| {
|
||||
self.with_lint_attrs(l.hir_id, |cx| {
|
||||
lint_callback!(cx, check_local, l);
|
||||
hir_visit::walk_local(cx, l);
|
||||
})
|
||||
|
@ -301,7 +300,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&trait_item.generics);
|
||||
self.with_lint_attrs(trait_item.hir_id(), &trait_item.attrs, |cx| {
|
||||
self.with_lint_attrs(trait_item.hir_id(), |cx| {
|
||||
cx.with_param_env(trait_item.hir_id(), |cx| {
|
||||
lint_callback!(cx, check_trait_item, trait_item);
|
||||
hir_visit::walk_trait_item(cx, trait_item);
|
||||
|
@ -314,7 +313,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&impl_item.generics);
|
||||
self.with_lint_attrs(impl_item.hir_id(), &impl_item.attrs, |cx| {
|
||||
self.with_lint_attrs(impl_item.hir_id(), |cx| {
|
||||
cx.with_param_env(impl_item.hir_id(), |cx| {
|
||||
lint_callback!(cx, check_impl_item, impl_item);
|
||||
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)
|
|||
let mut cx = LateContextAndPass { context, pass };
|
||||
|
||||
// Visit the whole crate.
|
||||
cx.with_lint_attrs(hir::CRATE_HIR_ID, &krate.item.attrs, |cx| {
|
||||
cx.with_lint_attrs(hir::CRATE_HIR_ID, |cx| {
|
||||
// since the root module isn't visited as an item (because it isn't an
|
||||
// item), warn for it here.
|
||||
lint_callback!(cx, check_crate, krate);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue