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

@ -13,13 +13,14 @@ use ast::mut_visit::{noop_visit_expr, MutVisitor};
use ast::token::IdentIsRaw;
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, Pat, Path, PathSegment};
use core::mem;
use core::ops::ControlFlow;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::Spacing;
use rustc_ast::util::case::Case;
use rustc_ast::util::classify;
use rustc_ast::util::parser::{prec_let_scrutinee_needs_par, AssocOp, Fixity};
use rustc_ast::visit::Visitor;
use rustc_ast::visit::{walk_expr, Visitor};
use rustc_ast::{self as ast, AttrStyle, AttrVec, CaptureBy, ExprField, UnOp, DUMMY_NODE_ID};
use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind};
use rustc_ast::{Arm, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
@ -1703,19 +1704,20 @@ impl<'a> Parser<'a> {
let span = expr.span;
let found_labeled_breaks = {
struct FindLabeledBreaksVisitor(bool);
struct FindLabeledBreaksVisitor;
impl<'ast> Visitor<'ast> for FindLabeledBreaksVisitor {
fn visit_expr_post(&mut self, ex: &'ast Expr) {
type Result = ControlFlow<()>;
fn visit_expr(&mut self, ex: &'ast Expr) -> ControlFlow<()> {
if let ExprKind::Break(Some(_label), _) = ex.kind {
self.0 = true;
ControlFlow::Break(())
} else {
walk_expr(self, ex)
}
}
}
let mut vis = FindLabeledBreaksVisitor(false);
vis.visit_expr(&expr);
vis.0
FindLabeledBreaksVisitor.visit_expr(&expr).is_break()
};
// Suggestion involves adding a labeled block.