Auto merge of - llogiq:more_post, r=eddyb

These `_post` methods are quite helpful to control lint behavior without storing e.g. block node ids. So here are a few more I believe will be helpful.

r? @Manishearth
This commit is contained in:
bors 2016-02-27 06:58:28 +00:00
commit 80dee36438
2 changed files with 22 additions and 0 deletions
src/librustc/lint

View file

@ -766,6 +766,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
self.with_lint_attrs(&it.attrs, |cx| { self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_foreign_item, late_passes, it); run_lints!(cx, check_foreign_item, late_passes, it);
hir_visit::walk_foreign_item(cx, it); hir_visit::walk_foreign_item(cx, it);
run_lints!(cx, check_foreign_item_post, late_passes, it);
}) })
} }
@ -795,6 +796,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
body: &'v hir::Block, span: Span, id: ast::NodeId) { body: &'v hir::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, late_passes, fk, decl, body, span, id); run_lints!(self, check_fn, late_passes, fk, decl, body, span, id);
hir_visit::walk_fn(self, fk, decl, body, span); hir_visit::walk_fn(self, fk, decl, body, span);
run_lints!(self, check_fn_post, late_passes, fk, decl, body, span, id);
} }
fn visit_variant_data(&mut self, fn visit_variant_data(&mut self,
@ -835,6 +837,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) { fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
run_lints!(self, check_mod, late_passes, m, s, n); run_lints!(self, check_mod, late_passes, m, s, n);
hir_visit::walk_mod(self, m); hir_visit::walk_mod(self, m);
run_lints!(self, check_mod_post, late_passes, m, s, n);
} }
fn visit_local(&mut self, l: &hir::Local) { fn visit_local(&mut self, l: &hir::Local) {
@ -874,6 +877,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
run_lints!(cx, check_trait_item, late_passes, trait_item); run_lints!(cx, check_trait_item, late_passes, trait_item);
cx.visit_ids(|v| v.visit_trait_item(trait_item)); cx.visit_ids(|v| v.visit_trait_item(trait_item));
hir_visit::walk_trait_item(cx, trait_item); hir_visit::walk_trait_item(cx, trait_item);
run_lints!(cx, check_trait_item_post, late_passes, trait_item);
}); });
} }
@ -882,6 +886,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
run_lints!(cx, check_impl_item, late_passes, impl_item); run_lints!(cx, check_impl_item, late_passes, impl_item);
cx.visit_ids(|v| v.visit_impl_item(impl_item)); cx.visit_ids(|v| v.visit_impl_item(impl_item));
hir_visit::walk_impl_item(cx, impl_item); hir_visit::walk_impl_item(cx, impl_item);
run_lints!(cx, check_impl_item_post, late_passes, impl_item);
}); });
} }
@ -928,6 +933,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
self.with_lint_attrs(&it.attrs, |cx| { self.with_lint_attrs(&it.attrs, |cx| {
run_lints!(cx, check_foreign_item, early_passes, it); run_lints!(cx, check_foreign_item, early_passes, it);
ast_visit::walk_foreign_item(cx, it); ast_visit::walk_foreign_item(cx, it);
run_lints!(cx, check_foreign_item_post, early_passes, it);
}) })
} }
@ -952,6 +958,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
body: &'v ast::Block, span: Span, id: ast::NodeId) { body: &'v ast::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, early_passes, fk, decl, body, span, id); run_lints!(self, check_fn, early_passes, fk, decl, body, span, id);
ast_visit::walk_fn(self, fk, decl, body, span); ast_visit::walk_fn(self, fk, decl, body, span);
run_lints!(self, check_fn_post, early_passes, fk, decl, body, span, id);
} }
fn visit_variant_data(&mut self, fn visit_variant_data(&mut self,
@ -992,6 +999,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) { fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) {
run_lints!(self, check_mod, early_passes, m, s, n); run_lints!(self, check_mod, early_passes, m, s, n);
ast_visit::walk_mod(self, m); ast_visit::walk_mod(self, m);
run_lints!(self, check_mod_post, early_passes, m, s, n);
} }
fn visit_local(&mut self, l: &ast::Local) { fn visit_local(&mut self, l: &ast::Local) {
@ -1031,6 +1039,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
run_lints!(cx, check_trait_item, early_passes, trait_item); run_lints!(cx, check_trait_item, early_passes, trait_item);
cx.visit_ids(|v| v.visit_trait_item(trait_item)); cx.visit_ids(|v| v.visit_trait_item(trait_item));
ast_visit::walk_trait_item(cx, trait_item); ast_visit::walk_trait_item(cx, trait_item);
run_lints!(cx, check_trait_item_post, early_passes, trait_item);
}); });
} }
@ -1039,6 +1048,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
run_lints!(cx, check_impl_item, early_passes, impl_item); run_lints!(cx, check_impl_item, early_passes, impl_item);
cx.visit_ids(|v| v.visit_impl_item(impl_item)); cx.visit_ids(|v| v.visit_impl_item(impl_item));
ast_visit::walk_impl_item(cx, impl_item); ast_visit::walk_impl_item(cx, impl_item);
run_lints!(cx, check_impl_item_post, early_passes, impl_item);
}); });
} }

View file

@ -134,7 +134,9 @@ pub trait LateLintPass: LintPass {
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { } fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
fn check_crate_post(&mut self, _: &LateContext, _: &hir::Crate) { } fn check_crate_post(&mut self, _: &LateContext, _: &hir::Crate) { }
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { } fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
fn check_mod_post(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { } fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
fn check_foreign_item_post(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
fn check_item(&mut self, _: &LateContext, _: &hir::Item) { } fn check_item(&mut self, _: &LateContext, _: &hir::Item) { }
fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { } fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { }
fn check_local(&mut self, _: &LateContext, _: &hir::Local) { } fn check_local(&mut self, _: &LateContext, _: &hir::Local) { }
@ -150,8 +152,12 @@ pub trait LateLintPass: LintPass {
fn check_generics(&mut self, _: &LateContext, _: &hir::Generics) { } fn check_generics(&mut self, _: &LateContext, _: &hir::Generics) { }
fn check_fn(&mut self, _: &LateContext, fn check_fn(&mut self, _: &LateContext,
_: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { } _: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { }
fn check_fn_post(&mut self, _: &LateContext,
_: FnKind, _: &hir::FnDecl, _: &hir::Block, _: Span, _: ast::NodeId) { }
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { } fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
fn check_trait_item_post(&mut self, _: &LateContext, _: &hir::TraitItem) { }
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { } fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
fn check_impl_item_post(&mut self, _: &LateContext, _: &hir::ImplItem) { }
fn check_struct_def(&mut self, _: &LateContext, fn check_struct_def(&mut self, _: &LateContext,
_: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { } _: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &LateContext, fn check_struct_def_post(&mut self, _: &LateContext,
@ -179,7 +185,9 @@ pub trait EarlyLintPass: LintPass {
fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { } fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { }
fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { } fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { }
fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { } fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
fn check_mod_post(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
fn check_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { } fn check_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
fn check_foreign_item_post(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { } fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { }
fn check_item_post(&mut self, _: &EarlyContext, _: &ast::Item) { } fn check_item_post(&mut self, _: &EarlyContext, _: &ast::Item) { }
fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { } fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { }
@ -195,8 +203,12 @@ pub trait EarlyLintPass: LintPass {
fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { } fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { }
fn check_fn(&mut self, _: &EarlyContext, fn check_fn(&mut self, _: &EarlyContext,
_: ast_visit::FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { } _: ast_visit::FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
fn check_fn_post(&mut self, _: &EarlyContext,
_: ast_visit::FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
fn check_trait_item(&mut self, _: &EarlyContext, _: &ast::TraitItem) { } fn check_trait_item(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
fn check_trait_item_post(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
fn check_impl_item(&mut self, _: &EarlyContext, _: &ast::ImplItem) { } fn check_impl_item(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
fn check_impl_item_post(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
fn check_struct_def(&mut self, _: &EarlyContext, fn check_struct_def(&mut self, _: &EarlyContext,
_: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { } _: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
fn check_struct_def_post(&mut self, _: &EarlyContext, fn check_struct_def_post(&mut self, _: &EarlyContext,