From a8fa8410cdda074f37dd948dc48efc20137d4d62 Mon Sep 17 00:00:00 2001 From: llogiq Date: Thu, 11 Feb 2016 05:58:09 +0100 Subject: [PATCH 1/3] Add _post methods for blocks and crates --- src/librustc/lint/context.rs | 6 ++++++ src/librustc/lint/mod.rs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 55782041be687..a9acbeb46c435 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -846,6 +846,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> { fn visit_block(&mut self, b: &hir::Block) { run_lints!(self, check_block, late_passes, b); hir_visit::walk_block(self, b); + run_lints!(self, check_block_post, late_passes, b); } fn visit_arm(&mut self, a: &hir::Arm) { @@ -1001,6 +1002,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { fn visit_block(&mut self, b: &ast::Block) { run_lints!(self, check_block, early_passes, b); ast_visit::walk_block(self, b); + run_lints!(self, check_block_post, early_passes, b); } fn visit_arm(&mut self, a: &ast::Arm) { @@ -1253,6 +1255,8 @@ pub fn check_crate(tcx: &ty::ctxt, access_levels: &AccessLevels) { run_lints!(cx, check_crate, late_passes, krate); hir_visit::walk_crate(cx, krate); + + run_lints!(cx, check_crate_post, late_passes, krate); }); // If we missed any lints added to the session, then there's a bug somewhere @@ -1284,6 +1288,8 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) { run_lints!(cx, check_crate, early_passes, krate); ast_visit::walk_crate(cx, krate); + + run_lints!(cx, check_crate_post, early_passes, krate); }); // Put the lint store back in the session. diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 6061525ef398c..612b23ff98eab 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -132,11 +132,13 @@ pub trait LintPass { pub trait LateLintPass: LintPass { fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { } fn check_crate(&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_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { } fn check_item(&mut self, _: &LateContext, _: &hir::Item) { } fn check_local(&mut self, _: &LateContext, _: &hir::Local) { } fn check_block(&mut self, _: &LateContext, _: &hir::Block) { } + fn check_block_post(&mut self, _: &LateContext, _: &hir::Block) { } fn check_stmt(&mut self, _: &LateContext, _: &hir::Stmt) { } fn check_arm(&mut self, _: &LateContext, _: &hir::Arm) { } fn check_pat(&mut self, _: &LateContext, _: &hir::Pat) { } @@ -174,11 +176,13 @@ pub trait LateLintPass: LintPass { pub trait EarlyLintPass: LintPass { fn check_ident(&mut self, _: &EarlyContext, _: Span, _: ast::Ident) { } fn check_crate(&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_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { } fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { } fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { } fn check_block(&mut self, _: &EarlyContext, _: &ast::Block) { } + fn check_block_post(&mut self, _: &EarlyContext, _: &ast::Block) { } fn check_stmt(&mut self, _: &EarlyContext, _: &ast::Stmt) { } fn check_arm(&mut self, _: &EarlyContext, _: &ast::Arm) { } fn check_pat(&mut self, _: &EarlyContext, _: &ast::Pat) { } From d483a6e2484e7dff3c4279bb026a6da0f1e4ba1e Mon Sep 17 00:00:00 2001 From: llogiq Date: Thu, 11 Feb 2016 18:19:18 +0100 Subject: [PATCH 2/3] add item_post methods --- src/librustc/lint/context.rs | 2 ++ src/librustc/lint/mod.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index a9acbeb46c435..6282a175e9a4a 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -758,6 +758,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> { run_lints!(cx, check_item, late_passes, it); cx.visit_ids(|v| v.visit_item(it)); hir_visit::walk_item(cx, it); + run_lints!(cx, check_item_post, late_passes, it); }) } @@ -919,6 +920,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { run_lints!(cx, check_item, early_passes, it); cx.visit_ids(|v| v.visit_item(it)); ast_visit::walk_item(cx, it); + run_lints!(cx, check_item, early_passes, it); }) } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 612b23ff98eab..5e2e8c4c6d5f8 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -136,6 +136,7 @@ pub trait LateLintPass: LintPass { fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { } fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { } fn check_item(&mut self, _: &LateContext, _: &hir::Item) { } + fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { } fn check_local(&mut self, _: &LateContext, _: &hir::Local) { } fn check_block(&mut self, _: &LateContext, _: &hir::Block) { } fn check_block_post(&mut self, _: &LateContext, _: &hir::Block) { } @@ -180,6 +181,7 @@ pub trait EarlyLintPass: LintPass { fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { } fn check_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { } fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { } + fn check_item_post(&mut self, _: &EarlyContext, _: &ast::Item) { } fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { } fn check_block(&mut self, _: &EarlyContext, _: &ast::Block) { } fn check_block_post(&mut self, _: &EarlyContext, _: &ast::Block) { } From a270b7b2d920689340d4d0cfd62bbde34b429441 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 12 Feb 2016 18:21:43 +0100 Subject: [PATCH 3/3] fix double check_item --- src/librustc/lint/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 6282a175e9a4a..9f40bd220b0a8 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -920,7 +920,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { run_lints!(cx, check_item, early_passes, it); cx.visit_ids(|v| v.visit_item(it)); ast_visit::walk_item(cx, it); - run_lints!(cx, check_item, early_passes, it); + run_lints!(cx, check_item_post, early_passes, it); }) }