Skip to content

Commit 0438e25

Browse files
Remove control_flow_destroyed and properly lower && and ||
1 parent 89e2c1d commit 0438e25

File tree

8 files changed

+0
-77
lines changed

8 files changed

+0
-77
lines changed

src/librustc_middle/mir/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ pub struct Body<'tcx> {
148148
/// Debug information pertaining to user variables, including captures.
149149
pub var_debug_info: Vec<VarDebugInfo<'tcx>>,
150150

151-
/// Mark this MIR of a const context other than const functions as having converted a `&&` or
152-
/// `||` expression into `&` or `|` respectively. This is problematic because if we ever stop
153-
/// this conversion from happening and use short circuiting, we will cause the following code
154-
/// to change the value of `x`: `let mut x = 42; false && { x = 55; true };`
155-
///
156-
/// List of places where control flow was destroyed. Used for error reporting.
157-
pub control_flow_destroyed: Vec<(Span, String)>,
158-
159151
/// A span representing this MIR, for error reporting.
160152
pub span: Span,
161153

@@ -185,7 +177,6 @@ impl<'tcx> Body<'tcx> {
185177
arg_count: usize,
186178
var_debug_info: Vec<VarDebugInfo<'tcx>>,
187179
span: Span,
188-
control_flow_destroyed: Vec<(Span, String)>,
189180
generator_kind: Option<GeneratorKind>,
190181
) -> Self {
191182
// We need `arg_count` locals, and one for the return place.
@@ -212,7 +203,6 @@ impl<'tcx> Body<'tcx> {
212203
span,
213204
required_consts: Vec::new(),
214205
ignore_interior_mut_in_const_validation: false,
215-
control_flow_destroyed,
216206
predecessor_cache: PredecessorCache::new(),
217207
}
218208
}
@@ -236,7 +226,6 @@ impl<'tcx> Body<'tcx> {
236226
spread_arg: None,
237227
span: DUMMY_SP,
238228
required_consts: Vec::new(),
239-
control_flow_destroyed: Vec::new(),
240229
generator_kind: None,
241230
var_debug_info: Vec::new(),
242231
ignore_interior_mut_in_const_validation: false,

src/librustc_mir/shim.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ fn new_body<'tcx>(
251251
arg_count,
252252
vec![],
253253
span,
254-
vec![],
255254
None,
256255
)
257256
}

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ impl Validator<'mir, 'tcx> {
207207
}
208208
}
209209

210-
check_short_circuiting_in_const_local(self.ccx);
211-
212210
if body.is_cfg_cyclic() {
213211
// We can't provide a good span for the error here, but this should be caught by the
214212
// HIR const-checker anyways.
@@ -626,44 +624,6 @@ fn error_min_const_fn_violation(tcx: TyCtxt<'_>, span: Span, msg: Cow<'_, str>)
626624
.emit();
627625
}
628626

629-
fn check_short_circuiting_in_const_local(ccx: &ConstCx<'_, 'tcx>) {
630-
let body = ccx.body;
631-
632-
if body.control_flow_destroyed.is_empty() {
633-
return;
634-
}
635-
636-
let mut locals = body.vars_iter();
637-
if let Some(local) = locals.next() {
638-
let span = body.local_decls[local].source_info.span;
639-
let mut error = ccx.tcx.sess.struct_span_err(
640-
span,
641-
&format!(
642-
"new features like let bindings are not permitted in {}s \
643-
which also use short circuiting operators",
644-
ccx.const_kind(),
645-
),
646-
);
647-
for (span, kind) in body.control_flow_destroyed.iter() {
648-
error.span_note(
649-
*span,
650-
&format!(
651-
"use of {} here does not actually short circuit due to \
652-
the const evaluator presently not being able to do control flow. \
653-
See issue #49146 <https://github.com/rust-lang/rust/issues/49146> \
654-
for more information.",
655-
kind
656-
),
657-
);
658-
}
659-
for local in locals {
660-
let span = body.local_decls[local].source_info.span;
661-
error.span_note(span, "more locals are defined here");
662-
}
663-
error.emit();
664-
}
665-
}
666-
667627
fn check_return_ty_is_sync(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, hir_id: HirId) {
668628
let ty = body.return_ty();
669629
tcx.infer_ctxt().enter(|infcx| {

src/librustc_mir/transform/const_prop.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
133133
body.arg_count,
134134
Default::default(),
135135
tcx.def_span(source.def_id()),
136-
Default::default(),
137136
body.generator_kind,
138137
);
139138

src/librustc_mir/transform/promote_consts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ pub fn promote_candidates<'tcx>(
11421142
0,
11431143
vec![],
11441144
body.span,
1145-
vec![],
11461145
body.generator_kind,
11471146
);
11481147
promoted.ignore_interior_mut_in_const_validation = true;

src/librustc_mir_build/build/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
778778
self.arg_count,
779779
self.var_debug_info,
780780
self.fn_span,
781-
self.hir.control_flow_destroyed(),
782781
self.generator_kind,
783782
)
784783
}

src/librustc_mir_build/hair/cx/expr.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,6 @@ fn make_mirror_unadjusted<'a, 'tcx>(
255255
} else {
256256
// FIXME overflow
257257
match (op.node, cx.constness) {
258-
// Destroy control flow if `#![feature(const_if_match)]` is not enabled.
259-
(hir::BinOpKind::And, hir::Constness::Const)
260-
if !cx.tcx.features().const_if_match =>
261-
{
262-
cx.control_flow_destroyed.push((op.span, "`&&` operator".into()));
263-
ExprKind::Binary { op: BinOp::BitAnd, lhs: lhs.to_ref(), rhs: rhs.to_ref() }
264-
}
265-
(hir::BinOpKind::Or, hir::Constness::Const)
266-
if !cx.tcx.features().const_if_match =>
267-
{
268-
cx.control_flow_destroyed.push((op.span, "`||` operator".into()));
269-
ExprKind::Binary { op: BinOp::BitOr, lhs: lhs.to_ref(), rhs: rhs.to_ref() }
270-
}
271-
272258
(hir::BinOpKind::And, _) => ExprKind::LogicalOp {
273259
op: LogicalOp::And,
274260
lhs: lhs.to_ref(),

src/librustc_mir_build/hair/cx/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ crate struct Cx<'a, 'tcx> {
4747

4848
/// Whether this constant/function needs overflow checks.
4949
check_overflow: bool,
50-
51-
/// See field with the same name on `mir::Body`.
52-
control_flow_destroyed: Vec<(Span, String)>,
5350
}
5451

5552
impl<'a, 'tcx> Cx<'a, 'tcx> {
@@ -89,13 +86,8 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
8986
body_owner: src_def_id.to_def_id(),
9087
body_owner_kind,
9188
check_overflow,
92-
control_flow_destroyed: Vec::new(),
9389
}
9490
}
95-
96-
crate fn control_flow_destroyed(self) -> Vec<(Span, String)> {
97-
self.control_flow_destroyed
98-
}
9991
}
10092

10193
impl<'a, 'tcx> Cx<'a, 'tcx> {

0 commit comments

Comments
 (0)