Rollup merge of #121563 - Jarcho:use_cf, r=petrochenkov

Use `ControlFlow` in visitors.

Follow up to #121256

This does have a few small behaviour changes in some diagnostic output where the visitor will now find the first match rather than the last match. The change in `find_anon_types.rs` has the only affected test. I don't see this being an issue as the last occurrence isn't any better of a choice than the first.
This commit is contained in:
Matthias Krüger 2024-03-08 13:22:26 +01:00 committed by GitHub
commit 3e634f8c5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 240 additions and 270 deletions

View file

@ -20,6 +20,7 @@ use rustc_span::symbol::Symbol;
use rustc_span::symbol::{kw, sym};
use rustc_span::{BytePos, Span};
use std::iter;
use std::ops::ControlFlow;
declare_lint! {
/// The `unused_must_use` lint detects unused result of a type flagged as
@ -753,21 +754,18 @@ trait UnusedDelimLint {
// fn f(){(print!(á
// ```
use rustc_ast::visit::{walk_expr, Visitor};
struct ErrExprVisitor {
has_error: bool,
}
struct ErrExprVisitor;
impl<'ast> Visitor<'ast> for ErrExprVisitor {
fn visit_expr(&mut self, expr: &'ast ast::Expr) {
type Result = ControlFlow<()>;
fn visit_expr(&mut self, expr: &'ast ast::Expr) -> ControlFlow<()> {
if let ExprKind::Err(_) = expr.kind {
self.has_error = true;
return;
ControlFlow::Break(())
} else {
walk_expr(self, expr)
}
walk_expr(self, expr)
}
}
let mut visitor = ErrExprVisitor { has_error: false };
visitor.visit_expr(value);
if visitor.has_error {
if ErrExprVisitor.visit_expr(value).is_break() {
return;
}
let spans = match value.kind {