Skip to content

Commit 59dec8b

Browse files
Remove Control enum in favor of ControlFlow
1 parent dcfa38f commit 59dec8b

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use std::cell::RefCell;
1919
use std::marker::PhantomData;
20-
use std::ops::Deref;
20+
use std::ops::{ControlFlow, Deref};
2121

2222
use rustc_abi::FieldIdx;
2323
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
@@ -1054,31 +1054,31 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10541054
rw,
10551055
(borrow_index, borrow),
10561056
);
1057-
Control::Continue
1057+
ControlFlow::Continue(())
10581058
}
10591059

10601060
(Read(_), BorrowKind::Shared | BorrowKind::Fake(_))
10611061
| (
10621062
Read(ReadKind::Borrow(BorrowKind::Fake(FakeBorrowKind::Shallow))),
10631063
BorrowKind::Mut { .. },
1064-
) => Control::Continue,
1064+
) => ControlFlow::Continue(()),
10651065

10661066
(Reservation(_), BorrowKind::Fake(_) | BorrowKind::Shared) => {
10671067
// This used to be a future compatibility warning (to be
10681068
// disallowed on NLL). See rust-lang/rust#56254
1069-
Control::Continue
1069+
ControlFlow::Continue(())
10701070
}
10711071

10721072
(Write(WriteKind::Move), BorrowKind::Fake(FakeBorrowKind::Shallow)) => {
10731073
// Handled by initialization checks.
1074-
Control::Continue
1074+
ControlFlow::Continue(())
10751075
}
10761076

10771077
(Read(kind), BorrowKind::Mut { .. }) => {
10781078
// Reading from mere reservations of mutable-borrows is OK.
10791079
if !is_active(this.dominators(), borrow, location) {
10801080
assert!(allow_two_phase_borrow(borrow.kind));
1081-
return Control::Continue;
1081+
return ControlFlow::Continue(());
10821082
}
10831083

10841084
error_reported = true;
@@ -1094,7 +1094,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10941094
this.buffer_error(err);
10951095
}
10961096
}
1097-
Control::Break
1097+
ControlFlow::Break(())
10981098
}
10991099

11001100
(Reservation(kind) | Activation(kind, _) | Write(kind), _) => {
@@ -1141,7 +1141,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11411141
this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
11421142
}
11431143
}
1144-
Control::Break
1144+
ControlFlow::Break(())
11451145
}
11461146
},
11471147
);

compiler/rustc_borrowck/src/path_utils.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::ControlFlow;
2+
13
use rustc_abi::FieldIdx;
24
use rustc_data_structures::graph::dominators::Dominators;
35
use rustc_middle::mir::{BasicBlock, Body, BorrowKind, Location, Place, PlaceRef, ProjectionElem};
@@ -14,13 +16,6 @@ pub(super) fn allow_two_phase_borrow(kind: BorrowKind) -> bool {
1416
kind.allows_two_phase_borrow()
1517
}
1618

17-
/// Control for the path borrow checking code
18-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
19-
pub(super) enum Control {
20-
Continue,
21-
Break,
22-
}
23-
2419
/// Encapsulates the idea of iterating over every borrow that involves a particular path
2520
pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
2621
s: &mut S,
@@ -31,7 +26,7 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
3126
is_candidate: I,
3227
mut op: F,
3328
) where
34-
F: FnMut(&mut S, BorrowIndex, &BorrowData<'tcx>) -> Control,
29+
F: FnMut(&mut S, BorrowIndex, &BorrowData<'tcx>) -> ControlFlow<()>,
3530
I: Fn(BorrowIndex) -> bool,
3631
{
3732
let (access, place) = access_place;
@@ -62,7 +57,7 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
6257
i, borrowed, place, access
6358
);
6459
let ctrl = op(s, i, borrowed);
65-
if ctrl == Control::Break {
60+
if ctrl == ControlFlow::Break(()) {
6661
return;
6762
}
6863
}

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::ControlFlow;
2+
13
use rustc_data_structures::graph::dominators::Dominators;
24
use rustc_middle::bug;
35
use rustc_middle::mir::visit::Visitor;
@@ -379,7 +381,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
379381
if !is_active(this.dominators, borrow, location) {
380382
// If the borrow isn't active yet, reads don't invalidate it
381383
assert!(allow_two_phase_borrow(borrow.kind));
382-
return Control::Continue;
384+
return ControlFlow::Continue(());
383385
}
384386

385387
// Unique and mutable borrows are invalidated by reads from any
@@ -395,7 +397,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
395397
this.emit_loan_invalidated_at(borrow_index, location);
396398
}
397399
}
398-
Control::Continue
400+
ControlFlow::Continue(())
399401
},
400402
);
401403
}

0 commit comments

Comments
 (0)