Skip to content

Commit 5801991

Browse files
committed
Auto merge of #31562 - llogiq:lint_post, r=Manishearth
This fixes #31512 for me. A bit of explanation: I want to have `check_block_post(&mut self, &Context, &Block)` and `check_crate_post(&mut self, &Context, &Crate)` methods in both early and late lint passes. Ideally we'd have _post methods for all operations that walk, but this'll do for now. @Manishearth r?
2 parents a94642c + a270b7b commit 5801991

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/librustc/lint/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
758758
run_lints!(cx, check_item, late_passes, it);
759759
cx.visit_ids(|v| v.visit_item(it));
760760
hir_visit::walk_item(cx, it);
761+
run_lints!(cx, check_item_post, late_passes, it);
761762
})
762763
}
763764

@@ -846,6 +847,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
846847
fn visit_block(&mut self, b: &hir::Block) {
847848
run_lints!(self, check_block, late_passes, b);
848849
hir_visit::walk_block(self, b);
850+
run_lints!(self, check_block_post, late_passes, b);
849851
}
850852

851853
fn visit_arm(&mut self, a: &hir::Arm) {
@@ -918,6 +920,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
918920
run_lints!(cx, check_item, early_passes, it);
919921
cx.visit_ids(|v| v.visit_item(it));
920922
ast_visit::walk_item(cx, it);
923+
run_lints!(cx, check_item_post, early_passes, it);
921924
})
922925
}
923926

@@ -1001,6 +1004,7 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
10011004
fn visit_block(&mut self, b: &ast::Block) {
10021005
run_lints!(self, check_block, early_passes, b);
10031006
ast_visit::walk_block(self, b);
1007+
run_lints!(self, check_block_post, early_passes, b);
10041008
}
10051009

10061010
fn visit_arm(&mut self, a: &ast::Arm) {
@@ -1253,6 +1257,8 @@ pub fn check_crate(tcx: &ty::ctxt, access_levels: &AccessLevels) {
12531257
run_lints!(cx, check_crate, late_passes, krate);
12541258

12551259
hir_visit::walk_crate(cx, krate);
1260+
1261+
run_lints!(cx, check_crate_post, late_passes, krate);
12561262
});
12571263

12581264
// If we missed any lints added to the session, then there's a bug somewhere
@@ -1284,6 +1290,8 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) {
12841290
run_lints!(cx, check_crate, early_passes, krate);
12851291

12861292
ast_visit::walk_crate(cx, krate);
1293+
1294+
run_lints!(cx, check_crate_post, early_passes, krate);
12871295
});
12881296

12891297
// Put the lint store back in the session.

src/librustc/lint/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ pub trait LintPass {
132132
pub trait LateLintPass: LintPass {
133133
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
134134
fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { }
135+
fn check_crate_post(&mut self, _: &LateContext, _: &hir::Crate) { }
135136
fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { }
136137
fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { }
137138
fn check_item(&mut self, _: &LateContext, _: &hir::Item) { }
139+
fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { }
138140
fn check_local(&mut self, _: &LateContext, _: &hir::Local) { }
139141
fn check_block(&mut self, _: &LateContext, _: &hir::Block) { }
142+
fn check_block_post(&mut self, _: &LateContext, _: &hir::Block) { }
140143
fn check_stmt(&mut self, _: &LateContext, _: &hir::Stmt) { }
141144
fn check_arm(&mut self, _: &LateContext, _: &hir::Arm) { }
142145
fn check_pat(&mut self, _: &LateContext, _: &hir::Pat) { }
@@ -174,11 +177,14 @@ pub trait LateLintPass: LintPass {
174177
pub trait EarlyLintPass: LintPass {
175178
fn check_ident(&mut self, _: &EarlyContext, _: Span, _: ast::Ident) { }
176179
fn check_crate(&mut self, _: &EarlyContext, _: &ast::Crate) { }
180+
fn check_crate_post(&mut self, _: &EarlyContext, _: &ast::Crate) { }
177181
fn check_mod(&mut self, _: &EarlyContext, _: &ast::Mod, _: Span, _: ast::NodeId) { }
178182
fn check_foreign_item(&mut self, _: &EarlyContext, _: &ast::ForeignItem) { }
179183
fn check_item(&mut self, _: &EarlyContext, _: &ast::Item) { }
184+
fn check_item_post(&mut self, _: &EarlyContext, _: &ast::Item) { }
180185
fn check_local(&mut self, _: &EarlyContext, _: &ast::Local) { }
181186
fn check_block(&mut self, _: &EarlyContext, _: &ast::Block) { }
187+
fn check_block_post(&mut self, _: &EarlyContext, _: &ast::Block) { }
182188
fn check_stmt(&mut self, _: &EarlyContext, _: &ast::Stmt) { }
183189
fn check_arm(&mut self, _: &EarlyContext, _: &ast::Arm) { }
184190
fn check_pat(&mut self, _: &EarlyContext, _: &ast::Pat) { }

0 commit comments

Comments
 (0)