Skip to content

Commit fac2726

Browse files
committedSep 4, 2020
Use ops::ControlFlow in graph::iterate
1 parent 0d0f6b1 commit fac2726

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed
 

‎compiler/rustc_data_structures/src/graph/iterate/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ where
8787
}
8888

8989
/// Allows searches to terminate early with a value.
90-
#[derive(Clone, Copy, Debug)]
91-
pub enum ControlFlow<T> {
92-
Break(T),
93-
Continue,
94-
}
90+
// FIXME (#75744): remove the alias once the generics are in a better order and `C=()`.
91+
pub type ControlFlow<T> = std::ops::ControlFlow<(), T>;
9592

9693
/// The status of a node in the depth-first search.
9794
///
@@ -260,12 +257,12 @@ where
260257
_node: G::Node,
261258
_prior_status: Option<NodeStatus>,
262259
) -> ControlFlow<Self::BreakVal> {
263-
ControlFlow::Continue
260+
ControlFlow::CONTINUE
264261
}
265262

266263
/// Called after all nodes reachable from this one have been examined.
267264
fn node_settled(&mut self, _node: G::Node) -> ControlFlow<Self::BreakVal> {
268-
ControlFlow::Continue
265+
ControlFlow::CONTINUE
269266
}
270267

271268
/// Behave as if no edges exist from `source` to `target`.
@@ -290,7 +287,7 @@ where
290287
) -> ControlFlow<Self::BreakVal> {
291288
match prior_status {
292289
Some(NodeStatus::Visited) => ControlFlow::Break(()),
293-
_ => ControlFlow::Continue,
290+
_ => ControlFlow::CONTINUE,
294291
}
295292
}
296293
}

‎compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
1010
#![allow(incomplete_features)]
11+
#![feature(control_flow_enum)]
1112
#![feature(in_band_lifetimes)]
1213
#![feature(unboxed_closures)]
1314
#![feature(generators)]

‎compiler/rustc_mir_build/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(box_syntax)]
77
#![feature(const_fn)]
88
#![feature(const_panic)]
9+
#![feature(control_flow_enum)]
910
#![feature(crate_visibility_modifier)]
1011
#![feature(bool_to_option)]
1112
#![feature(or_patterns)]

‎compiler/rustc_mir_build/src/lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
117117
// A diverging InlineAsm is treated as non-recursing
118118
TerminatorKind::InlineAsm { destination, .. } => {
119119
if destination.is_some() {
120-
ControlFlow::Continue
120+
ControlFlow::CONTINUE
121121
} else {
122122
ControlFlow::Break(NonRecursive)
123123
}
@@ -131,7 +131,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
131131
| TerminatorKind::FalseEdge { .. }
132132
| TerminatorKind::FalseUnwind { .. }
133133
| TerminatorKind::Goto { .. }
134-
| TerminatorKind::SwitchInt { .. } => ControlFlow::Continue,
134+
| TerminatorKind::SwitchInt { .. } => ControlFlow::CONTINUE,
135135
}
136136
}
137137

@@ -144,7 +144,7 @@ impl<'mir, 'tcx> TriColorVisitor<&'mir Body<'tcx>> for Search<'mir, 'tcx> {
144144
}
145145
}
146146

147-
ControlFlow::Continue
147+
ControlFlow::CONTINUE
148148
}
149149

150150
fn ignore_edge(&mut self, bb: BasicBlock, target: BasicBlock) -> bool {

‎library/core/src/iter/adapters/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ where
12731273
) -> impl FnMut((), T) -> ControlFlow<(), B> + '_ {
12741274
move |(), x| match f(x) {
12751275
Some(x) => ControlFlow::Break(x),
1276-
None => ControlFlow::Continue(()),
1276+
None => ControlFlow::CONTINUE,
12771277
}
12781278
}
12791279

‎library/core/src/iter/traits/double_ended.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub trait DoubleEndedIterator: Iterator {
310310
mut predicate: impl FnMut(&T) -> bool,
311311
) -> impl FnMut((), T) -> ControlFlow<(), T> {
312312
move |(), x| {
313-
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(()) }
313+
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::CONTINUE }
314314
}
315315
}
316316

‎library/core/src/ops/control_flow.rs

+7
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ impl<R: Try> ControlFlow<R::Ok, R> {
6565
}
6666
}
6767
}
68+
69+
impl<B> ControlFlow<(), B> {
70+
/// It's frequently the case that there's no value needed with `Continue`,
71+
/// so this provides a way to avoid typing `(())`, if you prefer it.
72+
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
73+
pub const CONTINUE: Self = ControlFlow::Continue(());
74+
}

0 commit comments

Comments
 (0)
Please sign in to comment.