Skip to content

Commit ae8ca1f

Browse files
committed
early linting: avoid redundant calls to check_id
1 parent 1434630 commit ae8ca1f

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,8 @@ fn visit_nested_use_tree<'a, V: Visitor<'a>>(
17001700
}
17011701

17021702
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
1703-
let Stmt { id: _, kind, span: _ } = statement;
1703+
let Stmt { id, kind, span: _ } = statement;
1704+
try_visit!(visit_id(visitor, id));
17041705
match kind {
17051706
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
17061707
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),

compiler/rustc_lint/src/early.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> {
3333
}
3434

3535
impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
36-
// This always-inlined function is for the hot call site.
37-
#[inline(always)]
3836
#[allow(rustc::diagnostic_outside_of_impl)]
39-
fn inlined_check_id(&mut self, id: ast::NodeId) {
37+
fn check_id(&mut self, id: ast::NodeId) {
4038
for early_lint in self.context.buffered.take(id) {
4139
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
4240
self.context.opt_span_lint(lint_id.lint, span, |diag| {
@@ -45,11 +43,6 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
4543
}
4644
}
4745

48-
// This non-inlined function is for the cold call sites.
49-
fn check_id(&mut self, id: ast::NodeId) {
50-
self.inlined_check_id(id)
51-
}
52-
5346
/// Merge the lints specified by any lint attributes into the
5447
/// current lint context, call the provided function, then reset the
5548
/// lints in effect to their previous state.
@@ -61,7 +54,6 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
6154
debug!(?id);
6255
let push = self.context.builder.push(attrs, is_crate_node, None);
6356

64-
self.inlined_check_id(id);
6557
debug!("early context: enter_attrs({:?})", attrs);
6658
lint_callback!(self, check_attributes, attrs);
6759
ensure_sufficient_stack(|| f(self));
@@ -136,12 +128,8 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
136128
// the AST struct that they wrap (e.g. an item)
137129
self.with_lint_attrs(s.id, s.attrs(), |cx| {
138130
lint_callback!(cx, check_stmt, s);
131+
ast_visit::walk_stmt(cx, s);
139132
});
140-
// The visitor for the AST struct wrapped
141-
// by the statement (e.g. `Item`) will call
142-
// `with_lint_attrs`, so do this walk
143-
// outside of the above `with_lint_attrs` call
144-
ast_visit::walk_stmt(self, s);
145133
}
146134

147135
fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, span: Span, id: ast::NodeId) {

tests/ui/label/label_misspelled.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ LL | break for_loop;
7878
| not found in this scope
7979
| help: use the similarly named label: `'for_loop`
8080

81+
warning: denote infinite loops with `loop { ... }`
82+
--> $DIR/label_misspelled.rs:4:5
83+
|
84+
LL | 'while_loop: while true {
85+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
86+
|
87+
= note: `#[warn(while_true)]` on by default
88+
8189
warning: unused label
8290
--> $DIR/label_misspelled.rs:4:5
8391
|
@@ -90,14 +98,6 @@ note: the lint level is defined here
9098
LL | #![warn(unused_labels)]
9199
| ^^^^^^^^^^^^^
92100

93-
warning: denote infinite loops with `loop { ... }`
94-
--> $DIR/label_misspelled.rs:4:5
95-
|
96-
LL | 'while_loop: while true {
97-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
98-
|
99-
= note: `#[warn(while_true)]` on by default
100-
101101
warning: unused label
102102
--> $DIR/label_misspelled.rs:9:5
103103
|
@@ -122,17 +122,17 @@ warning: denote infinite loops with `loop { ... }`
122122
LL | 'while_loop: while true {
123123
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
124124

125-
warning: unused label
125+
warning: denote infinite loops with `loop { ... }`
126126
--> $DIR/label_misspelled.rs:47:5
127127
|
128128
LL | 'while_loop: while true {
129-
| ^^^^^^^^^^^
129+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
130130

131-
warning: denote infinite loops with `loop { ... }`
131+
warning: unused label
132132
--> $DIR/label_misspelled.rs:47:5
133133
|
134134
LL | 'while_loop: while true {
135-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
135+
| ^^^^^^^^^^^
136136

137137
warning: unused label
138138
--> $DIR/label_misspelled.rs:52:5

0 commit comments

Comments
 (0)