From 66f0cef1b1284b3c4f8d94c1bed0b4fda3d2053c Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 11:44:45 -0700 Subject: [PATCH 01/14] Mark feature gate as accepted --- src/librustc_feature/accepted.rs | 2 ++ src/librustc_feature/active.rs | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc_feature/accepted.rs b/src/librustc_feature/accepted.rs index 18dc3e30db1..28a08330d49 100644 --- a/src/librustc_feature/accepted.rs +++ b/src/librustc_feature/accepted.rs @@ -261,6 +261,8 @@ declare_features! ( (accepted, transparent_enums, "1.42.0", Some(60405), None), /// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`. (accepted, slice_patterns, "1.42.0", Some(62254), None), + /// Allows the use of `if` and `match` in constants. + (accepted, const_if_match, "1.45.0", Some(49146), None), // ------------------------------------------------------------------------- // feature-group-end: accepted features diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index e2d497a3ada..a80ac3105ce 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -518,9 +518,6 @@ declare_features! ( /// Allows using the `#[register_tool]` attribute. (active, register_tool, "1.41.0", Some(66079), None), - /// Allows the use of `if` and `match` in constants. - (active, const_if_match, "1.41.0", Some(49146), None), - /// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used. (active, cfg_sanitize, "1.41.0", Some(39699), None), From f33a75c20ced68f5f9b384ab213ced26a1276107 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 12:12:46 -0700 Subject: [PATCH 02/14] 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> { From 48ebd2cdb8f9a9010a345349304edaa757d3e4cc Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 12:18:32 -0700 Subject: [PATCH 03/14] Remove `const_if_match` feature gate from libraries --- src/liballoc/lib.rs | 2 +- src/libcore/lib.rs | 2 +- src/libcore/num/mod.rs | 6 +++--- src/librustc_ast/lib.rs | 2 +- src/librustc_hir/lib.rs | 2 +- src/librustc_index/lib.rs | 2 +- src/librustc_infer/lib.rs | 2 +- src/librustc_middle/lib.rs | 2 +- src/librustc_mir/lib.rs | 2 +- src/librustc_mir_build/lib.rs | 2 +- src/librustc_query_system/lib.rs | 2 +- src/librustc_span/lib.rs | 2 +- src/librustc_target/lib.rs | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 41c2b221704..5f18fe8bfab 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -87,7 +87,7 @@ #![feature(const_generic_impls_guard)] #![feature(const_generics)] #![feature(const_in_array_repeat_expressions)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(cow_is_borrowed)] #![feature(dispatch_from_dyn)] #![feature(core_intrinsics)] diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 2b26e5303a8..1391dc7a953 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -73,7 +73,7 @@ #![feature(const_ascii_ctype_on_intrinsics)] #![feature(const_alloc_layout)] #![feature(const_discriminant)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_loop)] #![feature(const_checked_int_methods)] #![feature(const_euclidean_int_methods)] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index b1317bc2121..1714d2ee98e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1578,7 +1578,7 @@ $EndFeature, " #[stable(feature = "no_panic_abs", since = "1.13.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[allow(unused_attributes)] - #[allow_internal_unstable(const_if_match)] + #[cfg_attr(bootstrap, allow_internal_unstable(const_if_match))] #[inline] pub const fn wrapping_abs(self) -> Self { if self.is_negative() { @@ -1867,7 +1867,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self #[stable(feature = "wrapping", since = "1.7.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[allow(unused_attributes)] - #[allow_internal_unstable(const_if_match)] + #[cfg_attr(bootstrap, allow_internal_unstable(const_if_match))] pub const fn overflowing_neg(self) -> (Self, bool) { if self == Self::MIN { (Self::MIN, true) @@ -2160,7 +2160,7 @@ $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] #[allow(unused_attributes)] - #[allow_internal_unstable(const_if_match)] + #[cfg_attr(bootstrap, allow_internal_unstable(const_if_match))] #[inline] #[rustc_inherit_overflow_checks] pub const fn abs(self) -> Self { diff --git a/src/librustc_ast/lib.rs b/src/librustc_ast/lib.rs index cb3118cba23..5c1c9d6ab90 100644 --- a/src/librustc_ast/lib.rs +++ b/src/librustc_ast/lib.rs @@ -7,7 +7,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/", test(attr(deny(warnings))))] #![feature(bool_to_option)] #![feature(box_syntax)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] // For the `transmute` in `P::new` #![feature(const_panic)] #![feature(const_transmute)] diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs index b51c0a6e988..20ac2a04b47 100644 --- a/src/librustc_hir/lib.rs +++ b/src/librustc_hir/lib.rs @@ -3,7 +3,7 @@ //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html #![feature(crate_visibility_modifier)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] // For the unsizing cast on `&[]` #![feature(const_panic)] #![feature(in_band_lifetimes)] diff --git a/src/librustc_index/lib.rs b/src/librustc_index/lib.rs index 3effc416450..6fef49668da 100644 --- a/src/librustc_index/lib.rs +++ b/src/librustc_index/lib.rs @@ -1,5 +1,5 @@ #![feature(allow_internal_unstable)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] #![feature(const_panic)] #![feature(extend_one)] diff --git a/src/librustc_infer/lib.rs b/src/librustc_infer/lib.rs index 0f3f3db8679..27e086f1d50 100644 --- a/src/librustc_infer/lib.rs +++ b/src/librustc_infer/lib.rs @@ -17,7 +17,7 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(const_fn)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_panic)] #![feature(extend_one)] #![feature(never_type)] diff --git a/src/librustc_middle/lib.rs b/src/librustc_middle/lib.rs index 82dff60a26d..676346fbebd 100644 --- a/src/librustc_middle/lib.rs +++ b/src/librustc_middle/lib.rs @@ -27,7 +27,7 @@ #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] #![feature(const_panic)] #![feature(const_transmute)] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 928d5bf88f2..d64105f3b99 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -10,7 +10,7 @@ Rust MIR: a lowered representation of Rust. #![feature(box_patterns)] #![feature(box_syntax)] #![feature(const_fn)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_loop)] #![feature(const_panic)] #![feature(crate_visibility_modifier)] diff --git a/src/librustc_mir_build/lib.rs b/src/librustc_mir_build/lib.rs index c6d65d56c93..b44d8eee462 100644 --- a/src/librustc_mir_build/lib.rs +++ b/src/librustc_mir_build/lib.rs @@ -4,7 +4,7 @@ #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] #![feature(const_panic)] #![feature(crate_visibility_modifier)] diff --git a/src/librustc_query_system/lib.rs b/src/librustc_query_system/lib.rs index 3afc4565933..74a54176774 100644 --- a/src/librustc_query_system/lib.rs +++ b/src/librustc_query_system/lib.rs @@ -1,6 +1,6 @@ #![feature(bool_to_option)] #![feature(const_fn)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_panic)] #![feature(core_intrinsics)] #![feature(hash_raw_entry)] diff --git a/src/librustc_span/lib.rs b/src/librustc_span/lib.rs index dcd2e83b747..6dcb1430cdc 100644 --- a/src/librustc_span/lib.rs +++ b/src/librustc_span/lib.rs @@ -6,7 +6,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(crate_visibility_modifier)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] #![feature(const_panic)] #![feature(negative_impls)] diff --git a/src/librustc_target/lib.rs b/src/librustc_target/lib.rs index c2cdd2fd3ec..ec6deb5b059 100644 --- a/src/librustc_target/lib.rs +++ b/src/librustc_target/lib.rs @@ -9,7 +9,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(bool_to_option)] -#![feature(const_if_match)] +#![cfg_attr(bootstrap, feature(const_if_match))] #![feature(const_fn)] #![feature(const_panic)] #![feature(nll)] From 4c2383810bb783095e285ba56c5ecb3efe139dda Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 12:46:49 -0700 Subject: [PATCH 04/14] MIR const-checking --- src/librustc_mir/transform/check_consts/ops.rs | 13 ------------- .../transform/check_consts/validation.rs | 11 +---------- src/librustc_mir/transform/qualify_min_const_fn.rs | 10 ---------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 676688daf1c..814437faa58 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -142,19 +142,6 @@ impl NonConstOp for HeapAllocation { } } -#[derive(Debug)] -pub struct IfOrMatch; -impl NonConstOp for IfOrMatch { - fn feature_gate() -> Option { - Some(sym::const_if_match) - } - - fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) { - // This should be caught by the HIR const-checker. - ccx.tcx.sess.delay_span_bug(span, "complex control flow is forbidden in a const context"); - } -} - #[derive(Debug)] pub struct InlineAsm; impl NonConstOp for InlineAsm {} diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 238ad703fb0..a10e3ee9372 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -481,21 +481,12 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { self.super_statement(statement, location); } - StatementKind::FakeRead( - FakeReadCause::ForMatchedPlace - | FakeReadCause::ForMatchGuard - | FakeReadCause::ForGuardBinding, - _, - ) => { - self.super_statement(statement, location); - self.check_op(ops::IfOrMatch); - } StatementKind::LlvmInlineAsm { .. } => { self.super_statement(statement, location); self.check_op(ops::InlineAsm); } - StatementKind::FakeRead(FakeReadCause::ForLet | FakeReadCause::ForIndex, _) + StatementKind::FakeRead(..) | StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Retag { .. } diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index caf6c7715a9..5a3663384fb 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -239,12 +239,6 @@ fn check_statement( check_rvalue(tcx, body, def_id, rval, span) } - StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) - if !feature_allowed(tcx, def_id, sym::const_if_match) => - { - Err((span, "loops and conditional expressions are not stable in const fn".into())) - } - StatementKind::FakeRead(_, place) => check_place(tcx, **place, span, def_id, body), // just an assignment @@ -355,10 +349,6 @@ fn check_terminator( check_operand(tcx, value, span, def_id, body) } - TerminatorKind::SwitchInt { .. } if !feature_allowed(tcx, def_id, sym::const_if_match) => { - Err((span, "loops and conditional expressions are not stable in const fn".into())) - } - TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => { check_operand(tcx, discr, span, def_id, body) } From 696084c764e5fe3a318eb75a180763fdeab194da Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 12:47:09 -0700 Subject: [PATCH 05/14] HIR const-checking --- src/librustc_passes/check_const.rs | 47 +++++++----------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 90a076eeded..22a65b6730a 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -23,7 +23,6 @@ use rustc_span::{sym, Span, Symbol}; enum NonConstExpr { Loop(hir::LoopSource), Match(hir::MatchSource), - OrPattern, } impl NonConstExpr { @@ -31,7 +30,6 @@ impl NonConstExpr { match self { Self::Loop(src) => format!("`{}`", src.name()), Self::Match(src) => format!("`{}`", src.name()), - Self::OrPattern => "or-pattern".to_string(), } } @@ -40,22 +38,19 @@ impl NonConstExpr { use hir::MatchSource::*; let gates: &[_] = match self { - Self::Match(Normal) - | Self::Match(IfDesugar { .. }) - | Self::Match(IfLetDesugar { .. }) - | Self::OrPattern => &[sym::const_if_match], - - Self::Loop(Loop) => &[sym::const_loop], - - Self::Loop(While) - | Self::Loop(WhileLet) - | Self::Match(WhileDesugar | WhileLetDesugar) => { - &[sym::const_loop, sym::const_if_match] - } - // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`, // so they are not yet allowed with `#![feature(const_loop)]`. - _ => return None, + // Likewise, `?` desugars to a call to `Try::into_result`. + Self::Loop(ForLoop) | Self::Match(ForLoopDesugar | TryDesugar | AwaitDesugar) => { + return None; + } + + Self::Loop(Loop | While | WhileLet) | Self::Match(WhileDesugar | WhileLetDesugar) => { + &[sym::const_loop] + } + + // All other matches are allowed. + Self::Match(Normal | IfDesugar { .. } | IfLetDesugar { .. }) => &[], }; Some(gates) @@ -114,17 +109,6 @@ impl<'tcx> CheckConstVisitor<'tcx> { match missing_gates.as_slice() { &[] => struct_span_err!(self.tcx.sess, span, E0744, "{}", msg).emit(), - // If the user enabled `#![feature(const_loop)]` but not `#![feature(const_if_match)]`, - // explain why their `while` loop is being rejected. - &[gate @ sym::const_if_match] if required_gates.contains(&sym::const_loop) => { - feature_err(&self.tcx.sess.parse_sess, gate, span, &msg) - .note( - "`#![feature(const_loop)]` alone is not sufficient, \ - since this loop expression contains an implicit conditional", - ) - .emit(); - } - &[missing_primary, ref missing_secondary @ ..] => { let mut err = feature_err(&self.tcx.sess.parse_sess, missing_primary, span, &msg); @@ -175,15 +159,6 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { self.recurse_into(kind, |this| intravisit::walk_body(this, body)); } - fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) { - if self.const_kind.is_some() { - if let hir::PatKind::Or { .. } = p.kind { - self.const_check_violated(NonConstExpr::OrPattern, p.span); - } - } - intravisit::walk_pat(self, p) - } - fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { match &e.kind { // Skip the following checks if we are not currently in a const context. From d6139f76c072e281a77a5eac9ba57a0eb3a1936f Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 12:49:38 -0700 Subject: [PATCH 06/14] Update tests --- .../subslice-patterns-const-eval-match.rs | 3 +- src/test/ui/borrowck/issue-64453.rs | 4 +- src/test/ui/borrowck/issue-64453.stderr | 23 +- .../ui/consts/const-eval/infinite_loop.rs | 1 - .../ui/consts/const-eval/infinite_loop.stderr | 13 +- .../ui/consts/const-eval/issue-52475.stderr | 1 - .../consts/const-eval/match-test-ptr-null.rs | 1 - .../const-eval/match-test-ptr-null.stderr | 17 +- src/test/ui/consts/const-labeled-break.stderr | 1 - src/test/ui/consts/const-match-pattern-arm.rs | 8 +- .../ui/consts/const-match-pattern-arm.stderr | 28 -- .../const_in_pattern/custom-eq-branch-pass.rs | 1 - .../const_in_pattern/custom-eq-branch-warn.rs | 1 - .../custom-eq-branch-warn.stderr | 4 +- .../const_in_pattern/no-eq-branch-fail.rs | 1 - .../const_in_pattern/no-eq-branch-fail.stderr | 4 +- src/test/ui/consts/const_let_refutable.rs | 1 - src/test/ui/consts/const_let_refutable.stderr | 14 +- .../const_eval_limit_not_reached.rs | 2 +- .../const_limit/const_eval_limit_reached.rs | 5 +- .../const_eval_limit_reached.stderr | 2 +- src/test/ui/consts/const_short_circuit.rs | 4 +- src/test/ui/consts/const_short_circuit.stderr | 26 -- .../ui/consts/control-flow/assert.both.stderr | 13 - .../control-flow/assert.if_match.stderr | 23 -- .../consts/control-flow/assert.panic.stderr | 24 +- src/test/ui/consts/control-flow/assert.rs | 15 +- .../consts/control-flow/assert.stock.stderr | 16 +- src/test/ui/consts/control-flow/basics.rs | 1 - .../control-flow/drop-fail.precise.stderr | 4 +- src/test/ui/consts/control-flow/drop-fail.rs | 1 - .../control-flow/drop-fail.stock.stderr | 8 +- src/test/ui/consts/control-flow/drop-pass.rs | 1 - .../ui/consts/control-flow/drop-precise.rs | 1 - .../exhaustive-c-like-enum-match.rs | 2 - ...eature-gate-const-if-match.if_match.stderr | 14 - .../feature-gate-const-if-match.rs | 95 +++---- .../feature-gate-const-if-match.stock.stderr | 242 ------------------ .../control-flow/interior-mutability.rs | 2 - .../control-flow/interior-mutability.stderr | 6 +- .../ui/consts/control-flow/issue-46843.rs | 12 +- ...843.if_match.stderr => issue-46843.stderr} | 2 +- .../control-flow/issue-46843.stock.stderr | 18 -- .../ui/consts/control-flow/issue-50577.rs | 11 +- ...577.if_match.stderr => issue-50577.stderr} | 4 +- .../control-flow/issue-50577.stock.stderr | 47 ---- .../ui/consts/control-flow/loop.both.stderr | 19 -- .../consts/control-flow/loop.if_match.stderr | 151 ----------- .../ui/consts/control-flow/loop.loop_.stderr | 85 +----- src/test/ui/consts/control-flow/loop.rs | 40 ++- .../ui/consts/control-flow/loop.stock.stderr | 59 ++--- .../consts/control-flow/short-circuit-let.rs | 1 - .../short-circuit.if_match.stderr | 8 - .../ui/consts/control-flow/short-circuit.rs | 18 +- .../control-flow/short-circuit.stock.stderr | 23 -- .../control-flow/single_variant_match_ice.rs | 2 - src/test/ui/consts/control-flow/try.rs | 2 - src/test/ui/consts/control-flow/try.stderr | 2 +- .../ui/consts/min_const_fn/min_const_fn.rs | 8 +- .../consts/min_const_fn/min_const_fn.stderr | 22 +- .../const_refers_to_static_cross_crate.rs | 3 +- .../const_refers_to_static_cross_crate.stderr | 53 ++-- .../ui/consts/unstable-const-fn-in-libcore.rs | 1 - .../unstable-const-fn-in-libcore.stderr | 6 +- src/test/ui/enum-discriminant/niche.rs | 1 - .../ui/internal/internal-unstable-const.rs | 6 +- .../internal/internal-unstable-const.stderr | 13 +- src/test/ui/issues/issue-51714.stderr | 1 - src/test/ui/issues/issue-66706.rs | 1 - src/test/ui/issues/issue-66706.stderr | 13 +- .../{feature-gate-const-fn.rs => const-fn.rs} | 7 +- .../or-patterns/feature-gate-const-fn.stderr | 57 ----- .../ui/return/return-match-array-const.rs | 3 - .../ui/return/return-match-array-const.stderr | 36 +-- .../disallowed-positions.rs | 3 - .../disallowed-positions.stderr | 37 +-- .../hir-const-check.rs | 2 +- .../hir-const-check.stderr | 10 +- 78 files changed, 228 insertions(+), 1192 deletions(-) delete mode 100644 src/test/ui/consts/const-match-pattern-arm.stderr delete mode 100644 src/test/ui/consts/const_short_circuit.stderr delete mode 100644 src/test/ui/consts/control-flow/assert.both.stderr delete mode 100644 src/test/ui/consts/control-flow/assert.if_match.stderr delete mode 100644 src/test/ui/consts/control-flow/feature-gate-const-if-match.if_match.stderr delete mode 100644 src/test/ui/consts/control-flow/feature-gate-const-if-match.stock.stderr rename src/test/ui/consts/control-flow/{issue-46843.if_match.stderr => issue-46843.stderr} (90%) delete mode 100644 src/test/ui/consts/control-flow/issue-46843.stock.stderr rename src/test/ui/consts/control-flow/{issue-50577.if_match.stderr => issue-50577.stderr} (88%) delete mode 100644 src/test/ui/consts/control-flow/issue-50577.stock.stderr delete mode 100644 src/test/ui/consts/control-flow/loop.both.stderr delete mode 100644 src/test/ui/consts/control-flow/loop.if_match.stderr delete mode 100644 src/test/ui/consts/control-flow/short-circuit.if_match.stderr delete mode 100644 src/test/ui/consts/control-flow/short-circuit.stock.stderr rename src/test/ui/or-patterns/{feature-gate-const-fn.rs => const-fn.rs} (56%) delete mode 100644 src/test/ui/or-patterns/feature-gate-const-fn.stderr diff --git a/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs b/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs index 69c33921868..d8a9ae6ca20 100644 --- a/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs +++ b/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs @@ -2,7 +2,8 @@ // run-pass -#![feature(const_fn, const_if_match)] +#![feature(const_fn)] + #[derive(PartialEq, Debug, Clone)] struct N(u8); diff --git a/src/test/ui/borrowck/issue-64453.rs b/src/test/ui/borrowck/issue-64453.rs index 8a405edb046..3e803f3b6d8 100644 --- a/src/test/ui/borrowck/issue-64453.rs +++ b/src/test/ui/borrowck/issue-64453.rs @@ -2,7 +2,8 @@ struct Project; struct Value; static settings_dir: String = format!(""); -//~^ ERROR `match` is not allowed in a `static` +//~^ ERROR calls in statics are limited to constant functions +//~| ERROR calls in statics are limited to constant functions fn from_string(_: String) -> Value { Value @@ -11,6 +12,7 @@ fn set_editor(_: Value) {} fn main() { let settings_data = from_string(settings_dir); + //~^ ERROR cannot move out of static item let args: i32 = 0; match args { diff --git a/src/test/ui/borrowck/issue-64453.stderr b/src/test/ui/borrowck/issue-64453.stderr index 48859fb6763..081ccd37861 100644 --- a/src/test/ui/borrowck/issue-64453.stderr +++ b/src/test/ui/borrowck/issue-64453.stderr @@ -1,13 +1,26 @@ -error[E0658]: `match` is not allowed in a `static` +error[E0507]: cannot move out of static item `settings_dir` + --> $DIR/issue-64453.rs:14:37 + | +LL | let settings_data = from_string(settings_dir); + | ^^^^^^^^^^^^ move occurs because `settings_dir` has type `std::string::String`, which does not implement the `Copy` trait + +error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants --> $DIR/issue-64453.rs:4:31 | LL | static settings_dir: String = format!(""); | ^^^^^^^^^^^ | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-64453.rs:4:31 + | +LL | static settings_dir: String = format!(""); + | ^^^^^^^^^^^ + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -For more information about this error, try `rustc --explain E0658`. +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0015, E0507. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs index c8de259354e..7c2c40dd6fc 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.rs +++ b/src/test/ui/consts/const-eval/infinite_loop.rs @@ -7,7 +7,6 @@ fn main() { //~^ ERROR `while` is not allowed in a `const` n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; //~^ ERROR evaluation of constant value failed - //~| ERROR `if` is not allowed in a `const` } n }]; diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr index 3386e6e588e..df96f32516c 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.stderr +++ b/src/test/ui/consts/const-eval/infinite_loop.stderr @@ -5,22 +5,11 @@ LL | / while n != 0 { LL | | LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; LL | | -LL | | LL | | } | |_________^ | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/infinite_loop.rs:8:17 - | -LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0080]: evaluation of constant value failed --> $DIR/infinite_loop.rs:8:17 @@ -28,7 +17,7 @@ error[E0080]: evaluation of constant value failed LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`) -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0080, E0658. For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-52475.stderr b/src/test/ui/consts/const-eval/issue-52475.stderr index b069537ead9..c41000e7135 100644 --- a/src/test/ui/consts/const-eval/issue-52475.stderr +++ b/src/test/ui/consts/const-eval/issue-52475.stderr @@ -10,7 +10,6 @@ LL | | } | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0080]: evaluation of constant value failed --> $DIR/issue-52475.rs:7:17 diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.rs b/src/test/ui/consts/const-eval/match-test-ptr-null.rs index 80494d16629..f6b5ad005a8 100644 --- a/src/test/ui/consts/const-eval/match-test-ptr-null.rs +++ b/src/test/ui/consts/const-eval/match-test-ptr-null.rs @@ -5,7 +5,6 @@ fn main() { let _: [u8; 0] = [4; { match &1 as *const i32 as usize { //~^ ERROR casting pointers to integers in constants - //~| ERROR `match` is not allowed in a `const` //~| ERROR evaluation of constant value failed 0 => 42, n => n, diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.stderr b/src/test/ui/consts/const-eval/match-test-ptr-null.stderr index b47f6d5f845..48dbe661492 100644 --- a/src/test/ui/consts/const-eval/match-test-ptr-null.stderr +++ b/src/test/ui/consts/const-eval/match-test-ptr-null.stderr @@ -1,18 +1,3 @@ -error[E0658]: `match` is not allowed in a `const` - --> $DIR/match-test-ptr-null.rs:6:9 - | -LL | / match &1 as *const i32 as usize { -LL | | -LL | | -LL | | -LL | | 0 => 42, -LL | | n => n, -LL | | } - | |_________^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - error[E0658]: casting pointers to integers in constants is unstable --> $DIR/match-test-ptr-null.rs:6:15 | @@ -28,7 +13,7 @@ error[E0080]: evaluation of constant value failed LL | match &1 as *const i32 as usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0080, E0658. For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-labeled-break.stderr b/src/test/ui/consts/const-labeled-break.stderr index ac845df227c..1e24bb4ab98 100644 --- a/src/test/ui/consts/const-labeled-break.stderr +++ b/src/test/ui/consts/const-labeled-break.stderr @@ -6,7 +6,6 @@ LL | const CRASH: () = 'a: while break 'a {}; | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/consts/const-match-pattern-arm.rs b/src/test/ui/consts/const-match-pattern-arm.rs index 0482f7f7dae..90680c0194c 100644 --- a/src/test/ui/consts/const-match-pattern-arm.rs +++ b/src/test/ui/consts/const-match-pattern-arm.rs @@ -1,12 +1,12 @@ -#![allow(warnings)] +// check-pass -const x: bool = match Some(true) { //~ ERROR `match` is not allowed in a `const` +const _: bool = match Some(true) { Some(value) => true, _ => false }; -const y: bool = { - match Some(true) { //~ ERROR `match` is not allowed in a `const` +const _: bool = { + match Some(true) { Some(value) => true, _ => false } diff --git a/src/test/ui/consts/const-match-pattern-arm.stderr b/src/test/ui/consts/const-match-pattern-arm.stderr deleted file mode 100644 index 412e1609ccf..00000000000 --- a/src/test/ui/consts/const-match-pattern-arm.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error[E0658]: `match` is not allowed in a `const` - --> $DIR/const-match-pattern-arm.rs:3:17 - | -LL | const x: bool = match Some(true) { - | _________________^ -LL | | Some(value) => true, -LL | | _ => false -LL | | }; - | |_^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/const-match-pattern-arm.rs:9:5 - | -LL | / match Some(true) { -LL | | Some(value) => true, -LL | | _ => false -LL | | } - | |_____^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const_in_pattern/custom-eq-branch-pass.rs b/src/test/ui/consts/const_in_pattern/custom-eq-branch-pass.rs index 81a2024a81b..a38731ceb8a 100644 --- a/src/test/ui/consts/const_in_pattern/custom-eq-branch-pass.rs +++ b/src/test/ui/consts/const_in_pattern/custom-eq-branch-pass.rs @@ -1,6 +1,5 @@ // run-pass -#![feature(const_if_match)] #![warn(indirect_structural_match)] struct CustomEq; diff --git a/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.rs b/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.rs index 21c4de6fbb1..a1f9838ca08 100644 --- a/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.rs +++ b/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.rs @@ -1,6 +1,5 @@ // check-pass -#![feature(const_if_match)] #![warn(indirect_structural_match)] //~^ NOTE lint level is defined here diff --git a/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr b/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr index 06ec2a7fdd3..0be1cca806e 100644 --- a/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr +++ b/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr @@ -1,11 +1,11 @@ warning: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]` - --> $DIR/custom-eq-branch-warn.rs:33:9 + --> $DIR/custom-eq-branch-warn.rs:32:9 | LL | BAR_BAZ => panic!(), | ^^^^^^^ | note: the lint level is defined here - --> $DIR/custom-eq-branch-warn.rs:4:9 + --> $DIR/custom-eq-branch-warn.rs:3:9 | LL | #![warn(indirect_structural_match)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.rs b/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.rs index 28b3fbb9525..c7f02c615a0 100644 --- a/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.rs +++ b/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.rs @@ -1,4 +1,3 @@ -#![feature(const_if_match)] #![warn(indirect_structural_match)] struct NoEq; diff --git a/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.stderr b/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.stderr index cb870ec7dbc..ee78c6f5c3e 100644 --- a/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.stderr +++ b/src/test/ui/consts/const_in_pattern/no-eq-branch-fail.stderr @@ -1,11 +1,11 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]` - --> $DIR/no-eq-branch-fail.rs:22:9 + --> $DIR/no-eq-branch-fail.rs:21:9 | LL | BAR_BAZ => panic!(), | ^^^^^^^ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]` - --> $DIR/no-eq-branch-fail.rs:22:9 + --> $DIR/no-eq-branch-fail.rs:21:9 | LL | BAR_BAZ => panic!(), | ^^^^^^^ diff --git a/src/test/ui/consts/const_let_refutable.rs b/src/test/ui/consts/const_let_refutable.rs index e49d4767391..efb134d2eef 100644 --- a/src/test/ui/consts/const_let_refutable.rs +++ b/src/test/ui/consts/const_let_refutable.rs @@ -2,6 +2,5 @@ fn main() {} const fn slice(&[a, b]: &[i32]) -> i32 { //~^ ERROR refutable pattern in function argument - //~| ERROR loops and conditional expressions are not stable in const fn a + b } diff --git a/src/test/ui/consts/const_let_refutable.stderr b/src/test/ui/consts/const_let_refutable.stderr index 02296e6de75..d7e8c048f7d 100644 --- a/src/test/ui/consts/const_let_refutable.stderr +++ b/src/test/ui/consts/const_let_refutable.stderr @@ -6,16 +6,6 @@ LL | const fn slice(&[a, b]: &[i32]) -> i32 { | = note: the matched value is of type `&[i32]` -error[E0723]: loops and conditional expressions are not stable in const fn - --> $DIR/const_let_refutable.rs:3:17 - | -LL | const fn slice(&[a, b]: &[i32]) -> i32 { - | ^^^^^^ - | - = note: see issue #57563 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable +error: aborting due to previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0005, E0723. -For more information about an error, try `rustc --explain E0005`. +For more information about this error, try `rustc --explain E0005`. diff --git a/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs b/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs index 34abcdf08da..fa56de065ae 100644 --- a/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs +++ b/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs @@ -1,7 +1,7 @@ // check-pass #![feature(const_eval_limit)] -#![feature(const_loop, const_if_match)] +#![feature(const_loop)] // This needs to be higher than the number of loop iterations since each pass through the loop may // hit more than one terminator. diff --git a/src/test/ui/consts/const_limit/const_eval_limit_reached.rs b/src/test/ui/consts/const_limit/const_eval_limit_reached.rs index b45aca0b13e..a98a17f95d2 100644 --- a/src/test/ui/consts/const_limit/const_eval_limit_reached.rs +++ b/src/test/ui/consts/const_limit/const_eval_limit_reached.rs @@ -1,7 +1,6 @@ #![feature(const_eval_limit)] -#![feature(const_loop, const_if_match)] - -#![const_eval_limit="500"] +#![feature(const_loop)] +#![const_eval_limit = "500"] const X: usize = { let mut x = 0; diff --git a/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr b/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr index 8c2190b4e59..2c4f4ebd99a 100644 --- a/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr +++ b/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr @@ -1,5 +1,5 @@ error: any use of this value will cause an error - --> $DIR/const_eval_limit_reached.rs:8:5 + --> $DIR/const_eval_limit_reached.rs:7:11 | LL | / const X: usize = { LL | | let mut x = 0; diff --git a/src/test/ui/consts/const_short_circuit.rs b/src/test/ui/consts/const_short_circuit.rs index 87b14a11178..6403fbb17dd 100644 --- a/src/test/ui/consts/const_short_circuit.rs +++ b/src/test/ui/consts/const_short_circuit.rs @@ -1,13 +1,13 @@ +// check-pass + const _: bool = false && false; const _: bool = true && false; const _: bool = { let mut x = true && false; - //~^ ERROR new features like let bindings are not permitted x }; const _: bool = { let x = true && false; - //~^ ERROR new features like let bindings are not permitted x }; diff --git a/src/test/ui/consts/const_short_circuit.stderr b/src/test/ui/consts/const_short_circuit.stderr deleted file mode 100644 index b020382af07..00000000000 --- a/src/test/ui/consts/const_short_circuit.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: new features like let bindings are not permitted in constants which also use short circuiting operators - --> $DIR/const_short_circuit.rs:4:9 - | -LL | let mut x = true && false; - | ^^^^^ - | -note: use of `&&` operator 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. - --> $DIR/const_short_circuit.rs:4:22 - | -LL | let mut x = true && false; - | ^^ - -error: new features like let bindings are not permitted in constants which also use short circuiting operators - --> $DIR/const_short_circuit.rs:9:9 - | -LL | let x = true && false; - | ^ - | -note: use of `&&` operator 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. - --> $DIR/const_short_circuit.rs:9:18 - | -LL | let x = true && false; - | ^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/consts/control-flow/assert.both.stderr b/src/test/ui/consts/control-flow/assert.both.stderr deleted file mode 100644 index 7dd60cfb545..00000000000 --- a/src/test/ui/consts/control-flow/assert.both.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: any use of this value will cause an error - --> $DIR/assert.rs:12:15 - | -LL | const _: () = assert!(false); - | --------------^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'assertion failed: false', $DIR/assert.rs:12:15 - | - = note: `#[deny(const_err)]` on by default - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to previous error - diff --git a/src/test/ui/consts/control-flow/assert.if_match.stderr b/src/test/ui/consts/control-flow/assert.if_match.stderr deleted file mode 100644 index 466fb7c3ec5..00000000000 --- a/src/test/ui/consts/control-flow/assert.if_match.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0658]: panicking in constants is unstable - --> $DIR/assert.rs:8:15 - | -LL | const _: () = assert!(true); - | ^^^^^^^^^^^^^ - | - = note: see issue #51999 for more information - = help: add `#![feature(const_panic)]` to the crate attributes to enable - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0658]: panicking in constants is unstable - --> $DIR/assert.rs:12:15 - | -LL | const _: () = assert!(false); - | ^^^^^^^^^^^^^^ - | - = note: see issue #51999 for more information - = help: add `#![feature(const_panic)]` to the crate attributes to enable - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/control-flow/assert.panic.stderr b/src/test/ui/consts/control-flow/assert.panic.stderr index eafbdd84cc8..03662a35209 100644 --- a/src/test/ui/consts/control-flow/assert.panic.stderr +++ b/src/test/ui/consts/control-flow/assert.panic.stderr @@ -1,23 +1,13 @@ -error[E0658]: `if` is not allowed in a `const` - --> $DIR/assert.rs:8:15 - | -LL | const _: () = assert!(true); - | ^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/assert.rs:12:15 +error: any use of this value will cause an error + --> $DIR/assert.rs:10:15 | LL | const _: () = assert!(false); - | ^^^^^^^^^^^^^^ + | --------------^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'assertion failed: false', $DIR/assert.rs:10:15 | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable + = note: `#[deny(const_err)]` on by default = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/control-flow/assert.rs b/src/test/ui/consts/control-flow/assert.rs index 2da42d5084b..30cd31ee8a7 100644 --- a/src/test/ui/consts/control-flow/assert.rs +++ b/src/test/ui/consts/control-flow/assert.rs @@ -1,17 +1,14 @@ -// Test that `assert` works only when both `const_if_match` and `const_panic` are enabled. +// Test that `assert` works when `const_panic` is enabled. -// revisions: stock if_match panic both +// revisions: stock panic -#![cfg_attr(any(both, if_match), feature(const_if_match))] -#![cfg_attr(any(both, panic), feature(const_panic))] +#![cfg_attr(panic, feature(const_panic))] const _: () = assert!(true); -//[stock,panic]~^ ERROR `if` is not allowed in a `const` -//[if_match]~^^ ERROR panicking in constants is unstable +//[stock]~^ ERROR panicking in constants is unstable const _: () = assert!(false); -//[stock,panic]~^ ERROR `if` is not allowed in a `const` -//[if_match]~^^ ERROR panicking in constants is unstable -//[both]~^^^ ERROR any use of this value will cause an error +//[stock]~^ ERROR panicking in constants is unstable +//[panic]~^^ ERROR any use of this value will cause an error fn main() {} diff --git a/src/test/ui/consts/control-flow/assert.stock.stderr b/src/test/ui/consts/control-flow/assert.stock.stderr index eafbdd84cc8..fd344533ce1 100644 --- a/src/test/ui/consts/control-flow/assert.stock.stderr +++ b/src/test/ui/consts/control-flow/assert.stock.stderr @@ -1,21 +1,21 @@ -error[E0658]: `if` is not allowed in a `const` - --> $DIR/assert.rs:8:15 +error[E0658]: panicking in constants is unstable + --> $DIR/assert.rs:7:15 | LL | const _: () = assert!(true); | ^^^^^^^^^^^^^ | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable + = note: see issue #51999 for more information + = help: add `#![feature(const_panic)]` to the crate attributes to enable = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0658]: `if` is not allowed in a `const` - --> $DIR/assert.rs:12:15 +error[E0658]: panicking in constants is unstable + --> $DIR/assert.rs:10:15 | LL | const _: () = assert!(false); | ^^^^^^^^^^^^^^ | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable + = note: see issue #51999 for more information + = help: add `#![feature(const_panic)]` to the crate attributes to enable = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/control-flow/basics.rs b/src/test/ui/consts/control-flow/basics.rs index a53293743d5..3701f349d07 100644 --- a/src/test/ui/consts/control-flow/basics.rs +++ b/src/test/ui/consts/control-flow/basics.rs @@ -3,7 +3,6 @@ // run-pass #![feature(const_panic)] -#![feature(const_if_match)] #![feature(const_loop)] #![feature(const_fn)] diff --git a/src/test/ui/consts/control-flow/drop-fail.precise.stderr b/src/test/ui/consts/control-flow/drop-fail.precise.stderr index b4b6be8a1e5..f4edfaf72be 100644 --- a/src/test/ui/consts/control-flow/drop-fail.precise.stderr +++ b/src/test/ui/consts/control-flow/drop-fail.precise.stderr @@ -1,11 +1,11 @@ error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:10:9 + --> $DIR/drop-fail.rs:9:9 | LL | let x = Some(Vec::new()); | ^ constants cannot evaluate destructors error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:41:9 + --> $DIR/drop-fail.rs:40:9 | LL | let mut tmp = None; | ^^^^^^^ constants cannot evaluate destructors diff --git a/src/test/ui/consts/control-flow/drop-fail.rs b/src/test/ui/consts/control-flow/drop-fail.rs index 7bd36726cea..94deeb8c54c 100644 --- a/src/test/ui/consts/control-flow/drop-fail.rs +++ b/src/test/ui/consts/control-flow/drop-fail.rs @@ -1,6 +1,5 @@ // revisions: stock precise -#![feature(const_if_match)] #![feature(const_loop)] #![cfg_attr(precise, feature(const_precise_live_drops))] diff --git a/src/test/ui/consts/control-flow/drop-fail.stock.stderr b/src/test/ui/consts/control-flow/drop-fail.stock.stderr index 6a9ea91d20e..94734222117 100644 --- a/src/test/ui/consts/control-flow/drop-fail.stock.stderr +++ b/src/test/ui/consts/control-flow/drop-fail.stock.stderr @@ -1,5 +1,5 @@ error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:10:9 + --> $DIR/drop-fail.rs:9:9 | LL | let x = Some(Vec::new()); | ^ constants cannot evaluate destructors @@ -8,7 +8,7 @@ LL | }; | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:23:9 + --> $DIR/drop-fail.rs:22:9 | LL | let vec_tuple = (Vec::new(),); | ^^^^^^^^^ constants cannot evaluate destructors @@ -17,7 +17,7 @@ LL | }; | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:31:9 + --> $DIR/drop-fail.rs:30:9 | LL | let x: Result<_, Vec> = Ok(Vec::new()); | ^ constants cannot evaluate destructors @@ -26,7 +26,7 @@ LL | }; | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:41:9 + --> $DIR/drop-fail.rs:40:9 | LL | let mut tmp = None; | ^^^^^^^ constants cannot evaluate destructors diff --git a/src/test/ui/consts/control-flow/drop-pass.rs b/src/test/ui/consts/control-flow/drop-pass.rs index b0afd76c4e6..2ef8e08d744 100644 --- a/src/test/ui/consts/control-flow/drop-pass.rs +++ b/src/test/ui/consts/control-flow/drop-pass.rs @@ -1,7 +1,6 @@ // run-pass // revisions: stock precise -#![feature(const_if_match)] #![feature(const_loop)] #![cfg_attr(precise, feature(const_precise_live_drops))] diff --git a/src/test/ui/consts/control-flow/drop-precise.rs b/src/test/ui/consts/control-flow/drop-precise.rs index 95df76d9905..058c5608ec1 100644 --- a/src/test/ui/consts/control-flow/drop-precise.rs +++ b/src/test/ui/consts/control-flow/drop-precise.rs @@ -1,7 +1,6 @@ // run-pass // gate-test-const_precise_live_drops -#![feature(const_if_match)] #![feature(const_loop)] #![feature(const_precise_live_drops)] diff --git a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs index 6bbbdd972a2..4320133dfdb 100644 --- a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs +++ b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs @@ -2,8 +2,6 @@ // check-pass -#![feature(const_if_match)] - enum E { A, B, diff --git a/src/test/ui/consts/control-flow/feature-gate-const-if-match.if_match.stderr b/src/test/ui/consts/control-flow/feature-gate-const-if-match.if_match.stderr deleted file mode 100644 index 21e3f2af15a..00000000000 --- a/src/test/ui/consts/control-flow/feature-gate-const-if-match.if_match.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: fatal error triggered by #[rustc_error] - --> $DIR/feature-gate-const-if-match.rs:108:1 - | -LL | / fn main() { -LL | | let _ = [0; { -LL | | let x = if false { 0 } else { 1 }; -LL | | -... | -LL | | }]; -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/consts/control-flow/feature-gate-const-if-match.rs b/src/test/ui/consts/control-flow/feature-gate-const-if-match.rs index c49dd830a12..cb66bc75309 100644 --- a/src/test/ui/consts/control-flow/feature-gate-const-if-match.rs +++ b/src/test/ui/consts/control-flow/feature-gate-const-if-match.rs @@ -1,25 +1,10 @@ -// Ensure that `if`, `if let` and `match` are only allowed in the various const contexts when -// `#![feature(const_if_match)]` is enabled. When the feature gate is removed, the `#[rustc_error]` -// on `main` should be removed and this test converted to `check-pass`. +// check-pass -// revisions: stock if_match +const _: i32 = if true { 5 } else { 6 }; -#![feature(rustc_attrs)] -#![cfg_attr(if_match, feature(const_if_match))] +const _: i32 = if let Some(true) = Some(false) { 0 } else { 1 }; -const _: i32 = if true { //[stock]~ ERROR `if` is not allowed in a `const` - 5 -} else { - 6 -}; - -const _: i32 = if let Some(true) = Some(false) { //[stock]~ ERROR `if` is not allowed in a `const` - 0 -} else { - 1 -}; - -const _: i32 = match 1 { //[stock]~ ERROR `match` is not allowed in a `const` +const _: i32 = match 1 { 2 => 3, 4 => 5, _ => 0, @@ -27,91 +12,85 @@ const _: i32 = match 1 { //[stock]~ ERROR `match` is not allowed in a `const` static FOO: i32 = { let x = if true { 0 } else { 1 }; - //[stock]~^ ERROR `if` is not allowed in a `static` - let x = match x { 0 => 1, _ => 0 }; - //[stock]~^ ERROR `match` is not allowed in a `static` + let x = match x { + 0 => 1, + _ => 0, + }; if let Some(x) = Some(x) { x } else { 1 } - //[stock]~^ ERROR `if` is not allowed in a `static` }; static mut BAR: i32 = { let x = if true { 0 } else { 1 }; - //[stock]~^ ERROR `if` is not allowed in a `static mut` - let x = match x { 0 => 1, _ => 0 }; - //[stock]~^ ERROR `match` is not allowed in a `static mut` + let x = match x { + 0 => 1, + _ => 0, + }; if let Some(x) = Some(x) { x } else { 1 } - //[stock]~^ ERROR `if` is not allowed in a `static mut` }; const fn if_() -> i32 { - if true { 5 } else { 6 } //[stock]~ ERROR `if` is not allowed in a `const fn` + if true { 5 } else { 6 } } const fn if_let(a: Option) -> i32 { - if let Some(true) = a { //[stock]~ ERROR `if` is not allowed in a `const fn` - 0 - } else { - 1 - } + if let Some(true) = a { 0 } else { 1 } } const fn match_(i: i32) -> i32 { - match i { //[stock]~ ERROR `match` is not allowed in a `const fn` + match i { i if i > 10 => i, 1 => 2, - _ => 0 + _ => 0, } } pub trait Foo { const IF: i32 = if true { 5 } else { 6 }; - //[stock]~^ ERROR `if` is not allowed in a `const` - const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 }; - //[stock]~^ ERROR `if` is not allowed in a `const` - - const MATCH: i32 = match 0 { 1 => 2, _ => 0 }; - //[stock]~^ ERROR `match` is not allowed in a `const` + const MATCH: i32 = match 0 { + 1 => 2, + _ => 0, + }; } impl Foo for () { const IF: i32 = if true { 5 } else { 6 }; - //[stock]~^ ERROR `if` is not allowed in a `const` - const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 }; - //[stock]~^ ERROR `if` is not allowed in a `const` - - const MATCH: i32 = match 0 { 1 => 2, _ => 0 }; - //[stock]~^ ERROR `match` is not allowed in a `const` + const MATCH: i32 = match 0 { + 1 => 2, + _ => 0, + }; } fn non_const_outside() { const fn const_inside(y: bool) -> i32 { let x = if y { 0 } else { 1 }; - //[stock]~^ ERROR `if` is not allowed in a `const fn` - let x = match x { 0 => 1, _ => 0 }; - //[stock]~^ ERROR `match` is not allowed in a `const fn` + let x = match x { + 0 => 1, + _ => 0, + }; if let Some(x) = Some(x) { x } else { 1 } - //[stock]~^ ERROR `if` is not allowed in a `const fn` } } const fn const_outside() { fn non_const_inside(y: bool) -> i32 { let x = if y { 0 } else { 1 }; - let x = match x { 0 => 1, _ => 0 }; + let x = match x { + 0 => 1, + _ => 0, + }; if let Some(x) = Some(x) { x } else { 1 } } } -#[rustc_error] -fn main() { //[if_match]~ ERROR fatal error triggered by #[rustc_error] +fn main() { let _ = [0; { let x = if false { 0 } else { 1 }; - //[stock]~^ ERROR `if` is not allowed in a `const` - let x = match x { 0 => 1, _ => 0 }; - //[stock]~^ ERROR `match` is not allowed in a `const` + let x = match x { + 0 => 1, + _ => 0, + }; if let Some(x) = Some(x) { x } else { 1 } - //[stock]~^ ERROR `if` is not allowed in a `const` }]; } diff --git a/src/test/ui/consts/control-flow/feature-gate-const-if-match.stock.stderr b/src/test/ui/consts/control-flow/feature-gate-const-if-match.stock.stderr deleted file mode 100644 index b27971dccac..00000000000 --- a/src/test/ui/consts/control-flow/feature-gate-const-if-match.stock.stderr +++ /dev/null @@ -1,242 +0,0 @@ -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:10:16 - | -LL | const _: i32 = if true { - | ________________^ -LL | | 5 -LL | | } else { -LL | | 6 -LL | | }; - | |_^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:16:16 - | -LL | const _: i32 = if let Some(true) = Some(false) { - | ________________^ -LL | | 0 -LL | | } else { -LL | | 1 -LL | | }; - | |_^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:22:16 - | -LL | const _: i32 = match 1 { - | ________________^ -LL | | 2 => 3, -LL | | 4 => 5, -LL | | _ => 0, -LL | | }; - | |_^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `static` - --> $DIR/feature-gate-const-if-match.rs:29:13 - | -LL | let x = if true { 0 } else { 1 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `static` - --> $DIR/feature-gate-const-if-match.rs:31:13 - | -LL | let x = match x { 0 => 1, _ => 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `static` - --> $DIR/feature-gate-const-if-match.rs:33:5 - | -LL | if let Some(x) = Some(x) { x } else { 1 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `static mut` - --> $DIR/feature-gate-const-if-match.rs:38:13 - | -LL | let x = if true { 0 } else { 1 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `static mut` - --> $DIR/feature-gate-const-if-match.rs:40:13 - | -LL | let x = match x { 0 => 1, _ => 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `static mut` - --> $DIR/feature-gate-const-if-match.rs:42:5 - | -LL | if let Some(x) = Some(x) { x } else { 1 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const fn` - --> $DIR/feature-gate-const-if-match.rs:47:5 - | -LL | if true { 5 } else { 6 } - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const fn` - --> $DIR/feature-gate-const-if-match.rs:51:5 - | -LL | / if let Some(true) = a { -LL | | 0 -LL | | } else { -LL | | 1 -LL | | } - | |_____^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const fn` - --> $DIR/feature-gate-const-if-match.rs:59:5 - | -LL | / match i { -LL | | i if i > 10 => i, -LL | | 1 => 2, -LL | | _ => 0 -LL | | } - | |_____^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const fn` - --> $DIR/feature-gate-const-if-match.rs:90:17 - | -LL | let x = if y { 0 } else { 1 }; - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const fn` - --> $DIR/feature-gate-const-if-match.rs:92:17 - | -LL | let x = match x { 0 => 1, _ => 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const fn` - --> $DIR/feature-gate-const-if-match.rs:94:9 - | -LL | if let Some(x) = Some(x) { x } else { 1 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:110:17 - | -LL | let x = if false { 0 } else { 1 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:112:17 - | -LL | let x = match x { 0 => 1, _ => 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:114:9 - | -LL | if let Some(x) = Some(x) { x } else { 1 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:67:21 - | -LL | const IF: i32 = if true { 5 } else { 6 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:70:25 - | -LL | const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:73:24 - | -LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:78:21 - | -LL | const IF: i32 = if true { 5 } else { 6 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:81:25 - | -LL | const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/feature-gate-const-if-match.rs:84:24 - | -LL | const MATCH: i32 = match 0 { 1 => 2, _ => 0 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error: aborting due to 24 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/control-flow/interior-mutability.rs b/src/test/ui/consts/control-flow/interior-mutability.rs index c2439f4a7bf..cabdf4a929b 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.rs +++ b/src/test/ui/consts/control-flow/interior-mutability.rs @@ -1,7 +1,6 @@ // Ensure that *any* assignment to the return place of a value with interior mutability // disqualifies it from promotion. -#![feature(const_if_match)] #![feature(const_loop)] use std::cell::Cell; @@ -39,7 +38,6 @@ const Z: Option> = { z }; - fn main() { let x: &'static _ = &X; //~ ERROR temporary value dropped while borrowed let y: &'static _ = &Y; //~ ERROR temporary value dropped while borrowed diff --git a/src/test/ui/consts/control-flow/interior-mutability.stderr b/src/test/ui/consts/control-flow/interior-mutability.stderr index 0977c84d12d..8f18ae1816a 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.stderr +++ b/src/test/ui/consts/control-flow/interior-mutability.stderr @@ -1,5 +1,5 @@ error[E0716]: temporary value dropped while borrowed - --> $DIR/interior-mutability.rs:44:26 + --> $DIR/interior-mutability.rs:42:26 | LL | let x: &'static _ = &X; | ---------- ^ creates a temporary which is freed while still in use @@ -10,7 +10,7 @@ LL | } | - temporary value is freed at the end of this statement error[E0716]: temporary value dropped while borrowed - --> $DIR/interior-mutability.rs:45:26 + --> $DIR/interior-mutability.rs:43:26 | LL | let y: &'static _ = &Y; | ---------- ^ creates a temporary which is freed while still in use @@ -21,7 +21,7 @@ LL | } | - temporary value is freed at the end of this statement error[E0716]: temporary value dropped while borrowed - --> $DIR/interior-mutability.rs:46:26 + --> $DIR/interior-mutability.rs:44:26 | LL | let z: &'static _ = &Z; | ---------- ^ creates a temporary which is freed while still in use diff --git a/src/test/ui/consts/control-flow/issue-46843.rs b/src/test/ui/consts/control-flow/issue-46843.rs index 1fc91015ffa..edf62f23266 100644 --- a/src/test/ui/consts/control-flow/issue-46843.rs +++ b/src/test/ui/consts/control-flow/issue-46843.rs @@ -1,16 +1,14 @@ -// revisions: stock if_match - -#![cfg_attr(if_match, feature(const_if_match))] - -enum Thing { This, That } +enum Thing { + This, + That, +} fn non_const() -> Thing { Thing::This } pub const Q: i32 = match non_const() { - //[stock]~^ ERROR `match` is not allowed in a `const` - //[if_match]~^^ ERROR calls in constants are limited to constant functions + //~^ ERROR calls in constants are limited to constant functions Thing::This => 1, Thing::That => 0 }; diff --git a/src/test/ui/consts/control-flow/issue-46843.if_match.stderr b/src/test/ui/consts/control-flow/issue-46843.stderr similarity index 90% rename from src/test/ui/consts/control-flow/issue-46843.if_match.stderr rename to src/test/ui/consts/control-flow/issue-46843.stderr index 4c64d7dee8c..ea9ea25f9e1 100644 --- a/src/test/ui/consts/control-flow/issue-46843.if_match.stderr +++ b/src/test/ui/consts/control-flow/issue-46843.stderr @@ -1,5 +1,5 @@ error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-46843.rs:11:26 + --> $DIR/issue-46843.rs:10:26 | LL | pub const Q: i32 = match non_const() { | ^^^^^^^^^^^ diff --git a/src/test/ui/consts/control-flow/issue-46843.stock.stderr b/src/test/ui/consts/control-flow/issue-46843.stock.stderr deleted file mode 100644 index e4650da2075..00000000000 --- a/src/test/ui/consts/control-flow/issue-46843.stock.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0658]: `match` is not allowed in a `const` - --> $DIR/issue-46843.rs:11:20 - | -LL | pub const Q: i32 = match non_const() { - | ____________________^ -LL | | -LL | | -LL | | Thing::This => 1, -LL | | Thing::That => 0 -LL | | }; - | |_^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/control-flow/issue-50577.rs b/src/test/ui/consts/control-flow/issue-50577.rs index 9600f8b6aee..beb9a44fca5 100644 --- a/src/test/ui/consts/control-flow/issue-50577.rs +++ b/src/test/ui/consts/control-flow/issue-50577.rs @@ -1,13 +1,6 @@ -// revisions: stock if_match - -#![cfg_attr(if_match, feature(const_if_match))] - fn main() { enum Foo { - Drop = assert_eq!(1, 1) - //[stock,if_match]~^ ERROR `if` may be missing an `else` clause - //[stock]~^^ ERROR `match` is not allowed in a `const` - //[stock]~| ERROR `match` is not allowed in a `const` - //[stock]~| ERROR `if` is not allowed in a `const` + Drop = assert_eq!(1, 1), + //~^ ERROR `if` may be missing an `else` clause } } diff --git a/src/test/ui/consts/control-flow/issue-50577.if_match.stderr b/src/test/ui/consts/control-flow/issue-50577.stderr similarity index 88% rename from src/test/ui/consts/control-flow/issue-50577.if_match.stderr rename to src/test/ui/consts/control-flow/issue-50577.stderr index 831360d5652..b7b4c3a30d1 100644 --- a/src/test/ui/consts/control-flow/issue-50577.if_match.stderr +++ b/src/test/ui/consts/control-flow/issue-50577.stderr @@ -1,7 +1,7 @@ error[E0317]: `if` may be missing an `else` clause - --> $DIR/issue-50577.rs:7:16 + --> $DIR/issue-50577.rs:3:16 | -LL | Drop = assert_eq!(1, 1) +LL | Drop = assert_eq!(1, 1), | ^^^^^^^^^^^^^^^^ | | | expected `()`, found `isize` diff --git a/src/test/ui/consts/control-flow/issue-50577.stock.stderr b/src/test/ui/consts/control-flow/issue-50577.stock.stderr deleted file mode 100644 index 9d0d2831d9a..00000000000 --- a/src/test/ui/consts/control-flow/issue-50577.stock.stderr +++ /dev/null @@ -1,47 +0,0 @@ -error[E0658]: `match` is not allowed in a `const` - --> $DIR/issue-50577.rs:7:16 - | -LL | Drop = assert_eq!(1, 1) - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0658]: `if` is not allowed in a `const` - --> $DIR/issue-50577.rs:7:16 - | -LL | Drop = assert_eq!(1, 1) - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/issue-50577.rs:7:16 - | -LL | Drop = assert_eq!(1, 1) - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0317]: `if` may be missing an `else` clause - --> $DIR/issue-50577.rs:7:16 - | -LL | Drop = assert_eq!(1, 1) - | ^^^^^^^^^^^^^^^^ - | | - | expected `()`, found `isize` - | found here - | - = note: `if` expressions without `else` evaluate to `()` - = help: consider adding an `else` block that evaluates to the expected type - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0317, E0658. -For more information about an error, try `rustc --explain E0317`. diff --git a/src/test/ui/consts/control-flow/loop.both.stderr b/src/test/ui/consts/control-flow/loop.both.stderr deleted file mode 100644 index 71d96b216f9..00000000000 --- a/src/test/ui/consts/control-flow/loop.both.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:63:5 - | -LL | / for i in 0..4 { -LL | | x += i; -LL | | } - | |_____^ - -error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:67:5 - | -LL | / for i in 0..4 { -LL | | x += i; -LL | | } - | |_____^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0744`. diff --git a/src/test/ui/consts/control-flow/loop.if_match.stderr b/src/test/ui/consts/control-flow/loop.if_match.stderr deleted file mode 100644 index e8ff3624b77..00000000000 --- a/src/test/ui/consts/control-flow/loop.if_match.stderr +++ /dev/null @@ -1,151 +0,0 @@ -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:10:15 - | -LL | const _: () = loop {}; - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `static` - --> $DIR/loop.rs:12:19 - | -LL | static FOO: i32 = loop { break 4; }; - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop.rs:15:5 - | -LL | loop {} - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop.rs:28:9 - | -LL | loop {} - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:40:9 - | -LL | while false {} - | ^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:49:5 - | -LL | / while x < 4 { -LL | | x += 1; -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:53:5 - | -LL | / while x < 8 { -LL | | x += 1; -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:63:5 - | -LL | / for i in 0..4 { -LL | | x += i; -LL | | } - | |_____^ - -error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:67:5 - | -LL | / for i in 0..4 { -LL | | x += i; -LL | | } - | |_____^ - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:77:5 - | -LL | / loop { -LL | | x += 1; -LL | | if x == 4 { -LL | | break; -LL | | } -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:84:5 - | -LL | / loop { -LL | | x += 1; -LL | | if x == 8 { -LL | | break; -LL | | } -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:96:5 - | -LL | while let None = Some(x) { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:97:5 - | -LL | while let None = Some(x) { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:19:22 - | -LL | const BAR: i32 = loop { break 4; }; - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:23:22 - | -LL | const BAR: i32 = loop { break 4; }; - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error: aborting due to 15 previous errors - -Some errors have detailed explanations: E0658, E0744. -For more information about an error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/control-flow/loop.loop_.stderr b/src/test/ui/consts/control-flow/loop.loop_.stderr index 3d739f4d2b4..c40cee6620e 100644 --- a/src/test/ui/consts/control-flow/loop.loop_.stderr +++ b/src/test/ui/consts/control-flow/loop.loop_.stderr @@ -1,39 +1,5 @@ -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:40:9 - | -LL | while false {} - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: `#![feature(const_loop)]` alone is not sufficient, since this loop expression contains an implicit conditional - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:49:5 - | -LL | / while x < 4 { -LL | | x += 1; -LL | | } - | |_____^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: `#![feature(const_loop)]` alone is not sufficient, since this loop expression contains an implicit conditional - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:53:5 - | -LL | / while x < 8 { -LL | | x += 1; -LL | | } - | |_____^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: `#![feature(const_loop)]` alone is not sufficient, since this loop expression contains an implicit conditional - error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:63:5 + --> $DIR/loop.rs:61:5 | LL | / for i in 0..4 { LL | | x += i; @@ -41,56 +7,13 @@ LL | | } | |_____^ error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:67:5 + --> $DIR/loop.rs:65:5 | LL | / for i in 0..4 { LL | | x += i; LL | | } | |_____^ -error[E0658]: `if` is not allowed in a `const` - --> $DIR/loop.rs:79:9 - | -LL | / if x == 4 { -LL | | break; -LL | | } - | |_________^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable +error: aborting due to 2 previous errors -error[E0658]: `if` is not allowed in a `const` - --> $DIR/loop.rs:86:9 - | -LL | / if x == 8 { -LL | | break; -LL | | } - | |_________^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:96:5 - | -LL | while let None = Some(x) { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: `#![feature(const_loop)]` alone is not sufficient, since this loop expression contains an implicit conditional - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:97:5 - | -LL | while let None = Some(x) { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - = note: `#![feature(const_loop)]` alone is not sufficient, since this loop expression contains an implicit conditional - -error: aborting due to 9 previous errors - -Some errors have detailed explanations: E0658, E0744. -For more information about an error, try `rustc --explain E0658`. +For more information about this error, try `rustc --explain E0744`. diff --git a/src/test/ui/consts/control-flow/loop.rs b/src/test/ui/consts/control-flow/loop.rs index bc57f7568a7..30cc3d1b1af 100644 --- a/src/test/ui/consts/control-flow/loop.rs +++ b/src/test/ui/consts/control-flow/loop.rs @@ -1,31 +1,29 @@ // Ensure that loops are forbidden in a const context unless `#![feature(const_loop)]` is enabled. -// `while` loops require `#![feature(const_if_match)]` to be enabled as well. // gate-test-const_loop -// revisions: stock if_match loop_ both +// revisions: stock loop_ -#![cfg_attr(any(both, if_match), feature(const_if_match))] -#![cfg_attr(any(both, loop_), feature(const_loop))] +#![cfg_attr(loop_, feature(const_loop))] -const _: () = loop {}; //[stock,if_match]~ ERROR `loop` is not allowed in a `const` +const _: () = loop {}; //[stock]~ ERROR `loop` is not allowed in a `const` -static FOO: i32 = loop { break 4; }; //[stock,if_match]~ ERROR `loop` is not allowed in a `static` +static FOO: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `static` const fn foo() { - loop {} //[stock,if_match]~ ERROR `loop` is not allowed in a `const fn` + loop {} //[stock]~ ERROR `loop` is not allowed in a `const fn` } pub trait Foo { - const BAR: i32 = loop { break 4; }; //[stock,if_match]~ ERROR `loop` is not allowed in a `const` + const BAR: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `const` } impl Foo for () { - const BAR: i32 = loop { break 4; }; //[stock,if_match]~ ERROR `loop` is not allowed in a `const` + const BAR: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `const` } fn non_const_outside() { const fn const_inside() { - loop {} //[stock,if_match]~ ERROR `loop` is not allowed in a `const fn` + loop {} //[stock]~ ERROR `loop` is not allowed in a `const fn` } } @@ -38,7 +36,7 @@ const fn const_outside() { fn main() { let x = [0; { while false {} - //[stock,if_match,loop_]~^ ERROR `while` is not allowed in a `const` + //[stock]~^ ERROR `while` is not allowed in a `const` 4 }]; } @@ -46,11 +44,11 @@ fn main() { const _: i32 = { let mut x = 0; - while x < 4 { //[stock,if_match,loop_]~ ERROR `while` is not allowed in a `const` + while x < 4 { //[stock]~ ERROR `while` is not allowed in a `const` x += 1; } - while x < 8 { //[stock,if_match,loop_]~ ERROR `while` is not allowed in a `const` + while x < 8 { //[stock]~ ERROR `while` is not allowed in a `const` x += 1; } @@ -60,11 +58,11 @@ const _: i32 = { const _: i32 = { let mut x = 0; - for i in 0..4 { //[stock,if_match,loop_,both]~ ERROR `for` is not allowed in a `const` + for i in 0..4 { //[stock,loop_]~ ERROR `for` is not allowed in a `const` x += i; } - for i in 0..4 { //[stock,if_match,loop_,both]~ ERROR `for` is not allowed in a `const` + for i in 0..4 { //[stock,loop_]~ ERROR `for` is not allowed in a `const` x += i; } @@ -74,16 +72,16 @@ const _: i32 = { const _: i32 = { let mut x = 0; - loop { //[stock,if_match]~ ERROR `loop` is not allowed in a `const` + loop { //[stock]~ ERROR `loop` is not allowed in a `const` x += 1; - if x == 4 { //[stock,loop_]~ ERROR `if` is not allowed in a `const` + if x == 4 { break; } } - loop { //[stock,if_match]~ ERROR `loop` is not allowed in a `const` + loop { //[stock]~ ERROR `loop` is not allowed in a `const` x += 1; - if x == 8 { //[stock,loop_]~ ERROR `if` is not allowed in a `const` + if x == 8 { break; } } @@ -93,7 +91,7 @@ const _: i32 = { const _: i32 = { let mut x = 0; - while let None = Some(x) { } //[stock,if_match,loop_]~ ERROR `while` is not allowed in a `const` - while let None = Some(x) { } //[stock,if_match,loop_]~ ERROR `while` is not allowed in a `const` + while let None = Some(x) { } //[stock]~ ERROR `while` is not allowed in a `const` + while let None = Some(x) { } //[stock]~ ERROR `while` is not allowed in a `const` x }; diff --git a/src/test/ui/consts/control-flow/loop.stock.stderr b/src/test/ui/consts/control-flow/loop.stock.stderr index 987ced96551..a9ac3929bba 100644 --- a/src/test/ui/consts/control-flow/loop.stock.stderr +++ b/src/test/ui/consts/control-flow/loop.stock.stderr @@ -1,5 +1,5 @@ error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:10:15 + --> $DIR/loop.rs:8:15 | LL | const _: () = loop {}; | ^^^^^^^ @@ -8,7 +8,7 @@ LL | const _: () = loop {}; = help: add `#![feature(const_loop)]` to the crate attributes to enable error[E0658]: `loop` is not allowed in a `static` - --> $DIR/loop.rs:12:19 + --> $DIR/loop.rs:10:19 | LL | static FOO: i32 = loop { break 4; }; | ^^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL | static FOO: i32 = loop { break 4; }; = help: add `#![feature(const_loop)]` to the crate attributes to enable error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop.rs:15:5 + --> $DIR/loop.rs:13:5 | LL | loop {} | ^^^^^^^ @@ -26,7 +26,7 @@ LL | loop {} = help: add `#![feature(const_loop)]` to the crate attributes to enable error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop.rs:28:9 + --> $DIR/loop.rs:26:9 | LL | loop {} | ^^^^^^^ @@ -35,17 +35,16 @@ LL | loop {} = help: add `#![feature(const_loop)]` to the crate attributes to enable error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:40:9 + --> $DIR/loop.rs:38:9 | LL | while false {} | ^^^^^^^^^^^^^^ | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:49:5 + --> $DIR/loop.rs:47:5 | LL | / while x < 4 { LL | | x += 1; @@ -54,10 +53,9 @@ LL | | } | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:53:5 + --> $DIR/loop.rs:51:5 | LL | / while x < 8 { LL | | x += 1; @@ -66,10 +64,9 @@ LL | | } | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:63:5 + --> $DIR/loop.rs:61:5 | LL | / for i in 0..4 { LL | | x += i; @@ -77,7 +74,7 @@ LL | | } | |_____^ error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:67:5 + --> $DIR/loop.rs:65:5 | LL | / for i in 0..4 { LL | | x += i; @@ -85,7 +82,7 @@ LL | | } | |_____^ error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:77:5 + --> $DIR/loop.rs:75:5 | LL | / loop { LL | | x += 1; @@ -98,19 +95,8 @@ LL | | } = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable -error[E0658]: `if` is not allowed in a `const` - --> $DIR/loop.rs:79:9 - | -LL | / if x == 4 { -LL | | break; -LL | | } - | |_________^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:84:5 + --> $DIR/loop.rs:82:5 | LL | / loop { LL | | x += 1; @@ -123,39 +109,26 @@ LL | | } = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable -error[E0658]: `if` is not allowed in a `const` - --> $DIR/loop.rs:86:9 - | -LL | / if x == 8 { -LL | | break; -LL | | } - | |_________^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:96:5 + --> $DIR/loop.rs:94:5 | LL | while let None = Some(x) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:97:5 + --> $DIR/loop.rs:95:5 | LL | while let None = Some(x) { } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:19:22 + --> $DIR/loop.rs:17:22 | LL | const BAR: i32 = loop { break 4; }; | ^^^^^^^^^^^^^^^^^ @@ -164,7 +137,7 @@ LL | const BAR: i32 = loop { break 4; }; = help: add `#![feature(const_loop)]` to the crate attributes to enable error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:23:22 + --> $DIR/loop.rs:21:22 | LL | const BAR: i32 = loop { break 4; }; | ^^^^^^^^^^^^^^^^^ @@ -172,7 +145,7 @@ LL | const BAR: i32 = loop { break 4; }; = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable -error: aborting due to 17 previous errors +error: aborting due to 15 previous errors Some errors have detailed explanations: E0658, E0744. For more information about an error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/control-flow/short-circuit-let.rs b/src/test/ui/consts/control-flow/short-circuit-let.rs index 8cee2a54f56..4dfa22b8eba 100644 --- a/src/test/ui/consts/control-flow/short-circuit-let.rs +++ b/src/test/ui/consts/control-flow/short-circuit-let.rs @@ -2,7 +2,6 @@ // run-pass -#![feature(const_if_match)] #![feature(const_panic)] const X: i32 = { diff --git a/src/test/ui/consts/control-flow/short-circuit.if_match.stderr b/src/test/ui/consts/control-flow/short-circuit.if_match.stderr deleted file mode 100644 index f6ba28e7b72..00000000000 --- a/src/test/ui/consts/control-flow/short-circuit.if_match.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: fatal error triggered by #[rustc_error] - --> $DIR/short-circuit.rs:14:1 - | -LL | fn main() {} - | ^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/consts/control-flow/short-circuit.rs b/src/test/ui/consts/control-flow/short-circuit.rs index f5e54a69d4a..f6a0f03a4a6 100644 --- a/src/test/ui/consts/control-flow/short-circuit.rs +++ b/src/test/ui/consts/control-flow/short-circuit.rs @@ -1,14 +1,14 @@ -// Test that both `&&` and `||` actually short-circuit when the `const_if_match` feature flag is -// enabled. Without the feature flag, both sides are evaluated unconditionally. +// run-pass -// revisions: stock if_match +// Test that both `&&` and `||` actually short-circuit. +// Formerly, both sides were evaluated unconditionally -#![feature(rustc_attrs)] #![feature(const_panic)] -#![cfg_attr(if_match, feature(const_if_match))] -const _: bool = true || panic!(); //[stock]~ ERROR any use of this value will cause an error -const _: bool = false && panic!(); //[stock]~ ERROR any use of this value will cause an error +const TRUE: bool = true || panic!(); +const FALSE: bool = false && panic!(); -#[rustc_error] -fn main() {} //[if_match]~ ERROR fatal error triggered by #[rustc_error] +fn main() { + assert!(TRUE); + assert!(!FALSE); +} diff --git a/src/test/ui/consts/control-flow/short-circuit.stock.stderr b/src/test/ui/consts/control-flow/short-circuit.stock.stderr deleted file mode 100644 index f32f248af45..00000000000 --- a/src/test/ui/consts/control-flow/short-circuit.stock.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error: any use of this value will cause an error - --> $DIR/short-circuit.rs:10:25 - | -LL | const _: bool = true || panic!(); - | ------------------------^^^^^^^^- - | | - | the evaluated program panicked at 'explicit panic', $DIR/short-circuit.rs:10:25 - | - = note: `#[deny(const_err)]` on by default - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: any use of this value will cause an error - --> $DIR/short-circuit.rs:11:26 - | -LL | const _: bool = false && panic!(); - | -------------------------^^^^^^^^- - | | - | the evaluated program panicked at 'explicit panic', $DIR/short-circuit.rs:11:26 - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/consts/control-flow/single_variant_match_ice.rs b/src/test/ui/consts/control-flow/single_variant_match_ice.rs index 823605ff034..b59be00ffb7 100644 --- a/src/test/ui/consts/control-flow/single_variant_match_ice.rs +++ b/src/test/ui/consts/control-flow/single_variant_match_ice.rs @@ -1,7 +1,5 @@ // check-pass -#![feature(const_if_match)] - enum Foo { Prob, } diff --git a/src/test/ui/consts/control-flow/try.rs b/src/test/ui/consts/control-flow/try.rs index 31fe09d4f69..7d85a412b47 100644 --- a/src/test/ui/consts/control-flow/try.rs +++ b/src/test/ui/consts/control-flow/try.rs @@ -1,8 +1,6 @@ // The `?` operator is still not const-evaluatable because it calls `From::from` on the error // variant. -#![feature(const_if_match)] - const fn opt() -> Option { let x = Some(2); x?; //~ ERROR `?` is not allowed in a `const fn` diff --git a/src/test/ui/consts/control-flow/try.stderr b/src/test/ui/consts/control-flow/try.stderr index 60a386ef6c8..35075a3e60b 100644 --- a/src/test/ui/consts/control-flow/try.stderr +++ b/src/test/ui/consts/control-flow/try.stderr @@ -1,5 +1,5 @@ error[E0744]: `?` is not allowed in a `const fn` - --> $DIR/try.rs:8:5 + --> $DIR/try.rs:6:5 | LL | x?; | ^^ diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs index 557439f3949..2ebd9dd10c5 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn.rs @@ -98,13 +98,13 @@ const fn foo30_2(x: *mut u32) -> usize { x as usize } const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } } //~^ ERROR casting pointers to ints is unstable const fn foo30_6() -> bool { let x = true; x } -const fn foo36(a: bool, b: bool) -> bool { a && b } -//~^ ERROR loops and conditional expressions are not stable in const fn -const fn foo37(a: bool, b: bool) -> bool { a || b } -//~^ ERROR loops and conditional expressions are not stable in const fn const fn inc(x: &mut i32) { *x += 1 } //~^ ERROR mutable references in const fn are unstable +// ok +const fn foo36(a: bool, b: bool) -> bool { a && b } +const fn foo37(a: bool, b: bool) -> bool { a || b } + fn main() {} impl Foo { diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr index 4b0401ebf9d..9b55b6c6f3b 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr @@ -166,26 +166,8 @@ LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } = note: see issue #57563 for more information = help: add `#![feature(const_fn)]` to the crate attributes to enable -error[E0723]: loops and conditional expressions are not stable in const fn - --> $DIR/min_const_fn.rs:101:44 - | -LL | const fn foo36(a: bool, b: bool) -> bool { a && b } - | ^^^^^^ - | - = note: see issue #57563 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable - -error[E0723]: loops and conditional expressions are not stable in const fn - --> $DIR/min_const_fn.rs:103:44 - | -LL | const fn foo37(a: bool, b: bool) -> bool { a || b } - | ^^^^^^ - | - = note: see issue #57563 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable - error[E0723]: mutable references in const fn are unstable - --> $DIR/min_const_fn.rs:105:14 + --> $DIR/min_const_fn.rs:101:14 | LL | const fn inc(x: &mut i32) { *x += 1 } | ^ @@ -283,7 +265,7 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo } = note: see issue #57563 for more information = help: add `#![feature(const_fn)]` to the crate attributes to enable -error: aborting due to 32 previous errors +error: aborting due to 30 previous errors Some errors have detailed explanations: E0493, E0723. For more information about an error, try `rustc --explain E0493`. diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs index 52f6536b5ea..08d68b039be 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs @@ -2,8 +2,7 @@ // aux-build:static_cross_crate.rs #![allow(const_err)] -// `const_if_match` is a HIR check and thus needed even when unleashed. -#![feature(exclusive_range_pattern, half_open_range_patterns, const_if_match)] +#![feature(exclusive_range_pattern, half_open_range_patterns)] extern crate static_cross_crate; diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr index 9d1e88a811f..52662ef9eaf 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/const_refers_to_static_cross_crate.rs:12:1 + --> $DIR/const_refers_to_static_cross_crate.rs:11:1 | LL | / const SLICE_MUT: &[u8; 1] = { LL | | @@ -11,13 +11,13 @@ LL | | }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:40:9 + --> $DIR/const_refers_to_static_cross_crate.rs:39:9 | LL | SLICE_MUT => true, | ^^^^^^^^^ error[E0080]: it is undefined behavior to use this value - --> $DIR/const_refers_to_static_cross_crate.rs:18:1 + --> $DIR/const_refers_to_static_cross_crate.rs:17:1 | LL | / const U8_MUT: &u8 = { LL | | @@ -29,13 +29,13 @@ LL | | }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:49:9 + --> $DIR/const_refers_to_static_cross_crate.rs:48:9 | LL | U8_MUT => true, | ^^^^^^ warning: any use of this value will cause an error - --> $DIR/const_refers_to_static_cross_crate.rs:27:14 + --> $DIR/const_refers_to_static_cross_crate.rs:26:14 | LL | / const U8_MUT2: &u8 = { LL | | unsafe { &(*static_cross_crate::ZERO_REF)[0] } @@ -46,19 +46,19 @@ LL | | }; | |__- | note: the lint level is defined here - --> $DIR/const_refers_to_static_cross_crate.rs:25:8 + --> $DIR/const_refers_to_static_cross_crate.rs:24:8 | LL | #[warn(const_err)] | ^^^^^^^^^ error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:60:9 + --> $DIR/const_refers_to_static_cross_crate.rs:59:9 | LL | U8_MUT2 => true, | ^^^^^^^ warning: any use of this value will cause an error - --> $DIR/const_refers_to_static_cross_crate.rs:33:51 + --> $DIR/const_refers_to_static_cross_crate.rs:32:51 | LL | / const U8_MUT3: &u8 = { LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } @@ -69,37 +69,37 @@ LL | | }; | |__- | note: the lint level is defined here - --> $DIR/const_refers_to_static_cross_crate.rs:31:8 + --> $DIR/const_refers_to_static_cross_crate.rs:30:8 | LL | #[warn(const_err)] | ^^^^^^^^^ error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:68:9 + --> $DIR/const_refers_to_static_cross_crate.rs:67:9 | LL | U8_MUT3 => true, | ^^^^^^^ error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:40:9 + --> $DIR/const_refers_to_static_cross_crate.rs:39:9 | LL | SLICE_MUT => true, | ^^^^^^^^^ error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:49:9 + --> $DIR/const_refers_to_static_cross_crate.rs:48:9 | LL | U8_MUT => true, | ^^^^^^ error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:60:9 + --> $DIR/const_refers_to_static_cross_crate.rs:59:9 | LL | U8_MUT2 => true, | ^^^^^^^ error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:68:9 + --> $DIR/const_refers_to_static_cross_crate.rs:67:9 | LL | U8_MUT3 => true, | ^^^^^^^ @@ -107,57 +107,52 @@ LL | U8_MUT3 => true, warning: skipping const checks | help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:15:15 + --> $DIR/const_refers_to_static_cross_crate.rs:14:15 | LL | unsafe { &static_cross_crate::ZERO } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:15:15 + --> $DIR/const_refers_to_static_cross_crate.rs:14:15 | LL | unsafe { &static_cross_crate::ZERO } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:21:15 + --> $DIR/const_refers_to_static_cross_crate.rs:20:15 | LL | unsafe { &static_cross_crate::ZERO[0] } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:21:15 + --> $DIR/const_refers_to_static_cross_crate.rs:20:15 | LL | unsafe { &static_cross_crate::ZERO[0] } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:21:15 + --> $DIR/const_refers_to_static_cross_crate.rs:20:15 | LL | unsafe { &static_cross_crate::ZERO[0] } | ^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:27:17 + --> $DIR/const_refers_to_static_cross_crate.rs:26:17 | LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:33:20 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:33:20 - | -LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:33:20 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check for `const_panic` feature - --> $DIR/const_refers_to_static_cross_crate.rs:33:77 + --> $DIR/const_refers_to_static_cross_crate.rs:32:77 | LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } | ^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/const_refers_to_static_cross_crate.rs:33:20 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/unstable-const-fn-in-libcore.rs b/src/test/ui/consts/unstable-const-fn-in-libcore.rs index 0b64786ccce..29d3dc18fa7 100644 --- a/src/test/ui/consts/unstable-const-fn-in-libcore.rs +++ b/src/test/ui/consts/unstable-const-fn-in-libcore.rs @@ -4,7 +4,6 @@ // gate was not enabled in libcore. #![stable(feature = "core", since = "1.6.0")] -#![feature(const_if_match)] #![feature(rustc_const_unstable)] #![feature(staged_api)] diff --git a/src/test/ui/consts/unstable-const-fn-in-libcore.stderr b/src/test/ui/consts/unstable-const-fn-in-libcore.stderr index 928605356a1..be797cae7ca 100644 --- a/src/test/ui/consts/unstable-const-fn-in-libcore.stderr +++ b/src/test/ui/consts/unstable-const-fn-in-libcore.stderr @@ -1,11 +1,11 @@ error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants - --> $DIR/unstable-const-fn-in-libcore.rs:24:26 + --> $DIR/unstable-const-fn-in-libcore.rs:23:26 | LL | Opt::None => f(), | ^^^ error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/unstable-const-fn-in-libcore.rs:19:53 + --> $DIR/unstable-const-fn-in-libcore.rs:18:53 | LL | const fn unwrap_or_else T>(self, f: F) -> T { | ^ constant functions cannot evaluate destructors @@ -14,7 +14,7 @@ LL | } | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/unstable-const-fn-in-libcore.rs:19:47 + --> $DIR/unstable-const-fn-in-libcore.rs:18:47 | LL | const fn unwrap_or_else T>(self, f: F) -> T { | ^^^^ constant functions cannot evaluate destructors diff --git a/src/test/ui/enum-discriminant/niche.rs b/src/test/ui/enum-discriminant/niche.rs index 8d2cdf34f37..b3694bb4216 100644 --- a/src/test/ui/enum-discriminant/niche.rs +++ b/src/test/ui/enum-discriminant/niche.rs @@ -1,7 +1,6 @@ // run-pass #![feature(const_panic)] -#![feature(const_if_match)] //! Make sure that we read and write enum discriminants correctly for corner cases caused //! by layout optimizations. diff --git a/src/test/ui/internal/internal-unstable-const.rs b/src/test/ui/internal/internal-unstable-const.rs index ce306c84517..a32338c6546 100644 --- a/src/test/ui/internal/internal-unstable-const.rs +++ b/src/test/ui/internal/internal-unstable-const.rs @@ -1,10 +1,12 @@ +#![stable(feature = "rust1", since = "1.0.0")] + #![feature(staged_api)] -#![feature(const_if_match)] +#![feature(const_loop, const_fn)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] const fn foo() -> i32 { - if true { 4 } else { 5 } //~ loops and conditional expressions are not stable in const fn + loop { return 42; } //~ ERROR `loop` is not allowed in a `const fn` } fn main() {} diff --git a/src/test/ui/internal/internal-unstable-const.stderr b/src/test/ui/internal/internal-unstable-const.stderr index b2d97b981ba..a43e014b1c6 100644 --- a/src/test/ui/internal/internal-unstable-const.stderr +++ b/src/test/ui/internal/internal-unstable-const.stderr @@ -1,12 +1,9 @@ -error[E0723]: loops and conditional expressions are not stable in const fn - --> $DIR/internal-unstable-const.rs:7:5 +error[E0744]: `loop` is not allowed in a `const fn` + --> $DIR/internal-unstable-const.rs:9:5 | -LL | if true { 4 } else { 5 } - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #57563 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable +LL | loop { return 42; } + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0723`. +For more information about this error, try `rustc --explain E0744`. diff --git a/src/test/ui/issues/issue-51714.stderr b/src/test/ui/issues/issue-51714.stderr index 69603085043..71d4022a6d4 100644 --- a/src/test/ui/issues/issue-51714.stderr +++ b/src/test/ui/issues/issue-51714.stderr @@ -6,7 +6,6 @@ LL | [(); return while let Some(n) = Some(0) {}]; | = note: see issue #52000 for more information = help: add `#![feature(const_loop)]` to the crate attributes to enable - = help: add `#![feature(const_if_match)]` to the crate attributes to enable error[E0572]: return statement outside of function body --> $DIR/issue-51714.rs:2:14 diff --git a/src/test/ui/issues/issue-66706.rs b/src/test/ui/issues/issue-66706.rs index 02305191f6e..4585bcc8cd5 100644 --- a/src/test/ui/issues/issue-66706.rs +++ b/src/test/ui/issues/issue-66706.rs @@ -19,7 +19,6 @@ fn c() { fn d() { [0; match [|f @ &ref _| () ] {} ] //~^ ERROR expected identifier, found reserved identifier `_` - //~| ERROR `match` is not allowed in a `const` //~| ERROR mismatched types } diff --git a/src/test/ui/issues/issue-66706.stderr b/src/test/ui/issues/issue-66706.stderr index ea461cc5d03..f0b93ac9111 100644 --- a/src/test/ui/issues/issue-66706.stderr +++ b/src/test/ui/issues/issue-66706.stderr @@ -26,15 +26,6 @@ error: expected identifier, found reserved identifier `_` LL | [0; match [|f @ &ref _| () ] {} ] | ^ expected identifier, found reserved identifier -error[E0658]: `match` is not allowed in a `const` - --> $DIR/issue-66706.rs:20:9 - | -LL | [0; match [|f @ &ref _| () ] {} ] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - error[E0282]: type annotations needed --> $DIR/issue-66706.rs:2:11 | @@ -65,7 +56,7 @@ LL | fn d() { LL | [0; match [|f @ &ref _| () ] {} ] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]` -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors -Some errors have detailed explanations: E0282, E0308, E0658. +Some errors have detailed explanations: E0282, E0308. For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/or-patterns/feature-gate-const-fn.rs b/src/test/ui/or-patterns/const-fn.rs similarity index 56% rename from src/test/ui/or-patterns/feature-gate-const-fn.rs rename to src/test/ui/or-patterns/const-fn.rs index d21cf3dc72c..f4af2f0d2dd 100644 --- a/src/test/ui/or-patterns/feature-gate-const-fn.rs +++ b/src/test/ui/or-patterns/const-fn.rs @@ -1,35 +1,30 @@ +// check-pass #![feature(or_patterns)] const fn foo((Ok(a) | Err(a)): Result) { - //~^ ERROR or-pattern is not allowed in a `const fn` let x = Ok(3); let Ok(y) | Err(y) = x; - //~^ ERROR or-pattern is not allowed in a `const fn` } const X: () = { let x = Ok(3); let Ok(y) | Err(y) = x; - //~^ ERROR or-pattern is not allowed in a `const` }; static Y: () = { let x = Ok(3); let Ok(y) | Err(y) = x; - //~^ ERROR or-pattern is not allowed in a `static` }; static mut Z: () = { let x = Ok(3); let Ok(y) | Err(y) = x; - //~^ ERROR or-pattern is not allowed in a `static mut` }; fn main() { let _: [(); { let x = Ok(3); let Ok(y) | Err(y) = x; - //~^ ERROR or-pattern is not allowed in a `const` 2 }]; } diff --git a/src/test/ui/or-patterns/feature-gate-const-fn.stderr b/src/test/ui/or-patterns/feature-gate-const-fn.stderr deleted file mode 100644 index 345d6c70981..00000000000 --- a/src/test/ui/or-patterns/feature-gate-const-fn.stderr +++ /dev/null @@ -1,57 +0,0 @@ -error[E0658]: or-pattern is not allowed in a `const fn` - --> $DIR/feature-gate-const-fn.rs:3:15 - | -LL | const fn foo((Ok(a) | Err(a)): Result) { - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: or-pattern is not allowed in a `const fn` - --> $DIR/feature-gate-const-fn.rs:6:9 - | -LL | let Ok(y) | Err(y) = x; - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: or-pattern is not allowed in a `const` - --> $DIR/feature-gate-const-fn.rs:12:9 - | -LL | let Ok(y) | Err(y) = x; - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: or-pattern is not allowed in a `static` - --> $DIR/feature-gate-const-fn.rs:18:9 - | -LL | let Ok(y) | Err(y) = x; - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: or-pattern is not allowed in a `static mut` - --> $DIR/feature-gate-const-fn.rs:24:9 - | -LL | let Ok(y) | Err(y) = x; - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: or-pattern is not allowed in a `const` - --> $DIR/feature-gate-const-fn.rs:31:13 - | -LL | let Ok(y) | Err(y) = x; - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/return/return-match-array-const.rs b/src/test/ui/return/return-match-array-const.rs index 9f3b9651642..f21eac37c17 100644 --- a/src/test/ui/return/return-match-array-const.rs +++ b/src/test/ui/return/return-match-array-const.rs @@ -1,13 +1,10 @@ fn main() { [(); return match 0 { n => n }]; //~^ ERROR: return statement outside of function body - //~| ERROR: `match` is not allowed in a `const` [(); return match 0 { 0 => 0 }]; //~^ ERROR: return statement outside of function body - //~| ERROR: `match` is not allowed in a `const` [(); return match () { 'a' => 0, _ => 0 }]; //~^ ERROR: return statement outside of function body - //~| ERROR: `match` is not allowed in a `const` } diff --git a/src/test/ui/return/return-match-array-const.stderr b/src/test/ui/return/return-match-array-const.stderr index c475c7de438..8e801e3fbb7 100644 --- a/src/test/ui/return/return-match-array-const.stderr +++ b/src/test/ui/return/return-match-array-const.stderr @@ -1,30 +1,3 @@ -error[E0658]: `match` is not allowed in a `const` - --> $DIR/return-match-array-const.rs:2:17 - | -LL | [(); return match 0 { n => n }]; - | ^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/return-match-array-const.rs:6:17 - | -LL | [(); return match 0 { 0 => 0 }]; - | ^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/return-match-array-const.rs:10:17 - | -LL | [(); return match () { 'a' => 0, _ => 0 }]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - error[E0572]: return statement outside of function body --> $DIR/return-match-array-const.rs:2:10 | @@ -32,18 +5,17 @@ LL | [(); return match 0 { n => n }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0572]: return statement outside of function body - --> $DIR/return-match-array-const.rs:6:10 + --> $DIR/return-match-array-const.rs:5:10 | LL | [(); return match 0 { 0 => 0 }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0572]: return statement outside of function body - --> $DIR/return-match-array-const.rs:10:10 + --> $DIR/return-match-array-const.rs:8:10 | LL | [(); return match () { 'a' => 0, _ => 0 }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0572, E0658. -For more information about an error, try `rustc --explain E0572`. +For more information about this error, try `rustc --explain E0572`. diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs index d5756737f17..71af704c69f 100644 --- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs +++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs @@ -216,17 +216,14 @@ fn inside_const_generic_arguments() { if let A::<{ true && let 1 = 1 //~ ERROR `let` expressions are not supported here - //~| ERROR `match` is not allowed in a `const` }>::O = 5 {} while let A::<{ true && let 1 = 1 //~ ERROR `let` expressions are not supported here - //~| ERROR `match` is not allowed in a `const` }>::O = 5 {} if A::<{ true && let 1 = 1 //~ ERROR `let` expressions are not supported here - //~| ERROR `match` is not allowed in a `const` }>::O == 5 {} // In the cases above we have `ExprKind::Block` to help us out. diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr index 4c3a00e5f35..7f343d1a853 100644 --- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr @@ -1,5 +1,5 @@ error: expected one of `,` or `>`, found `&&` - --> $DIR/disallowed-positions.rs:239:14 + --> $DIR/disallowed-positions.rs:236:14 | LL | true && let 1 = 1 | ^^ expected one of `,` or `>` @@ -482,7 +482,7 @@ LL | true && let 1 = 1 = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:223:17 + --> $DIR/disallowed-positions.rs:222:17 | LL | true && let 1 = 1 | ^^^^^^^^^ @@ -491,7 +491,7 @@ LL | true && let 1 = 1 = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:228:17 + --> $DIR/disallowed-positions.rs:226:17 | LL | true && let 1 = 1 | ^^^^^^^^^ @@ -516,33 +516,6 @@ LL | #![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates | = note: see issue #53667 for more information -error[E0658]: `match` is not allowed in a `const` - --> $DIR/disallowed-positions.rs:218:17 - | -LL | true && let 1 = 1 - | ^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/disallowed-positions.rs:223:17 - | -LL | true && let 1 = 1 - | ^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - -error[E0658]: `match` is not allowed in a `const` - --> $DIR/disallowed-positions.rs:228:17 - | -LL | true && let 1 = 1 - | ^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable - error[E0308]: mismatched types --> $DIR/disallowed-positions.rs:32:8 | @@ -983,7 +956,7 @@ LL | let 0 = 0?; = help: the trait `std::ops::Try` is not implemented for `{integer}` = note: required by `std::ops::Try::into_result` -error: aborting due to 106 previous errors; 2 warnings emitted +error: aborting due to 103 previous errors; 2 warnings emitted -Some errors have detailed explanations: E0277, E0308, E0600, E0614, E0658. +Some errors have detailed explanations: E0277, E0308, E0600, E0614. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs index f7af1b506f0..6154b484d34 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs @@ -9,7 +9,7 @@ pub trait MyTrait { impl const MyTrait for () { fn method(&self) { - match *self {} //~ ERROR `match` is not allowed in a `const fn` + loop {} //~ ERROR `loop` is not allowed in a `const fn` } } diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr index 563a9afe5bb..ec404060535 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr @@ -1,11 +1,11 @@ -error[E0658]: `match` is not allowed in a `const fn` +error[E0658]: `loop` is not allowed in a `const fn` --> $DIR/hir-const-check.rs:12:9 | -LL | match *self {} - | ^^^^^^^^^^^^^^ +LL | loop {} + | ^^^^^^^ | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` to the crate attributes to enable + = note: see issue #52000 for more information + = help: add `#![feature(const_loop)]` to the crate attributes to enable error: aborting due to previous error From 69a5cb15925d4e547f7c91a9558a1ca6503dceda Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 13:35:43 -0700 Subject: [PATCH 07/14] Remove `const_if_match` from unstable book --- .../src/language-features/const-if-match.md | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/const-if-match.md diff --git a/src/doc/unstable-book/src/language-features/const-if-match.md b/src/doc/unstable-book/src/language-features/const-if-match.md deleted file mode 100644 index ee9cfcbd9de..00000000000 --- a/src/doc/unstable-book/src/language-features/const-if-match.md +++ /dev/null @@ -1,14 +0,0 @@ -# `const_if_match` - -The tracking issue for this feature is: [#49146] - -[#49146]: https://github.com/rust-lang/rust/issues/49146 - ------------------------- - -Allows for the use of conditionals (`if` and `match`) in a const context. -Const contexts include `static`, `static mut`, `const`, `const fn`, const -generics, and array initializers. Enabling this feature flag will also make -`&&` and `||` function normally in a const-context by removing the hack that -replaces them with their non-short-circuiting equivalents, `&` and `|`, in a -`const` or `static`. From 565be31504bf12a9ac2562da7c3ce6d3165b6691 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 21 May 2020 14:23:50 -0700 Subject: [PATCH 08/14] Require `allow_internal_unstable` in HIR const-checker --- src/librustc_passes/check_const.rs | 63 ++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 22a65b6730a..e3bb124e1e5 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -7,6 +7,7 @@ //! errors. We still look for those primitives in the MIR const-checker to ensure nothing slips //! through, but errors for structured control flow in a `const` should be emitted here. +use rustc_attr as attr; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; @@ -70,35 +71,63 @@ pub(crate) fn provide(providers: &mut Providers<'_>) { struct CheckConstVisitor<'tcx> { tcx: TyCtxt<'tcx>, const_kind: Option, + def_id: Option, } impl<'tcx> CheckConstVisitor<'tcx> { fn new(tcx: TyCtxt<'tcx>) -> Self { - CheckConstVisitor { tcx, const_kind: None } + CheckConstVisitor { tcx, const_kind: None, def_id: None } } /// Emits an error when an unsupported expression is found in a const context. fn const_check_violated(&self, expr: NonConstExpr, span: Span) { - let features = self.tcx.features(); + let Self { tcx, def_id, const_kind } = *self; + + let features = tcx.features(); let required_gates = expr.required_feature_gates(); + + let is_feature_allowed = |feature_gate| { + // All features require that the corresponding gate be enabled, + // even if the function has `#[allow_internal_unstable(the_gate)]`. + if !tcx.features().enabled(feature_gate) { + return false; + } + + // If `def_id` is `None`, we don't need to consider stability attributes. + let def_id = match def_id { + Some(x) => x, + None => return true, + }; + + // If this crate is not using stability attributes, or this function is not claiming to be a + // stable `const fn`, that is all that is required. + if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) { + return true; + } + + // However, we cannot allow stable `const fn`s to use unstable features without an explicit + // opt-in via `allow_internal_unstable`. + attr::allow_internal_unstable(&tcx.get_attrs(def_id), &tcx.sess.diagnostic()) + .map_or(false, |mut features| features.any(|name| name == feature_gate)) + }; + match required_gates { // Don't emit an error if the user has enabled the requisite feature gates. - Some(gates) if gates.iter().all(|&g| features.enabled(g)) => return, + Some(gates) if gates.iter().copied().all(is_feature_allowed) => return, // `-Zunleash-the-miri-inside-of-you` only works for expressions that don't have a // corresponding feature gate. This encourages nightly users to use feature gates when // possible. - None if self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you => { - self.tcx.sess.span_warn(span, "skipping const checks"); + None if tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you => { + tcx.sess.span_warn(span, "skipping const checks"); return; } _ => {} } - let const_kind = self - .const_kind - .expect("`const_check_violated` may only be called inside a const context"); + let const_kind = + const_kind.expect("`const_check_violated` may only be called inside a const context"); let msg = format!("{} is not allowed in a `{}`", expr.name(), const_kind.keyword_name()); @@ -107,10 +136,10 @@ impl<'tcx> CheckConstVisitor<'tcx> { required_gates.iter().copied().filter(|&g| !features.enabled(g)).collect(); match missing_gates.as_slice() { - &[] => struct_span_err!(self.tcx.sess, span, E0744, "{}", msg).emit(), + &[] => struct_span_err!(tcx.sess, span, E0744, "{}", msg).emit(), &[missing_primary, ref missing_secondary @ ..] => { - let mut err = feature_err(&self.tcx.sess.parse_sess, missing_primary, span, &msg); + let mut err = feature_err(&tcx.sess.parse_sess, missing_primary, span, &msg); // If multiple feature gates would be required to enable this expression, include // them as help messages. Don't emit a separate error for each missing feature gate. @@ -133,10 +162,18 @@ impl<'tcx> CheckConstVisitor<'tcx> { } /// Saves the parent `const_kind` before calling `f` and restores it afterwards. - fn recurse_into(&mut self, kind: Option, f: impl FnOnce(&mut Self)) { + fn recurse_into( + &mut self, + kind: Option, + def_id: Option, + f: impl FnOnce(&mut Self), + ) { + let parent_def_id = self.def_id; let parent_kind = self.const_kind; + self.def_id = def_id; self.const_kind = kind; f(self); + self.def_id = parent_def_id; self.const_kind = parent_kind; } } @@ -150,13 +187,13 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { fn visit_anon_const(&mut self, anon: &'tcx hir::AnonConst) { let kind = Some(hir::ConstContext::Const); - self.recurse_into(kind, |this| intravisit::walk_anon_const(this, anon)); + self.recurse_into(kind, None, |this| intravisit::walk_anon_const(this, anon)); } fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { let owner = self.tcx.hir().body_owner_def_id(body.id()); let kind = self.tcx.hir().body_const_context(owner); - self.recurse_into(kind, |this| intravisit::walk_body(this, body)); + self.recurse_into(kind, Some(owner.to_def_id()), |this| intravisit::walk_body(this, body)); } fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { From 86e1555e9fe6a000958db50710838826952e4515 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 25 Jun 2020 17:40:06 -0700 Subject: [PATCH 09/14] Mark `const_loop` feature gate as accepted --- src/librustc_feature/accepted.rs | 2 ++ src/librustc_feature/active.rs | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc_feature/accepted.rs b/src/librustc_feature/accepted.rs index 28a08330d49..b164b21913d 100644 --- a/src/librustc_feature/accepted.rs +++ b/src/librustc_feature/accepted.rs @@ -263,6 +263,8 @@ declare_features! ( (accepted, slice_patterns, "1.42.0", Some(62254), None), /// Allows the use of `if` and `match` in constants. (accepted, const_if_match, "1.45.0", Some(49146), None), + /// Allows the use of `loop` and `while` in constants. + (accepted, const_loop, "1.45.0", Some(52000), None), // ------------------------------------------------------------------------- // feature-group-end: accepted features diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index a80ac3105ce..8660d6a8d64 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -527,9 +527,6 @@ declare_features! ( /// Allows using `&mut` in constant functions. (active, const_mut_refs, "1.41.0", Some(57349), None), - /// Allows the use of `loop` and `while` in constants. - (active, const_loop, "1.41.0", Some(52000), None), - /// Allows bindings in the subpattern of a binding pattern. /// For example, you can write `x @ Some(y)`. (active, bindings_after_at, "1.41.0", Some(65490), None), From 5bed94cda405f157bafae010da90d201a2875e42 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 25 Jun 2020 17:40:56 -0700 Subject: [PATCH 10/14] Remove uses of `const_loop` in `rustc` --- src/libcore/lib.rs | 2 +- src/librustc_mir/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 1391dc7a953..a6146f9e5c9 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -74,7 +74,7 @@ #![feature(const_alloc_layout)] #![feature(const_discriminant)] #![cfg_attr(bootstrap, feature(const_if_match))] -#![feature(const_loop)] +#![cfg_attr(bootstrap, feature(const_loop))] #![feature(const_checked_int_methods)] #![feature(const_euclidean_int_methods)] #![feature(const_overflowing_int_methods)] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index d64105f3b99..cb6893166fd 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -11,7 +11,7 @@ Rust MIR: a lowered representation of Rust. #![feature(box_syntax)] #![feature(const_fn)] #![cfg_attr(bootstrap, feature(const_if_match))] -#![feature(const_loop)] +#![cfg_attr(bootstrap, feature(const_loop))] #![feature(const_panic)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] From 7c46e4251219c25582f26b7838958a04b4b50bc6 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 25 Jun 2020 17:41:32 -0700 Subject: [PATCH 11/14] Stop checking for `while` and `loop` in a const context --- src/librustc_mir/transform/check_consts/ops.rs | 13 ------------- .../transform/check_consts/validation.rs | 6 ------ src/librustc_passes/check_const.rs | 13 ++++++------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 814437faa58..ea025f208e4 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -164,19 +164,6 @@ impl NonConstOp for LiveDrop { } } -#[derive(Debug)] -pub struct Loop; -impl NonConstOp for Loop { - fn feature_gate() -> Option { - Some(sym::const_loop) - } - - fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) { - // This should be caught by the HIR const-checker. - ccx.tcx.sess.delay_span_bug(span, "complex control flow is forbidden in a const context"); - } -} - #[derive(Debug)] pub struct CellBorrow; impl NonConstOp for CellBorrow { diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index a10e3ee9372..ca1f0aecd04 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -207,12 +207,6 @@ impl Validator<'mir, 'tcx> { } } - 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. - self.check_op_spanned(ops::Loop, body.span); - } - self.visit_body(&body); // Ensure that the end result is `Sync` in a non-thread local `static`. diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index e3bb124e1e5..a385d96d974 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -40,18 +40,17 @@ impl NonConstExpr { let gates: &[_] = match self { // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`, - // so they are not yet allowed with `#![feature(const_loop)]`. + // so they are not yet allowed. // Likewise, `?` desugars to a call to `Try::into_result`. Self::Loop(ForLoop) | Self::Match(ForLoopDesugar | TryDesugar | AwaitDesugar) => { return None; } - Self::Loop(Loop | While | WhileLet) | Self::Match(WhileDesugar | WhileLetDesugar) => { - &[sym::const_loop] - } - - // All other matches are allowed. - Self::Match(Normal | IfDesugar { .. } | IfLetDesugar { .. }) => &[], + // All other expressions are allowed. + Self::Loop(Loop | While | WhileLet) + | Self::Match( + WhileDesugar | WhileLetDesugar | Normal | IfDesugar { .. } | IfLetDesugar { .. }, + ) => &[], }; Some(gates) From d84f0c8d329017c95cbf73418be8e804b0a10472 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 25 Jun 2020 17:43:48 -0700 Subject: [PATCH 12/14] Update tests --- src/test/compile-fail/issue-52443.rs | 8 +- src/test/ui/async-await/issue-70594.rs | 1 - src/test/ui/async-await/issue-70594.stderr | 13 +- src/test/ui/closures/issue-52437.rs | 1 - src/test/ui/closures/issue-52437.stderr | 13 +- .../ui/consts/const-eval/infinite_loop.rs | 1 - .../ui/consts/const-eval/infinite_loop.stderr | 20 +-- src/test/ui/consts/const-eval/issue-52442.rs | 3 +- .../ui/consts/const-eval/issue-52442.stderr | 11 +- src/test/ui/consts/const-eval/issue-52475.rs | 1 - .../ui/consts/const-eval/issue-52475.stderr | 20 +-- src/test/ui/consts/const-eval/issue-62272.rs | 11 -- .../ui/consts/const-eval/issue-62272.stderr | 21 --- src/test/ui/consts/const-eval/issue-70723.rs | 2 - .../ui/consts/const-eval/issue-70723.stderr | 2 +- src/test/ui/consts/const-eval/livedrop.rs | 3 - src/test/ui/consts/const-eval/livedrop.stderr | 2 +- src/test/ui/consts/const-labeled-break.rs | 9 +- src/test/ui/consts/const-labeled-break.stderr | 12 -- .../const_eval_limit_not_reached.rs | 1 - .../const_limit/const_eval_limit_reached.rs | 1 - .../const_eval_limit_reached.stderr | 2 +- src/test/ui/consts/control-flow/basics.rs | 1 - .../control-flow/drop-fail.precise.stderr | 4 +- src/test/ui/consts/control-flow/drop-fail.rs | 1 - .../control-flow/drop-fail.stock.stderr | 8 +- src/test/ui/consts/control-flow/drop-pass.rs | 1 - .../ui/consts/control-flow/drop-precise.rs | 1 - .../control-flow/interior-mutability.rs | 2 - .../control-flow/interior-mutability.stderr | 6 +- src/test/ui/consts/control-flow/loop.rs | 36 ++--- .../{loop.loop_.stderr => loop.stderr} | 4 +- .../ui/consts/control-flow/loop.stock.stderr | 151 ------------------ src/test/ui/consts/min_const_fn/loop_ice.rs | 5 - .../ui/consts/min_const_fn/loop_ice.stderr | 12 -- .../ui/internal/internal-unstable-const.rs | 8 +- .../internal/internal-unstable-const.stderr | 13 +- src/test/ui/issues/issue-51714.rs | 1 - src/test/ui/issues/issue-51714.stderr | 14 +- .../hir-const-check.rs | 7 +- .../hir-const-check.stderr | 11 +- .../tests/ui/redundant_pattern_matching.fixed | 2 - .../tests/ui/redundant_pattern_matching.rs | 2 - .../ui/redundant_pattern_matching.stderr | 56 +++---- ...undant_pattern_matching_const_result.fixed | 2 - ...redundant_pattern_matching_const_result.rs | 2 - ...ndant_pattern_matching_const_result.stderr | 12 +- 47 files changed, 105 insertions(+), 415 deletions(-) delete mode 100644 src/test/ui/consts/const-eval/issue-62272.rs delete mode 100644 src/test/ui/consts/const-eval/issue-62272.stderr delete mode 100644 src/test/ui/consts/const-labeled-break.stderr rename src/test/ui/consts/control-flow/{loop.loop_.stderr => loop.stderr} (88%) delete mode 100644 src/test/ui/consts/control-flow/loop.stock.stderr delete mode 100644 src/test/ui/consts/min_const_fn/loop_ice.rs delete mode 100644 src/test/ui/consts/min_const_fn/loop_ice.stderr diff --git a/src/test/compile-fail/issue-52443.rs b/src/test/compile-fail/issue-52443.rs index 00aca1d14ba..21bd6252219 100644 --- a/src/test/compile-fail/issue-52443.rs +++ b/src/test/compile-fail/issue-52443.rs @@ -1,11 +1,11 @@ fn main() { [(); & { loop { continue } } ]; //~ ERROR mismatched types - //~^ ERROR `loop` is not allowed in a `const` + [(); loop { break }]; //~ ERROR mismatched types - //~^ ERROR `loop` is not allowed in a `const` + [(); {while true {break}; 0}]; - //~^ ERROR `while` is not allowed in a `const` - //~| WARN denote infinite loops with + //~^ WARN denote infinite loops with + [(); { for _ in 0usize.. {}; 0}]; //~^ ERROR `for` is not allowed in a `const` //~| ERROR calls in constants are limited to constant functions diff --git a/src/test/ui/async-await/issue-70594.rs b/src/test/ui/async-await/issue-70594.rs index 34d12db8806..9e7c5847b3b 100644 --- a/src/test/ui/async-await/issue-70594.rs +++ b/src/test/ui/async-await/issue-70594.rs @@ -4,7 +4,6 @@ async fn fun() { [1; ().await]; //~^ error: `await` is only allowed inside `async` functions and blocks //~| error: `.await` is not allowed in a `const` - //~| error: `loop` is not allowed in a `const` //~| error: `.await` is not allowed in a `const` //~| error: `()` is not a future } diff --git a/src/test/ui/async-await/issue-70594.stderr b/src/test/ui/async-await/issue-70594.stderr index 1b7abe31722..badb7ae9f6f 100644 --- a/src/test/ui/async-await/issue-70594.stderr +++ b/src/test/ui/async-await/issue-70594.stderr @@ -12,15 +12,6 @@ error[E0744]: `.await` is not allowed in a `const` LL | [1; ().await]; | ^^^^^^^^ -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/issue-70594.rs:4:9 - | -LL | [1; ().await]; - | ^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - error[E0744]: `.await` is not allowed in a `const` --> $DIR/issue-70594.rs:4:9 | @@ -36,7 +27,7 @@ LL | [1; ().await]; = help: the trait `std::future::Future` is not implemented for `()` = note: required by `std::future::Future::poll` -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0277, E0658, E0728, E0744. +Some errors have detailed explanations: E0277, E0728, E0744. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/closures/issue-52437.rs b/src/test/ui/closures/issue-52437.rs index 634638e1335..f79a0bd3548 100644 --- a/src/test/ui/closures/issue-52437.rs +++ b/src/test/ui/closures/issue-52437.rs @@ -1,7 +1,6 @@ fn main() { [(); &(&'static: loop { |x| {}; }) as *const _ as usize] //~^ ERROR: invalid label name `'static` - //~| ERROR: `loop` is not allowed in a `const` //~| ERROR: type annotations needed //~| ERROR mismatched types } diff --git a/src/test/ui/closures/issue-52437.stderr b/src/test/ui/closures/issue-52437.stderr index acb59c7b02d..54825cb746d 100644 --- a/src/test/ui/closures/issue-52437.stderr +++ b/src/test/ui/closures/issue-52437.stderr @@ -4,15 +4,6 @@ error: invalid label name `'static` LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize] | ^^^^^^^ -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/issue-52437.rs:2:13 - | -LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - error[E0282]: type annotations needed --> $DIR/issue-52437.rs:2:30 | @@ -27,7 +18,7 @@ LL | fn main() { LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[(); _]` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0282, E0308, E0658. +Some errors have detailed explanations: E0282, E0308. For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs index 7c2c40dd6fc..14a573ccf5a 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.rs +++ b/src/test/ui/consts/const-eval/infinite_loop.rs @@ -4,7 +4,6 @@ fn main() { let _ = [(); { let mut n = 113383; // #20 in https://oeis.org/A006884 while n != 0 { - //~^ ERROR `while` is not allowed in a `const` n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; //~^ ERROR evaluation of constant value failed } diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr index df96f32516c..d01376e5959 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.stderr +++ b/src/test/ui/consts/const-eval/infinite_loop.stderr @@ -1,23 +1,9 @@ -error[E0658]: `while` is not allowed in a `const` - --> $DIR/infinite_loop.rs:6:9 - | -LL | / while n != 0 { -LL | | -LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; -LL | | -LL | | } - | |_________^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - error[E0080]: evaluation of constant value failed - --> $DIR/infinite_loop.rs:8:17 + --> $DIR/infinite_loop.rs:7:17 | LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`) -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0080, E0658. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-52442.rs b/src/test/ui/consts/const-eval/issue-52442.rs index 07fb491015a..ea24578c7dd 100644 --- a/src/test/ui/consts/const-eval/issue-52442.rs +++ b/src/test/ui/consts/const-eval/issue-52442.rs @@ -1,6 +1,5 @@ fn main() { [(); { &loop { break } as *const _ as usize } ]; - //~^ ERROR `loop` is not allowed in a `const` - //~| ERROR casting pointers to integers in constants is unstable + //~^ ERROR casting pointers to integers in constants is unstable //~| ERROR evaluation of constant value failed } diff --git a/src/test/ui/consts/const-eval/issue-52442.stderr b/src/test/ui/consts/const-eval/issue-52442.stderr index eda2dbf0b6b..53a87837e16 100644 --- a/src/test/ui/consts/const-eval/issue-52442.stderr +++ b/src/test/ui/consts/const-eval/issue-52442.stderr @@ -1,12 +1,3 @@ -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/issue-52442.rs:2:14 - | -LL | [(); { &loop { break } as *const _ as usize } ]; - | ^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - error[E0658]: casting pointers to integers in constants is unstable --> $DIR/issue-52442.rs:2:13 | @@ -22,7 +13,7 @@ error[E0080]: evaluation of constant value failed LL | [(); { &loop { break } as *const _ as usize } ]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0080, E0658. For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-52475.rs b/src/test/ui/consts/const-eval/issue-52475.rs index 869f0b981af..ce65407bbab 100644 --- a/src/test/ui/consts/const-eval/issue-52475.rs +++ b/src/test/ui/consts/const-eval/issue-52475.rs @@ -3,7 +3,6 @@ fn main() { let mut x = &0; let mut n = 0; while n < 5 { - //~^ ERROR `while` is not allowed in a `const` n = (n + 1) % 5; //~ ERROR evaluation of constant value failed x = &0; // Materialize a new AllocId } diff --git a/src/test/ui/consts/const-eval/issue-52475.stderr b/src/test/ui/consts/const-eval/issue-52475.stderr index c41000e7135..8536ff02c6d 100644 --- a/src/test/ui/consts/const-eval/issue-52475.stderr +++ b/src/test/ui/consts/const-eval/issue-52475.stderr @@ -1,23 +1,9 @@ -error[E0658]: `while` is not allowed in a `const` - --> $DIR/issue-52475.rs:5:9 - | -LL | / while n < 5 { -LL | | -LL | | n = (n + 1) % 5; -LL | | x = &0; // Materialize a new AllocId -LL | | } - | |_________^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - error[E0080]: evaluation of constant value failed - --> $DIR/issue-52475.rs:7:17 + --> $DIR/issue-52475.rs:6:17 | LL | n = (n + 1) % 5; | ^^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`) -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0080, E0658. -For more information about an error, try `rustc --explain E0080`. +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/issue-62272.rs b/src/test/ui/consts/const-eval/issue-62272.rs deleted file mode 100644 index 19abd91252d..00000000000 --- a/src/test/ui/consts/const-eval/issue-62272.rs +++ /dev/null @@ -1,11 +0,0 @@ -// `loop`s unconditionally-broken-from used to be allowed in constants, but are now forbidden by -// the HIR const-checker. -// -// See https://github.com/rust-lang/rust/pull/66170 and -// https://github.com/rust-lang/rust/issues/62272. - -const FOO: () = loop { break; }; //~ ERROR `loop` is not allowed in a `const` - -fn main() { - [FOO; { let x; loop { x = 5; break; } x }]; //~ ERROR `loop` is not allowed in a `const` -} diff --git a/src/test/ui/consts/const-eval/issue-62272.stderr b/src/test/ui/consts/const-eval/issue-62272.stderr deleted file mode 100644 index 380f68bee09..00000000000 --- a/src/test/ui/consts/const-eval/issue-62272.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/issue-62272.rs:7:17 - | -LL | const FOO: () = loop { break; }; - | ^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/issue-62272.rs:10:20 - | -LL | [FOO; { let x; loop { x = 5; break; } x }]; - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const-eval/issue-70723.rs b/src/test/ui/consts/const-eval/issue-70723.rs index 8b79d5d53c5..3c81afa67a6 100644 --- a/src/test/ui/consts/const-eval/issue-70723.rs +++ b/src/test/ui/consts/const-eval/issue-70723.rs @@ -1,5 +1,3 @@ -#![feature(const_loop)] - static _X: () = loop {}; //~ ERROR could not evaluate static initializer fn main() {} diff --git a/src/test/ui/consts/const-eval/issue-70723.stderr b/src/test/ui/consts/const-eval/issue-70723.stderr index 687d6565a71..09fb3e060dc 100644 --- a/src/test/ui/consts/const-eval/issue-70723.stderr +++ b/src/test/ui/consts/const-eval/issue-70723.stderr @@ -1,5 +1,5 @@ error[E0080]: could not evaluate static initializer - --> $DIR/issue-70723.rs:3:17 + --> $DIR/issue-70723.rs:1:17 | LL | static _X: () = loop {}; | ^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`) diff --git a/src/test/ui/consts/const-eval/livedrop.rs b/src/test/ui/consts/const-eval/livedrop.rs index f00d1c70659..66b7d058080 100644 --- a/src/test/ui/consts/const-eval/livedrop.rs +++ b/src/test/ui/consts/const-eval/livedrop.rs @@ -1,6 +1,3 @@ -#![feature(const_if_match)] -#![feature(const_loop)] - const _: Option> = { let mut never_returned = Some(Vec::new()); let mut always_returned = None; //~ ERROR destructors cannot be evaluated at compile-time diff --git a/src/test/ui/consts/const-eval/livedrop.stderr b/src/test/ui/consts/const-eval/livedrop.stderr index b802d23d9a8..1e8b4230c6f 100644 --- a/src/test/ui/consts/const-eval/livedrop.stderr +++ b/src/test/ui/consts/const-eval/livedrop.stderr @@ -1,5 +1,5 @@ error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/livedrop.rs:6:9 + --> $DIR/livedrop.rs:3:9 | LL | let mut always_returned = None; | ^^^^^^^^^^^^^^^^^^^ constants cannot evaluate destructors diff --git a/src/test/ui/consts/const-labeled-break.rs b/src/test/ui/consts/const-labeled-break.rs index 45e3cf43888..6864f7247ad 100644 --- a/src/test/ui/consts/const-labeled-break.rs +++ b/src/test/ui/consts/const-labeled-break.rs @@ -1,12 +1,11 @@ +// run-pass + // Using labeled break in a while loop has caused an illegal instruction being // generated, and an ICE later. // // See https://github.com/rust-lang/rust/issues/51350 for more information. -// -// It is now forbidden by the HIR const-checker. -// -// See https://github.com/rust-lang/rust/pull/66170. -const CRASH: () = 'a: while break 'a {}; //~ ERROR `while` is not allowed in a `const` +#[allow(unreachable_code)] +const _: () = 'a: while break 'a {}; fn main() {} diff --git a/src/test/ui/consts/const-labeled-break.stderr b/src/test/ui/consts/const-labeled-break.stderr deleted file mode 100644 index 1e24bb4ab98..00000000000 --- a/src/test/ui/consts/const-labeled-break.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `while` is not allowed in a `const` - --> $DIR/const-labeled-break.rs:10:19 - | -LL | const CRASH: () = 'a: while break 'a {}; - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs b/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs index fa56de065ae..629d1f02a30 100644 --- a/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs +++ b/src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs @@ -1,7 +1,6 @@ // check-pass #![feature(const_eval_limit)] -#![feature(const_loop)] // This needs to be higher than the number of loop iterations since each pass through the loop may // hit more than one terminator. diff --git a/src/test/ui/consts/const_limit/const_eval_limit_reached.rs b/src/test/ui/consts/const_limit/const_eval_limit_reached.rs index a98a17f95d2..069dac00c9a 100644 --- a/src/test/ui/consts/const_limit/const_eval_limit_reached.rs +++ b/src/test/ui/consts/const_limit/const_eval_limit_reached.rs @@ -1,5 +1,4 @@ #![feature(const_eval_limit)] -#![feature(const_loop)] #![const_eval_limit = "500"] const X: usize = { diff --git a/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr b/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr index 2c4f4ebd99a..8785c9e54b9 100644 --- a/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr +++ b/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr @@ -1,5 +1,5 @@ error: any use of this value will cause an error - --> $DIR/const_eval_limit_reached.rs:7:11 + --> $DIR/const_eval_limit_reached.rs:6:5 | LL | / const X: usize = { LL | | let mut x = 0; diff --git a/src/test/ui/consts/control-flow/basics.rs b/src/test/ui/consts/control-flow/basics.rs index 3701f349d07..6dd6192941d 100644 --- a/src/test/ui/consts/control-flow/basics.rs +++ b/src/test/ui/consts/control-flow/basics.rs @@ -3,7 +3,6 @@ // run-pass #![feature(const_panic)] -#![feature(const_loop)] #![feature(const_fn)] const X: u32 = 4; diff --git a/src/test/ui/consts/control-flow/drop-fail.precise.stderr b/src/test/ui/consts/control-flow/drop-fail.precise.stderr index f4edfaf72be..0b0b2443a4a 100644 --- a/src/test/ui/consts/control-flow/drop-fail.precise.stderr +++ b/src/test/ui/consts/control-flow/drop-fail.precise.stderr @@ -1,11 +1,11 @@ error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:9:9 + --> $DIR/drop-fail.rs:8:9 | LL | let x = Some(Vec::new()); | ^ constants cannot evaluate destructors error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:40:9 + --> $DIR/drop-fail.rs:39:9 | LL | let mut tmp = None; | ^^^^^^^ constants cannot evaluate destructors diff --git a/src/test/ui/consts/control-flow/drop-fail.rs b/src/test/ui/consts/control-flow/drop-fail.rs index 94deeb8c54c..efa5a11c941 100644 --- a/src/test/ui/consts/control-flow/drop-fail.rs +++ b/src/test/ui/consts/control-flow/drop-fail.rs @@ -1,6 +1,5 @@ // revisions: stock precise -#![feature(const_loop)] #![cfg_attr(precise, feature(const_precise_live_drops))] // `x` is *not* always moved into the final value and may be dropped inside the initializer. diff --git a/src/test/ui/consts/control-flow/drop-fail.stock.stderr b/src/test/ui/consts/control-flow/drop-fail.stock.stderr index 94734222117..72ca4fa08bc 100644 --- a/src/test/ui/consts/control-flow/drop-fail.stock.stderr +++ b/src/test/ui/consts/control-flow/drop-fail.stock.stderr @@ -1,5 +1,5 @@ error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:9:9 + --> $DIR/drop-fail.rs:8:9 | LL | let x = Some(Vec::new()); | ^ constants cannot evaluate destructors @@ -8,7 +8,7 @@ LL | }; | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:22:9 + --> $DIR/drop-fail.rs:21:9 | LL | let vec_tuple = (Vec::new(),); | ^^^^^^^^^ constants cannot evaluate destructors @@ -17,7 +17,7 @@ LL | }; | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:30:9 + --> $DIR/drop-fail.rs:29:9 | LL | let x: Result<_, Vec> = Ok(Vec::new()); | ^ constants cannot evaluate destructors @@ -26,7 +26,7 @@ LL | }; | - value is dropped here error[E0493]: destructors cannot be evaluated at compile-time - --> $DIR/drop-fail.rs:40:9 + --> $DIR/drop-fail.rs:39:9 | LL | let mut tmp = None; | ^^^^^^^ constants cannot evaluate destructors diff --git a/src/test/ui/consts/control-flow/drop-pass.rs b/src/test/ui/consts/control-flow/drop-pass.rs index 2ef8e08d744..95f954a59a8 100644 --- a/src/test/ui/consts/control-flow/drop-pass.rs +++ b/src/test/ui/consts/control-flow/drop-pass.rs @@ -1,7 +1,6 @@ // run-pass // revisions: stock precise -#![feature(const_loop)] #![cfg_attr(precise, feature(const_precise_live_drops))] // `x` is always moved into the final value and is not dropped inside the initializer. diff --git a/src/test/ui/consts/control-flow/drop-precise.rs b/src/test/ui/consts/control-flow/drop-precise.rs index 058c5608ec1..4ecc5ef78dd 100644 --- a/src/test/ui/consts/control-flow/drop-precise.rs +++ b/src/test/ui/consts/control-flow/drop-precise.rs @@ -1,7 +1,6 @@ // run-pass // gate-test-const_precise_live_drops -#![feature(const_loop)] #![feature(const_precise_live_drops)] const _: Vec = { diff --git a/src/test/ui/consts/control-flow/interior-mutability.rs b/src/test/ui/consts/control-flow/interior-mutability.rs index cabdf4a929b..a6d44237b0d 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.rs +++ b/src/test/ui/consts/control-flow/interior-mutability.rs @@ -1,8 +1,6 @@ // Ensure that *any* assignment to the return place of a value with interior mutability // disqualifies it from promotion. -#![feature(const_loop)] - use std::cell::Cell; const X: Option> = { diff --git a/src/test/ui/consts/control-flow/interior-mutability.stderr b/src/test/ui/consts/control-flow/interior-mutability.stderr index 8f18ae1816a..4f9c7d34c35 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.stderr +++ b/src/test/ui/consts/control-flow/interior-mutability.stderr @@ -1,5 +1,5 @@ error[E0716]: temporary value dropped while borrowed - --> $DIR/interior-mutability.rs:42:26 + --> $DIR/interior-mutability.rs:40:26 | LL | let x: &'static _ = &X; | ---------- ^ creates a temporary which is freed while still in use @@ -10,7 +10,7 @@ LL | } | - temporary value is freed at the end of this statement error[E0716]: temporary value dropped while borrowed - --> $DIR/interior-mutability.rs:43:26 + --> $DIR/interior-mutability.rs:41:26 | LL | let y: &'static _ = &Y; | ---------- ^ creates a temporary which is freed while still in use @@ -21,7 +21,7 @@ LL | } | - temporary value is freed at the end of this statement error[E0716]: temporary value dropped while borrowed - --> $DIR/interior-mutability.rs:44:26 + --> $DIR/interior-mutability.rs:42:26 | LL | let z: &'static _ = &Z; | ---------- ^ creates a temporary which is freed while still in use diff --git a/src/test/ui/consts/control-flow/loop.rs b/src/test/ui/consts/control-flow/loop.rs index 30cc3d1b1af..2b8561a2644 100644 --- a/src/test/ui/consts/control-flow/loop.rs +++ b/src/test/ui/consts/control-flow/loop.rs @@ -1,29 +1,22 @@ -// Ensure that loops are forbidden in a const context unless `#![feature(const_loop)]` is enabled. +const _: () = loop { break (); }; -// gate-test-const_loop -// revisions: stock loop_ - -#![cfg_attr(loop_, feature(const_loop))] - -const _: () = loop {}; //[stock]~ ERROR `loop` is not allowed in a `const` - -static FOO: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `static` +static FOO: i32 = loop { break 4; }; const fn foo() { - loop {} //[stock]~ ERROR `loop` is not allowed in a `const fn` + loop {} } pub trait Foo { - const BAR: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `const` + const BAR: i32 = loop { break 4; }; } impl Foo for () { - const BAR: i32 = loop { break 4; }; //[stock]~ ERROR `loop` is not allowed in a `const` + const BAR: i32 = loop { break 4; }; } fn non_const_outside() { const fn const_inside() { - loop {} //[stock]~ ERROR `loop` is not allowed in a `const fn` + loop {} } } @@ -36,7 +29,6 @@ const fn const_outside() { fn main() { let x = [0; { while false {} - //[stock]~^ ERROR `while` is not allowed in a `const` 4 }]; } @@ -44,11 +36,11 @@ fn main() { const _: i32 = { let mut x = 0; - while x < 4 { //[stock]~ ERROR `while` is not allowed in a `const` + while x < 4 { x += 1; } - while x < 8 { //[stock]~ ERROR `while` is not allowed in a `const` + while x < 8 { x += 1; } @@ -58,11 +50,11 @@ const _: i32 = { const _: i32 = { let mut x = 0; - for i in 0..4 { //[stock,loop_]~ ERROR `for` is not allowed in a `const` + for i in 0..4 { //~ ERROR `for` is not allowed in a `const` x += i; } - for i in 0..4 { //[stock,loop_]~ ERROR `for` is not allowed in a `const` + for i in 0..4 { //~ ERROR `for` is not allowed in a `const` x += i; } @@ -72,14 +64,14 @@ const _: i32 = { const _: i32 = { let mut x = 0; - loop { //[stock]~ ERROR `loop` is not allowed in a `const` + loop { x += 1; if x == 4 { break; } } - loop { //[stock]~ ERROR `loop` is not allowed in a `const` + loop { x += 1; if x == 8 { break; @@ -91,7 +83,7 @@ const _: i32 = { const _: i32 = { let mut x = 0; - while let None = Some(x) { } //[stock]~ ERROR `while` is not allowed in a `const` - while let None = Some(x) { } //[stock]~ ERROR `while` is not allowed in a `const` + while let None = Some(x) { } + while let None = Some(x) { } x }; diff --git a/src/test/ui/consts/control-flow/loop.loop_.stderr b/src/test/ui/consts/control-flow/loop.stderr similarity index 88% rename from src/test/ui/consts/control-flow/loop.loop_.stderr rename to src/test/ui/consts/control-flow/loop.stderr index c40cee6620e..7b99fa4fe46 100644 --- a/src/test/ui/consts/control-flow/loop.loop_.stderr +++ b/src/test/ui/consts/control-flow/loop.stderr @@ -1,5 +1,5 @@ error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:61:5 + --> $DIR/loop.rs:53:5 | LL | / for i in 0..4 { LL | | x += i; @@ -7,7 +7,7 @@ LL | | } | |_____^ error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:65:5 + --> $DIR/loop.rs:57:5 | LL | / for i in 0..4 { LL | | x += i; diff --git a/src/test/ui/consts/control-flow/loop.stock.stderr b/src/test/ui/consts/control-flow/loop.stock.stderr deleted file mode 100644 index a9ac3929bba..00000000000 --- a/src/test/ui/consts/control-flow/loop.stock.stderr +++ /dev/null @@ -1,151 +0,0 @@ -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:8:15 - | -LL | const _: () = loop {}; - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `static` - --> $DIR/loop.rs:10:19 - | -LL | static FOO: i32 = loop { break 4; }; - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop.rs:13:5 - | -LL | loop {} - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop.rs:26:9 - | -LL | loop {} - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:38:9 - | -LL | while false {} - | ^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:47:5 - | -LL | / while x < 4 { -LL | | x += 1; -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:51:5 - | -LL | / while x < 8 { -LL | | x += 1; -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:61:5 - | -LL | / for i in 0..4 { -LL | | x += i; -LL | | } - | |_____^ - -error[E0744]: `for` is not allowed in a `const` - --> $DIR/loop.rs:65:5 - | -LL | / for i in 0..4 { -LL | | x += i; -LL | | } - | |_____^ - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:75:5 - | -LL | / loop { -LL | | x += 1; -LL | | if x == 4 { -LL | | break; -LL | | } -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:82:5 - | -LL | / loop { -LL | | x += 1; -LL | | if x == 8 { -LL | | break; -LL | | } -LL | | } - | |_____^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:94:5 - | -LL | while let None = Some(x) { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `while` is not allowed in a `const` - --> $DIR/loop.rs:95:5 - | -LL | while let None = Some(x) { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:17:22 - | -LL | const BAR: i32 = loop { break 4; }; - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error[E0658]: `loop` is not allowed in a `const` - --> $DIR/loop.rs:21:22 - | -LL | const BAR: i32 = loop { break 4; }; - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error: aborting due to 15 previous errors - -Some errors have detailed explanations: E0658, E0744. -For more information about an error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/min_const_fn/loop_ice.rs b/src/test/ui/consts/min_const_fn/loop_ice.rs deleted file mode 100644 index 754a1d7c2a3..00000000000 --- a/src/test/ui/consts/min_const_fn/loop_ice.rs +++ /dev/null @@ -1,5 +0,0 @@ -const fn foo() { - loop {} //~ ERROR `loop` is not allowed in a `const fn` -} - -fn main() {} diff --git a/src/test/ui/consts/min_const_fn/loop_ice.stderr b/src/test/ui/consts/min_const_fn/loop_ice.stderr deleted file mode 100644 index f48b7396e77..00000000000 --- a/src/test/ui/consts/min_const_fn/loop_ice.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `loop` is not allowed in a `const fn` - --> $DIR/loop_ice.rs:2:5 - | -LL | loop {} - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/internal/internal-unstable-const.rs b/src/test/ui/internal/internal-unstable-const.rs index a32338c6546..3b3a2950942 100644 --- a/src/test/ui/internal/internal-unstable-const.rs +++ b/src/test/ui/internal/internal-unstable-const.rs @@ -1,12 +1,14 @@ +// Don't allow unstable features in stable functions without `allow_internal_unstable`. + #![stable(feature = "rust1", since = "1.0.0")] #![feature(staged_api)] -#![feature(const_loop, const_fn)] +#![feature(const_transmute, const_fn)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] -const fn foo() -> i32 { - loop { return 42; } //~ ERROR `loop` is not allowed in a `const fn` +pub const fn foo() -> i32 { + unsafe { std::mem::transmute(4u32) } //~ ERROR is not stable as `const fn` } fn main() {} diff --git a/src/test/ui/internal/internal-unstable-const.stderr b/src/test/ui/internal/internal-unstable-const.stderr index a43e014b1c6..5a2c58f3928 100644 --- a/src/test/ui/internal/internal-unstable-const.stderr +++ b/src/test/ui/internal/internal-unstable-const.stderr @@ -1,9 +1,12 @@ -error[E0744]: `loop` is not allowed in a `const fn` - --> $DIR/internal-unstable-const.rs:9:5 +error[E0723]: can only call other `const fn` within a `const fn`, but `const std::intrinsics::transmute::` is not stable as `const fn` + --> $DIR/internal-unstable-const.rs:11:14 | -LL | loop { return 42; } - | ^^^^^^^^^^^^^^^^^^^ +LL | unsafe { std::mem::transmute(4u32) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #57563 for more information + = help: add `#![feature(const_fn)]` to the crate attributes to enable error: aborting due to previous error -For more information about this error, try `rustc --explain E0744`. +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/issues/issue-51714.rs b/src/test/ui/issues/issue-51714.rs index 782037a1fe5..0dc588d75c6 100644 --- a/src/test/ui/issues/issue-51714.rs +++ b/src/test/ui/issues/issue-51714.rs @@ -10,5 +10,4 @@ fn main() { [(); return while let Some(n) = Some(0) {}]; //~^ ERROR return statement outside of function body - //~| ERROR `while` is not allowed in a `const` } diff --git a/src/test/ui/issues/issue-51714.stderr b/src/test/ui/issues/issue-51714.stderr index 71d4022a6d4..023d9013ab4 100644 --- a/src/test/ui/issues/issue-51714.stderr +++ b/src/test/ui/issues/issue-51714.stderr @@ -1,12 +1,3 @@ -error[E0658]: `while` is not allowed in a `const` - --> $DIR/issue-51714.rs:11:17 - | -LL | [(); return while let Some(n) = Some(0) {}]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable - error[E0572]: return statement outside of function body --> $DIR/issue-51714.rs:2:14 | @@ -31,7 +22,6 @@ error[E0572]: return statement outside of function body LL | [(); return while let Some(n) = Some(0) {}]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0572, E0658. -For more information about an error, try `rustc --explain E0572`. +For more information about this error, try `rustc --explain E0572`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs index 6154b484d34..655d4d7400b 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs @@ -4,12 +4,13 @@ #![allow(incomplete_features)] pub trait MyTrait { - fn method(&self); + fn method(&self) -> Option<()>; } impl const MyTrait for () { - fn method(&self) { - loop {} //~ ERROR `loop` is not allowed in a `const fn` + fn method(&self) -> Option<()> { + Some(())?; //~ ERROR `?` is not allowed in a `const fn` + None } } diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr index ec404060535..8c76d7eb597 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr @@ -1,12 +1,9 @@ -error[E0658]: `loop` is not allowed in a `const fn` +error[E0744]: `?` is not allowed in a `const fn` --> $DIR/hir-const-check.rs:12:9 | -LL | loop {} - | ^^^^^^^ - | - = note: see issue #52000 for more information - = help: add `#![feature(const_loop)]` to the crate attributes to enable +LL | Some(())?; + | ^^^^^^^^^ error: aborting due to previous error -For more information about this error, try `rustc --explain E0658`. +For more information about this error, try `rustc --explain E0744`. diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed index 6ba5cfb1d71..8b4e2d21331 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching.fixed @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::unit_arg, unused_must_use, clippy::needless_bool, deprecated)] diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching.rs index 17de66f9ad0..b0904e41b6f 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching.rs @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(clippy::unit_arg, unused_must_use, clippy::needless_bool, deprecated)] diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr index 1b9a4b40a2f..51a6f4350d3 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:10:12 + --> $DIR/redundant_pattern_matching.rs:8:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` @@ -7,67 +7,67 @@ LL | if let Ok(_) = Ok::(42) {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:12:12 + --> $DIR/redundant_pattern_matching.rs:10:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:14:12 + --> $DIR/redundant_pattern_matching.rs:12:12 | LL | if let None = None::<()> {} | -------^^^^------------- help: try this: `if None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:16:12 + --> $DIR/redundant_pattern_matching.rs:14:12 | LL | if let Some(_) = Some(42) {} | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:18:12 + --> $DIR/redundant_pattern_matching.rs:16:12 | LL | if let Some(_) = Some(42) { | -------^^^^^^^----------- help: try this: `if Some(42).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:24:15 + --> $DIR/redundant_pattern_matching.rs:22:15 | LL | while let Some(_) = Some(42) {} | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:26:15 + --> $DIR/redundant_pattern_matching.rs:24:15 | LL | while let None = Some(42) {} | ----------^^^^----------- help: try this: `while Some(42).is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:28:15 + --> $DIR/redundant_pattern_matching.rs:26:15 | LL | while let None = None::<()> {} | ----------^^^^------------- help: try this: `while None::<()>.is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:30:15 + --> $DIR/redundant_pattern_matching.rs:28:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:32:15 + --> $DIR/redundant_pattern_matching.rs:30:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:35:15 + --> $DIR/redundant_pattern_matching.rs:33:15 | LL | while let Some(_) = v.pop() { | ----------^^^^^^^---------- help: try this: `while v.pop().is_some()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:51:5 + --> $DIR/redundant_pattern_matching.rs:49:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -76,7 +76,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:56:5 + --> $DIR/redundant_pattern_matching.rs:54:5 | LL | / match Ok::(42) { LL | | Ok(_) => false, @@ -85,7 +85,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:61:5 + --> $DIR/redundant_pattern_matching.rs:59:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -94,7 +94,7 @@ LL | | }; | |_____^ help: try this: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:66:5 + --> $DIR/redundant_pattern_matching.rs:64:5 | LL | / match Err::(42) { LL | | Ok(_) => true, @@ -103,7 +103,7 @@ LL | | }; | |_____^ help: try this: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:71:5 + --> $DIR/redundant_pattern_matching.rs:69:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -112,7 +112,7 @@ LL | | }; | |_____^ help: try this: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:76:5 + --> $DIR/redundant_pattern_matching.rs:74:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: try this: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:81:13 + --> $DIR/redundant_pattern_matching.rs:79:13 | LL | let _ = match None::<()> { | _____________^ @@ -131,61 +131,61 @@ LL | | }; | |_____^ help: try this: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:86:20 + --> $DIR/redundant_pattern_matching.rs:84:20 | LL | let _ = if let Ok(_) = Ok::(4) { true } else { false }; | -------^^^^^--------------------- help: try this: `if Ok::(4).is_ok()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:89:20 + --> $DIR/redundant_pattern_matching.rs:87:20 | LL | let x = if let Some(_) = opt { true } else { false }; | -------^^^^^^^------ help: try this: `if opt.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:95:20 + --> $DIR/redundant_pattern_matching.rs:93:20 | LL | let _ = if let Some(_) = gen_opt() { | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching.rs:97:19 + --> $DIR/redundant_pattern_matching.rs:95:19 | LL | } else if let None = gen_opt() { | -------^^^^------------ help: try this: `if gen_opt().is_none()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching.rs:99:19 + --> $DIR/redundant_pattern_matching.rs:97:19 | LL | } else if let Ok(_) = gen_res() { | -------^^^^^------------ help: try this: `if gen_res().is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching.rs:101:19 + --> $DIR/redundant_pattern_matching.rs:99:19 | LL | } else if let Err(_) = gen_res() { | -------^^^^^^------------ help: try this: `if gen_res().is_err()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:134:19 + --> $DIR/redundant_pattern_matching.rs:132:19 | LL | while let Some(_) = r#try!(result_opt()) {} | ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:135:16 + --> $DIR/redundant_pattern_matching.rs:133:16 | LL | if let Some(_) = r#try!(result_opt()) {} | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:141:12 + --> $DIR/redundant_pattern_matching.rs:139:12 | LL | if let Some(_) = m!() {} | -------^^^^^^^------- help: try this: `if m!().is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching.rs:142:15 + --> $DIR/redundant_pattern_matching.rs:140:15 | LL | while let Some(_) = m!() {} | ----------^^^^^^^------- help: try this: `while m!().is_some()` diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed index c8bc5458067..8a81e92f04a 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.fixed @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![feature(const_result)] #![warn(clippy::redundant_pattern_matching)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs index 75f37ec15c6..1cd515441d1 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.rs @@ -1,7 +1,5 @@ // run-rustfix -#![feature(const_if_match)] -#![feature(const_loop)] #![feature(const_result)] #![warn(clippy::redundant_pattern_matching)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr index c32292f0eee..8ecd72158d3 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_const_result.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:12:12 + --> $DIR/redundant_pattern_matching_const_result.rs:10:12 | LL | if let Ok(_) = Ok::(42) {} | -------^^^^^--------------------- help: try this: `if Ok::(42).is_ok()` @@ -7,25 +7,25 @@ LL | if let Ok(_) = Ok::(42) {} = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:14:12 + --> $DIR/redundant_pattern_matching_const_result.rs:12:12 | LL | if let Err(_) = Err::(42) {} | -------^^^^^^---------------------- help: try this: `if Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:16:15 + --> $DIR/redundant_pattern_matching_const_result.rs:14:15 | LL | while let Ok(_) = Ok::(10) {} | ----------^^^^^--------------------- help: try this: `while Ok::(10).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:18:15 + --> $DIR/redundant_pattern_matching_const_result.rs:16:15 | LL | while let Err(_) = Ok::(10) {} | ----------^^^^^^--------------------- help: try this: `while Ok::(10).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_const_result.rs:20:5 + --> $DIR/redundant_pattern_matching_const_result.rs:18:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -34,7 +34,7 @@ LL | | }; | |_____^ help: try this: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_const_result.rs:25:5 + --> $DIR/redundant_pattern_matching_const_result.rs:23:5 | LL | / match Err::(42) { LL | | Ok(_) => false, From 1b28f94fbb3238603d0ccb1ea048e675a7189cae Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 26 Jun 2020 13:11:24 -0700 Subject: [PATCH 13/14] Remove `ignore-tidy-filelength` --- src/librustc_middle/mir/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index d54c6db6d5e..0ed0d905007 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -2,8 +2,6 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html -// ignore-tidy-filelength - use crate::mir::interpret::{GlobalAlloc, Scalar}; use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; From 8509b6951a6a4f29b9426227e1edff6d6484571f Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 28 Jun 2020 10:13:04 -0700 Subject: [PATCH 14/14] Use `LocalDefId` in HIR const-checker --- src/librustc_passes/check_const.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index a385d96d974..738754557d8 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -70,7 +70,7 @@ pub(crate) fn provide(providers: &mut Providers<'_>) { struct CheckConstVisitor<'tcx> { tcx: TyCtxt<'tcx>, const_kind: Option, - def_id: Option, + def_id: Option, } impl<'tcx> CheckConstVisitor<'tcx> { @@ -94,7 +94,7 @@ impl<'tcx> CheckConstVisitor<'tcx> { // If `def_id` is `None`, we don't need to consider stability attributes. let def_id = match def_id { - Some(x) => x, + Some(x) => x.to_def_id(), None => return true, }; @@ -164,7 +164,7 @@ impl<'tcx> CheckConstVisitor<'tcx> { fn recurse_into( &mut self, kind: Option, - def_id: Option, + def_id: Option, f: impl FnOnce(&mut Self), ) { let parent_def_id = self.def_id; @@ -192,7 +192,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { let owner = self.tcx.hir().body_owner_def_id(body.id()); let kind = self.tcx.hir().body_const_context(owner); - self.recurse_into(kind, Some(owner.to_def_id()), |this| intravisit::walk_body(this, body)); + self.recurse_into(kind, Some(owner), |this| intravisit::walk_body(this, body)); } fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {