Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28e8274

Browse files
committedMar 8, 2024
Auto merge of rust-lang#122190 - matthiaskrgr:rollup-9ol4y30, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#121025 (add known-bug tests for derive failure to detect packed repr) - rust-lang#121194 (Refactor pre-getopts command line argument handling) - rust-lang#121563 (Use `ControlFlow` in visitors.) - rust-lang#122173 (Don't ICE in CTFE if raw/fn-ptr types differ) - rust-lang#122175 (Bless tidy issues order) - rust-lang#122179 (rustc: Fix typo) - rust-lang#122181 (Fix crash in internal late lint checking) - rust-lang#122183 (interpret: update comment about read_discriminant on uninhabited variants) Failed merges: - rust-lang#122076 (Tweak the way we protect in-place function arguments in interpreters) - rust-lang#122132 (Diagnostic renaming 3) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4282576 + 8abeac2 commit 28e8274

File tree

76 files changed

+821
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+821
-457
lines changed
 

‎compiler/rustc_ast_lowering/src/format.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::LoweringContext;
2+
use core::ops::ControlFlow;
23
use rustc_ast as ast;
34
use rustc_ast::visit::Visitor;
45
use rustc_ast::*;
@@ -594,30 +595,32 @@ fn expand_format_args<'hir>(
594595
}
595596

596597
fn may_contain_yield_point(e: &ast::Expr) -> bool {
597-
struct MayContainYieldPoint(bool);
598+
struct MayContainYieldPoint;
598599

599600
impl Visitor<'_> for MayContainYieldPoint {
600-
fn visit_expr(&mut self, e: &ast::Expr) {
601+
type Result = ControlFlow<()>;
602+
603+
fn visit_expr(&mut self, e: &ast::Expr) -> ControlFlow<()> {
601604
if let ast::ExprKind::Await(_, _) | ast::ExprKind::Yield(_) = e.kind {
602-
self.0 = true;
605+
ControlFlow::Break(())
603606
} else {
604607
visit::walk_expr(self, e);
608+
ControlFlow::Continue(())
605609
}
606610
}
607611

608-
fn visit_mac_call(&mut self, _: &ast::MacCall) {
612+
fn visit_mac_call(&mut self, _: &ast::MacCall) -> ControlFlow<()> {
609613
// Macros should be expanded at this point.
610614
unreachable!("unexpanded macro in ast lowering");
611615
}
612616

613-
fn visit_item(&mut self, _: &ast::Item) {
617+
fn visit_item(&mut self, _: &ast::Item) -> ControlFlow<()> {
614618
// Do not recurse into nested items.
619+
ControlFlow::Continue(())
615620
}
616621
}
617622

618-
let mut visitor = MayContainYieldPoint(false);
619-
visitor.visit_expr(e);
620-
visitor.0
623+
MayContainYieldPoint.visit_expr(e).is_break()
621624
}
622625

623626
fn for_all_argument_indexes(template: &mut [FormatArgsPiece], mut f: impl FnMut(&mut usize)) {

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(rustc::diagnostic_outside_of_impl)]
22
#![allow(rustc::untranslatable_diagnostic)]
33

4+
use core::ops::ControlFlow;
45
use hir::ExprKind;
56
use rustc_errors::{Applicability, Diag};
67
use rustc_hir as hir;
@@ -727,30 +728,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
727728
_ => local_decl.source_info.span,
728729
};
729730

730-
struct BindingFinder {
731-
span: Span,
732-
hir_id: Option<hir::HirId>,
733-
}
734-
735-
impl<'tcx> Visitor<'tcx> for BindingFinder {
736-
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
737-
if let hir::StmtKind::Local(local) = s.kind {
738-
if local.pat.span == self.span {
739-
self.hir_id = Some(local.hir_id);
740-
}
741-
}
742-
hir::intravisit::walk_stmt(self, s);
743-
}
744-
}
745-
746731
let def_id = self.body.source.def_id();
747732
let hir_id = if let Some(local_def_id) = def_id.as_local()
748733
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
749734
{
750735
let body = self.infcx.tcx.hir().body(body_id);
751-
let mut v = BindingFinder { span: pat_span, hir_id: None };
752-
v.visit_body(body);
753-
v.hir_id
736+
BindingFinder { span: pat_span }.visit_body(body).break_value()
754737
} else {
755738
None
756739
};
@@ -859,17 +842,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
859842
};
860843

861844
let hir_map = self.infcx.tcx.hir();
862-
struct Finder<'tcx> {
845+
struct Finder {
863846
span: Span,
864-
expr: Option<&'tcx Expr<'tcx>>,
865847
}
866848

867-
impl<'tcx> Visitor<'tcx> for Finder<'tcx> {
868-
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
869-
if e.span == self.span && self.expr.is_none() {
870-
self.expr = Some(e);
849+
impl<'tcx> Visitor<'tcx> for Finder {
850+
type Result = ControlFlow<&'tcx Expr<'tcx>>;
851+
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) -> Self::Result {
852+
if e.span == self.span {
853+
ControlFlow::Break(e)
854+
} else {
855+
hir::intravisit::walk_expr(self, e)
871856
}
872-
hir::intravisit::walk_expr(self, e);
873857
}
874858
}
875859
if let Some(body_id) = hir_map.maybe_body_owned_by(self.mir_def_id())
@@ -878,9 +862,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
878862
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
879863
// expression with that span in order to identify potential fixes when encountering a
880864
// read-only iterator that should be mutable.
881-
let mut v = Finder { span, expr: None };
882-
v.visit_block(block);
883-
if let Some(expr) = v.expr
865+
if let ControlFlow::Break(expr) = (Finder { span }).visit_block(block)
884866
&& let Call(_, [expr]) = expr.kind
885867
{
886868
match expr.kind {
@@ -1179,29 +1161,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11791161
);
11801162
}
11811163
Some((false, err_label_span, message)) => {
1182-
struct BindingFinder {
1183-
span: Span,
1184-
hir_id: Option<hir::HirId>,
1185-
}
1186-
1187-
impl<'tcx> Visitor<'tcx> for BindingFinder {
1188-
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
1189-
if let hir::StmtKind::Local(local) = s.kind {
1190-
if local.pat.span == self.span {
1191-
self.hir_id = Some(local.hir_id);
1192-
}
1193-
}
1194-
hir::intravisit::walk_stmt(self, s);
1195-
}
1196-
}
11971164
let def_id = self.body.source.def_id();
11981165
let hir_id = if let Some(local_def_id) = def_id.as_local()
11991166
&& let Some(body_id) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
12001167
{
12011168
let body = self.infcx.tcx.hir().body(body_id);
1202-
let mut v = BindingFinder { span: err_label_span, hir_id: None };
1203-
v.visit_body(body);
1204-
v.hir_id
1169+
BindingFinder { span: err_label_span }.visit_body(body).break_value()
12051170
} else {
12061171
None
12071172
};
@@ -1333,6 +1298,23 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
13331298
}
13341299
}
13351300

1301+
struct BindingFinder {
1302+
span: Span,
1303+
}
1304+
1305+
impl<'tcx> Visitor<'tcx> for BindingFinder {
1306+
type Result = ControlFlow<hir::HirId>;
1307+
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) -> Self::Result {
1308+
if let hir::StmtKind::Local(local) = s.kind
1309+
&& local.pat.span == self.span
1310+
{
1311+
ControlFlow::Break(local.hir_id)
1312+
} else {
1313+
hir::intravisit::walk_stmt(self, s)
1314+
}
1315+
}
1316+
}
1317+
13361318
pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
13371319
debug!("local_info: {:?}, ty.kind(): {:?}", local_decl.local_info, local_decl.ty.kind());
13381320

0 commit comments

Comments
 (0)
This repository has been archived.