From f33a75c20ced68f5f9b384ab213ced26a1276107 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 12:12:46 -0700 Subject: [PATCH] Remove `control_flow_destroyed` and properly lower `&&` and `||` --- src/librustc_middle/mir/mod.rs | 11 ----- src/librustc_mir/shim.rs | 1 - .../transform/check_consts/validation.rs | 40 ------------------- src/librustc_mir/transform/const_prop.rs | 1 - src/librustc_mir/transform/promote_consts.rs | 1 - src/librustc_mir_build/build/mod.rs | 1 - src/librustc_mir_build/hair/cx/expr.rs | 14 ------- src/librustc_mir_build/hair/cx/mod.rs | 8 ---- 8 files changed, 77 deletions(-) diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index b3e410f362d..d54c6db6d5e 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -148,14 +148,6 @@ pub struct Body<'tcx> { /// Debug information pertaining to user variables, including captures. pub var_debug_info: Vec>, - /// Mark this MIR of a const context other than const functions as having converted a `&&` or - /// `||` expression into `&` or `|` respectively. This is problematic because if we ever stop - /// this conversion from happening and use short circuiting, we will cause the following code - /// to change the value of `x`: `let mut x = 42; false && { x = 55; true };` - /// - /// List of places where control flow was destroyed. Used for error reporting. - pub control_flow_destroyed: Vec<(Span, String)>, - /// A span representing this MIR, for error reporting. pub span: Span, @@ -185,7 +177,6 @@ impl<'tcx> Body<'tcx> { arg_count: usize, var_debug_info: Vec>, span: Span, - control_flow_destroyed: Vec<(Span, String)>, generator_kind: Option, ) -> Self { // We need `arg_count` locals, and one for the return place. @@ -212,7 +203,6 @@ impl<'tcx> Body<'tcx> { span, required_consts: Vec::new(), ignore_interior_mut_in_const_validation: false, - control_flow_destroyed, predecessor_cache: PredecessorCache::new(), } } @@ -236,7 +226,6 @@ impl<'tcx> Body<'tcx> { spread_arg: None, span: DUMMY_SP, required_consts: Vec::new(), - control_flow_destroyed: Vec::new(), generator_kind: None, var_debug_info: Vec::new(), ignore_interior_mut_in_const_validation: false, diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 8327affd982..5671b5b4f04 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -251,7 +251,6 @@ fn new_body<'tcx>( arg_count, vec![], span, - vec![], None, ) } diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index d263bf12e88..238ad703fb0 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -207,8 +207,6 @@ impl Validator<'mir, 'tcx> { } } - check_short_circuiting_in_const_local(self.ccx); - if body.is_cfg_cyclic() { // We can't provide a good span for the error here, but this should be caught by the // HIR const-checker anyways. @@ -626,44 +624,6 @@ fn error_min_const_fn_violation(tcx: TyCtxt<'_>, span: Span, msg: Cow<'_, str>) .emit(); } -fn check_short_circuiting_in_const_local(ccx: &ConstCx<'_, 'tcx>) { - let body = ccx.body; - - if body.control_flow_destroyed.is_empty() { - return; - } - - let mut locals = body.vars_iter(); - if let Some(local) = locals.next() { - let span = body.local_decls[local].source_info.span; - let mut error = ccx.tcx.sess.struct_span_err( - span, - &format!( - "new features like let bindings are not permitted in {}s \ - which also use short circuiting operators", - ccx.const_kind(), - ), - ); - for (span, kind) in body.control_flow_destroyed.iter() { - error.span_note( - *span, - &format!( - "use of {} here does not actually short circuit due to \ - the const evaluator presently not being able to do control flow. \ - See issue #49146 \ - for more information.", - kind - ), - ); - } - for local in locals { - let span = body.local_decls[local].source_info.span; - error.span_note(span, "more locals are defined here"); - } - error.emit(); - } -} - fn check_return_ty_is_sync(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, hir_id: HirId) { let ty = body.return_ty(); tcx.infer_ctxt().enter(|infcx| { diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index a891f12c8e1..5d0d7c15478 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -133,7 +133,6 @@ impl<'tcx> MirPass<'tcx> for ConstProp { body.arg_count, Default::default(), tcx.def_span(source.def_id()), - Default::default(), body.generator_kind, ); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 8bcbcd79ae6..bd7ebaa01f8 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -1142,7 +1142,6 @@ pub fn promote_candidates<'tcx>( 0, vec![], body.span, - vec![], body.generator_kind, ); promoted.ignore_interior_mut_in_const_validation = true; diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index e2cf1bce733..e69f6b30abd 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -778,7 +778,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.arg_count, self.var_debug_info, self.fn_span, - self.hir.control_flow_destroyed(), self.generator_kind, ) } diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index a1796c9433e..d36990684e0 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -255,20 +255,6 @@ fn make_mirror_unadjusted<'a, 'tcx>( } else { // FIXME overflow match (op.node, cx.constness) { - // Destroy control flow if `#![feature(const_if_match)]` is not enabled. - (hir::BinOpKind::And, hir::Constness::Const) - if !cx.tcx.features().const_if_match => - { - cx.control_flow_destroyed.push((op.span, "`&&` operator".into())); - ExprKind::Binary { op: BinOp::BitAnd, lhs: lhs.to_ref(), rhs: rhs.to_ref() } - } - (hir::BinOpKind::Or, hir::Constness::Const) - if !cx.tcx.features().const_if_match => - { - cx.control_flow_destroyed.push((op.span, "`||` operator".into())); - ExprKind::Binary { op: BinOp::BitOr, lhs: lhs.to_ref(), rhs: rhs.to_ref() } - } - (hir::BinOpKind::And, _) => ExprKind::LogicalOp { op: LogicalOp::And, lhs: lhs.to_ref(), diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/hair/cx/mod.rs index 46607fd07cd..d8b3ac79e6b 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/hair/cx/mod.rs @@ -47,9 +47,6 @@ crate struct Cx<'a, 'tcx> { /// Whether this constant/function needs overflow checks. check_overflow: bool, - - /// See field with the same name on `mir::Body`. - control_flow_destroyed: Vec<(Span, String)>, } impl<'a, 'tcx> Cx<'a, 'tcx> { @@ -89,13 +86,8 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { body_owner: src_def_id.to_def_id(), body_owner_kind, check_overflow, - control_flow_destroyed: Vec::new(), } } - - crate fn control_flow_destroyed(self) -> Vec<(Span, String)> { - self.control_flow_destroyed - } } impl<'a, 'tcx> Cx<'a, 'tcx> {