Skip to content

early linting: avoid redundant calls to check_id #142398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,8 @@ fn visit_nested_use_tree<'a, V: Visitor<'a>>(
}

pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
let Stmt { id: _, kind, span: _ } = statement;
let Stmt { id, kind, span: _ } = statement;
try_visit!(visit_id(visitor, id));
match kind {
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> {
}

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

// This non-inlined function is for the cold call sites.
fn check_id(&mut self, id: ast::NodeId) {
self.inlined_check_id(id)
}

/// 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.
Expand All @@ -61,7 +54,6 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
debug!(?id);
let push = self.context.builder.push(attrs, is_crate_node, None);

self.inlined_check_id(id);
debug!("early context: enter_attrs({:?})", attrs);
lint_callback!(self, check_attributes, attrs);
ensure_sufficient_stack(|| f(self));
Expand Down Expand Up @@ -136,12 +128,8 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
// the AST struct that they wrap (e.g. an item)
self.with_lint_attrs(s.id, s.attrs(), |cx| {
lint_callback!(cx, check_stmt, s);
ast_visit::walk_stmt(cx, s);
});
// The visitor for the AST struct wrapped
// by the statement (e.g. `Item`) will call
// `with_lint_attrs`, so do this walk
// outside of the above `with_lint_attrs` call
ast_visit::walk_stmt(self, s);
}

fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, span: Span, id: ast::NodeId) {
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/label/label_misspelled.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ LL | break for_loop;
| not found in this scope
| help: use the similarly named label: `'for_loop`

warning: denote infinite loops with `loop { ... }`
--> $DIR/label_misspelled.rs:4:5
|
LL | 'while_loop: while true {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
|
= note: `#[warn(while_true)]` on by default

warning: unused label
--> $DIR/label_misspelled.rs:4:5
|
Expand All @@ -90,14 +98,6 @@ note: the lint level is defined here
LL | #![warn(unused_labels)]
| ^^^^^^^^^^^^^

warning: denote infinite loops with `loop { ... }`
--> $DIR/label_misspelled.rs:4:5
|
LL | 'while_loop: while true {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
|
= note: `#[warn(while_true)]` on by default

warning: unused label
--> $DIR/label_misspelled.rs:9:5
|
Expand All @@ -122,17 +122,17 @@ warning: denote infinite loops with `loop { ... }`
LL | 'while_loop: while true {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`

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

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

warning: unused label
--> $DIR/label_misspelled.rs:52:5
Expand Down
Loading