Auto merge of #142398 - fee1-dead-contrib:push-ynxrtswtkyxw, r=oli-obk
early linting: avoid redundant calls to `check_id` An attempt to address the regression at https://github.com/rust-lang/rust/pull/142240#issuecomment-2964425460 r? `@oli-obk` cc `@nnethercote` who might have a better understanding of the performance implications
This commit is contained in:
@@ -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 {
|
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 {
|
match kind {
|
||||||
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
|
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
|
||||||
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
|
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
|
||||||
|
|||||||
@@ -33,10 +33,8 @@ pub struct EarlyContextAndPass<'ecx, 'tcx, T: EarlyLintPass> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
|
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)]
|
#[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) {
|
for early_lint in self.context.buffered.take(id) {
|
||||||
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
|
let BufferedEarlyLint { span, node_id: _, lint_id, diagnostic } = early_lint;
|
||||||
self.context.opt_span_lint(lint_id.lint, span, |diag| {
|
self.context.opt_span_lint(lint_id.lint, span, |diag| {
|
||||||
@@ -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
|
/// Merge the lints specified by any lint attributes into the
|
||||||
/// current lint context, call the provided function, then reset the
|
/// current lint context, call the provided function, then reset the
|
||||||
/// lints in effect to their previous state.
|
/// lints in effect to their previous state.
|
||||||
@@ -61,7 +54,6 @@ impl<'ecx, 'tcx, T: EarlyLintPass> EarlyContextAndPass<'ecx, 'tcx, T> {
|
|||||||
debug!(?id);
|
debug!(?id);
|
||||||
let push = self.context.builder.push(attrs, is_crate_node, None);
|
let push = self.context.builder.push(attrs, is_crate_node, None);
|
||||||
|
|
||||||
self.inlined_check_id(id);
|
|
||||||
debug!("early context: enter_attrs({:?})", attrs);
|
debug!("early context: enter_attrs({:?})", attrs);
|
||||||
lint_callback!(self, check_attributes, attrs);
|
lint_callback!(self, check_attributes, attrs);
|
||||||
ensure_sufficient_stack(|| f(self));
|
ensure_sufficient_stack(|| f(self));
|
||||||
@@ -136,12 +128,8 @@ impl<'ast, 'ecx, 'tcx, T: EarlyLintPass> ast_visit::Visitor<'ast>
|
|||||||
// the AST struct that they wrap (e.g. an item)
|
// the AST struct that they wrap (e.g. an item)
|
||||||
self.with_lint_attrs(s.id, s.attrs(), |cx| {
|
self.with_lint_attrs(s.id, s.attrs(), |cx| {
|
||||||
lint_callback!(cx, check_stmt, s);
|
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) {
|
fn visit_fn(&mut self, fk: ast_visit::FnKind<'ast>, span: Span, id: ast::NodeId) {
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ LL | break for_loop;
|
|||||||
| not found in this scope
|
| not found in this scope
|
||||||
| help: use the similarly named label: `'for_loop`
|
| 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
|
warning: unused label
|
||||||
--> $DIR/label_misspelled.rs:4:5
|
--> $DIR/label_misspelled.rs:4:5
|
||||||
|
|
|
|
||||||
@@ -90,14 +98,6 @@ note: the lint level is defined here
|
|||||||
LL | #![warn(unused_labels)]
|
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
|
warning: unused label
|
||||||
--> $DIR/label_misspelled.rs:9:5
|
--> $DIR/label_misspelled.rs:9:5
|
||||||
|
|
|
|
||||||
@@ -122,18 +122,18 @@ warning: denote infinite loops with `loop { ... }`
|
|||||||
LL | 'while_loop: while true {
|
LL | 'while_loop: while true {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
|
||||||
|
|
||||||
warning: unused label
|
|
||||||
--> $DIR/label_misspelled.rs:47:5
|
|
||||||
|
|
|
||||||
LL | 'while_loop: while true {
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: denote infinite loops with `loop { ... }`
|
warning: denote infinite loops with `loop { ... }`
|
||||||
--> $DIR/label_misspelled.rs:47:5
|
--> $DIR/label_misspelled.rs:47:5
|
||||||
|
|
|
|
||||||
LL | 'while_loop: while true {
|
LL | 'while_loop: while true {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop`
|
||||||
|
|
||||||
|
warning: unused label
|
||||||
|
--> $DIR/label_misspelled.rs:47:5
|
||||||
|
|
|
||||||
|
LL | 'while_loop: while true {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
warning: unused label
|
warning: unused label
|
||||||
--> $DIR/label_misspelled.rs:52:5
|
--> $DIR/label_misspelled.rs:52:5
|
||||||
|
|
|
|
||||||
|
|||||||
Reference in New Issue
Block a user