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 ee9cfcbd9dee2..0000000000000 --- 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`. diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 41c2b221704e6..5f18fe8bfab84 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 15466ce94a82e..aeb52bffbf24c 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -73,8 +73,8 @@ #![feature(const_ascii_ctype_on_intrinsics)] #![feature(const_alloc_layout)] #![feature(const_discriminant)] -#![feature(const_if_match)] -#![feature(const_loop)] +#![cfg_attr(bootstrap, feature(const_if_match))] +#![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/libcore/num/mod.rs b/src/libcore/num/mod.rs index b1317bc2121f6..1714d2ee98ef2 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 cb3118cba23dd..5c1c9d6ab906e 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_feature/accepted.rs b/src/librustc_feature/accepted.rs index 18dc3e30db1d4..b164b21913d6e 100644 --- a/src/librustc_feature/accepted.rs +++ b/src/librustc_feature/accepted.rs @@ -261,6 +261,10 @@ 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), + /// 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 e2d497a3adab3..8660d6a8d6410 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), @@ -530,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), diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs index b51c0a6e98840..20ac2a04b474f 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 3effc41645011..6fef49668da5f 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 0f3f3db867959..27e086f1d5002 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 82dff60a26dcb..676346fbebdd1 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_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index b3e410f362d68..0ed0d9050078c 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; @@ -148,14 +146,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 +175,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 +201,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 +224,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/lib.rs b/src/librustc_mir/lib.rs index 928d5bf88f2fc..cb6893166fd79 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -10,8 +10,8 @@ Rust MIR: a lowered representation of Rust. #![feature(box_patterns)] #![feature(box_syntax)] #![feature(const_fn)] -#![feature(const_if_match)] -#![feature(const_loop)] +#![cfg_attr(bootstrap, feature(const_if_match))] +#![cfg_attr(bootstrap, feature(const_loop))] #![feature(const_panic)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 8327affd982ed..5671b5b4f04c1 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/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 676688daf1c6d..ea025f208e49d 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 {} @@ -177,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 d263bf12e8868..ca1f0aecd048a 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -207,14 +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. - 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`. @@ -483,21 +475,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 { .. } @@ -626,44 +609,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 841f1c2b647f6..2c1565b54261c 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -134,7 +134,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 8bcbcd79ae60b..bd7ebaa01f81b 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/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index caf6c7715a9e1..5a3663384fb87 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) } diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index e2cf1bce733d6..e69f6b30abd5c 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 a1796c9433eac..d36990684e03b 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 46607fd07cdd7..d8b3ac79e6b9c 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> { diff --git a/src/librustc_mir_build/lib.rs b/src/librustc_mir_build/lib.rs index c6d65d56c93f0..b44d8eee462f0 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_passes/check_const.rs b/src/librustc_passes/check_const.rs index 90a076eeded7e..738754557d84c 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; @@ -23,7 +24,6 @@ use rustc_span::{sym, Span, Symbol}; enum NonConstExpr { Loop(hir::LoopSource), Match(hir::MatchSource), - OrPattern, } impl NonConstExpr { @@ -31,7 +31,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 +39,18 @@ 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. + // Likewise, `?` desugars to a call to `Try::into_result`. + Self::Loop(ForLoop) | Self::Match(ForLoopDesugar | TryDesugar | AwaitDesugar) => { + return None; } - // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`, - // so they are not yet allowed with `#![feature(const_loop)]`. - _ => return None, + // All other expressions are allowed. + Self::Loop(Loop | While | WhileLet) + | Self::Match( + WhileDesugar | WhileLetDesugar | Normal | IfDesugar { .. } | IfLetDesugar { .. }, + ) => &[], }; Some(gates) @@ -75,35 +70,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.to_def_id(), + 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()); @@ -112,21 +135,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(), - - // 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(); - } + &[] => 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. @@ -149,10 +161,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; } } @@ -166,22 +186,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)); - } - - 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) + self.recurse_into(kind, Some(owner), |this| intravisit::walk_body(this, body)); } fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { diff --git a/src/librustc_query_system/lib.rs b/src/librustc_query_system/lib.rs index 3afc4565933e5..74a54176774ca 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 dcd2e83b74713..6dcb1430cdc17 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 c2cdd2fd3ecf6..ec6deb5b05952 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)] diff --git a/src/test/compile-fail/issue-52443.rs b/src/test/compile-fail/issue-52443.rs index 00aca1d14baa7..21bd625221903 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/array-slice-vec/subslice-patterns-const-eval-match.rs b/src/test/ui/array-slice-vec/subslice-patterns-const-eval-match.rs index 69c33921868cf..d8a9ae6ca2030 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/async-await/issue-70594.rs b/src/test/ui/async-await/issue-70594.rs index 34d12db8806dc..9e7c5847b3b2e 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 1b7abe317222d..badb7ae9f6f65 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/borrowck/issue-64453.rs b/src/test/ui/borrowck/issue-64453.rs index 8a405edb04655..3e803f3b6d8b2 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 48859fb676342..081ccd37861cb 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: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +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: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0015, E0507. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/closures/issue-52437.rs b/src/test/ui/closures/issue-52437.rs index 634638e1335b3..f79a0bd35486a 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 acb59c7b02d1b..54825cb746d42 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 c8de259354eac..14a573ccf5ac6 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.rs +++ b/src/test/ui/consts/const-eval/infinite_loop.rs @@ -4,10 +4,8 @@ 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 - //~| 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 3386e6e588e71..d01376e595945 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.stderr +++ b/src/test/ui/consts/const-eval/infinite_loop.stderr @@ -1,34 +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 | | -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 + --> $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 3 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 07fb491015a85..ea24578c7dd0c 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 eda2dbf0b6b15..53a87837e16e3 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 869f0b981af7d..ce65407bbab0b 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 b069537ead963..8536ff02c6dae 100644 --- a/src/test/ui/consts/const-eval/issue-52475.stderr +++ b/src/test/ui/consts/const-eval/issue-52475.stderr @@ -1,24 +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 - = 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 + --> $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 19abd91252db9..0000000000000 --- 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 380f68bee09ce..0000000000000 --- 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 8b79d5d53c5c2..3c81afa67a69f 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 687d6565a7163..09fb3e060dc4c 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 f00d1c70659fd..66b7d05808084 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 b802d23d9a89c..1e8b4230c6f11 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-eval/match-test-ptr-null.rs b/src/test/ui/consts/const-eval/match-test-ptr-null.rs index 80494d1662987..f6b5ad005a884 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 b47f6d5f845fe..48dbe661492d4 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.rs b/src/test/ui/consts/const-labeled-break.rs index 45e3cf438888e..6864f7247ad5f 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 ac845df227c42..0000000000000 --- a/src/test/ui/consts/const-labeled-break.stderr +++ /dev/null @@ -1,13 +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 - = 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/const-match-pattern-arm.rs b/src/test/ui/consts/const-match-pattern-arm.rs index 0482f7f7daeab..90680c0194c55 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 412e1609ccfab..0000000000000 --- 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 81a2024a81b7b..a38731ceb8a86 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 21c4de6fbb1f1..a1f9838ca0885 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 06ec2a7fdd35c..0be1cca806ed1 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 28b3fbb952563..c7f02c615a02a 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 cb870ec7dbcf2..ee78c6f5c3e9f 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 e49d47673912a..efb134d2eef1a 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 02296e6de75fc..d7e8c048f7dcc 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 2 previous errors +error: aborting due to previous error -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 34abcdf08dae0..629d1f02a30f3 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, const_if_match)] // 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 b45aca0b13e42..069dac00c9ace 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,5 @@ #![feature(const_eval_limit)] -#![feature(const_loop, const_if_match)] - -#![const_eval_limit="500"] +#![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 8c2190b4e591f..8785c9e54b9bf 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:6:5 | 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 87b14a1117805..6403fbb17dd58 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 b020382af07c8..0000000000000 --- 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 7dd60cfb5458f..0000000000000 --- 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 466fb7c3ec5b1..0000000000000 --- 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 eafbdd84cc86c..03662a3520909 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 2da42d5084bc1..30cd31ee8a734 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 eafbdd84cc86c..fd344533ce10f 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 a53293743d522..6dd6192941d38 100644 --- a/src/test/ui/consts/control-flow/basics.rs +++ b/src/test/ui/consts/control-flow/basics.rs @@ -3,8 +3,6 @@ // run-pass #![feature(const_panic)] -#![feature(const_if_match)] -#![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 b4b6be8a1e5f0..0b0b2443a4a46 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: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:41: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 7bd36726cead5..efa5a11c941e9 100644 --- a/src/test/ui/consts/control-flow/drop-fail.rs +++ b/src/test/ui/consts/control-flow/drop-fail.rs @@ -1,7 +1,5 @@ // revisions: stock precise -#![feature(const_if_match)] -#![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 6a9ea91d20e1f..72ca4fa08bc4e 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: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:23: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:31: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:41: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 b0afd76c4e6ef..95f954a59a8dd 100644 --- a/src/test/ui/consts/control-flow/drop-pass.rs +++ b/src/test/ui/consts/control-flow/drop-pass.rs @@ -1,8 +1,6 @@ // run-pass // revisions: stock precise -#![feature(const_if_match)] -#![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 95df76d990554..4ecc5ef78dd5c 100644 --- a/src/test/ui/consts/control-flow/drop-precise.rs +++ b/src/test/ui/consts/control-flow/drop-precise.rs @@ -1,8 +1,6 @@ // run-pass // gate-test-const_precise_live_drops -#![feature(const_if_match)] -#![feature(const_loop)] #![feature(const_precise_live_drops)] const _: Vec = { 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 6bbbdd972a26c..4320133dfdbcc 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 21e3f2af15ad6..0000000000000 --- 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 c49dd830a12e8..cb66bc75309b6 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 b27971dccac6c..0000000000000 --- 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 c2439f4a7bff3..a6d44237b0d98 100644 --- a/src/test/ui/consts/control-flow/interior-mutability.rs +++ b/src/test/ui/consts/control-flow/interior-mutability.rs @@ -1,9 +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; const X: Option> = { @@ -39,7 +36,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 0977c84d12d8a..4f9c7d34c35f4 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: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:45: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:46: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/issue-46843.rs b/src/test/ui/consts/control-flow/issue-46843.rs index 1fc91015ffa70..edf62f2326619 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 4c64d7dee8c01..ea9ea25f9e12d 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 e4650da2075bd..0000000000000 --- 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 9600f8b6aeeab..beb9a44fca52d 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 831360d5652e8..b7b4c3a30d1bf 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 9d0d2831d9af3..0000000000000 --- 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.if_match.stderr b/src/test/ui/consts/control-flow/loop.if_match.stderr deleted file mode 100644 index e8ff3624b7720..0000000000000 --- 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 deleted file mode 100644 index 3d739f4d2b41b..0000000000000 --- a/src/test/ui/consts/control-flow/loop.loop_.stderr +++ /dev/null @@ -1,96 +0,0 @@ -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 - | -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]: `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]: `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`. diff --git a/src/test/ui/consts/control-flow/loop.rs b/src/test/ui/consts/control-flow/loop.rs index bc57f7568a70a..2b8561a264488 100644 --- a/src/test/ui/consts/control-flow/loop.rs +++ b/src/test/ui/consts/control-flow/loop.rs @@ -1,31 +1,22 @@ -// 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. +const _: () = loop { break (); }; -// gate-test-const_loop -// revisions: stock if_match loop_ both - -#![cfg_attr(any(both, if_match), feature(const_if_match))] -#![cfg_attr(any(both, loop_), feature(const_loop))] - -const _: () = loop {}; //[stock,if_match]~ 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; }; const fn foo() { - loop {} //[stock,if_match]~ ERROR `loop` is not allowed in a `const fn` + loop {} } 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; }; } 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; }; } fn non_const_outside() { const fn const_inside() { - loop {} //[stock,if_match]~ ERROR `loop` is not allowed in a `const fn` + loop {} } } @@ -38,7 +29,6 @@ const fn const_outside() { fn main() { let x = [0; { while false {} - //[stock,if_match,loop_]~^ ERROR `while` is not allowed in a `const` 4 }]; } @@ -46,11 +36,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 { x += 1; } - while x < 8 { //[stock,if_match,loop_]~ ERROR `while` is not allowed in a `const` + while x < 8 { x += 1; } @@ -60,11 +50,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 { //~ 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 { //~ ERROR `for` is not allowed in a `const` x += i; } @@ -74,16 +64,16 @@ const _: i32 = { const _: i32 = { let mut x = 0; - loop { //[stock,if_match]~ ERROR `loop` is not allowed in a `const` + loop { 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 { x += 1; - if x == 8 { //[stock,loop_]~ ERROR `if` is not allowed in a `const` + if x == 8 { break; } } @@ -93,7 +83,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) { } + while let None = Some(x) { } x }; diff --git a/src/test/ui/consts/control-flow/loop.both.stderr b/src/test/ui/consts/control-flow/loop.stderr similarity index 88% rename from src/test/ui/consts/control-flow/loop.both.stderr rename to src/test/ui/consts/control-flow/loop.stderr index 71d96b216f974..7b99fa4fe4609 100644 --- a/src/test/ui/consts/control-flow/loop.both.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:63: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:67: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 987ced9655186..0000000000000 --- a/src/test/ui/consts/control-flow/loop.stock.stderr +++ /dev/null @@ -1,178 +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 - = 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 - | -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 - = 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 - | -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 - = 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 - | -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]: `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 - | -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]: `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 #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 - | -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 - | -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 17 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 8cee2a54f56d3..4dfa22b8ebaf6 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 f6ba28e7b7246..0000000000000 --- 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 f5e54a69d4a6f..f6a0f03a4a6b8 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 f32f248af4557..0000000000000 --- 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 823605ff034f1..b59be00ffb788 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 31fe09d4f6962..7d85a412b4722 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 60a386ef6c870..35075a3e60b98 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/loop_ice.rs b/src/test/ui/consts/min_const_fn/loop_ice.rs deleted file mode 100644 index 754a1d7c2a3a7..0000000000000 --- 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 f48b7396e77c6..0000000000000 --- 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/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs index 557439f394953..2ebd9dd10c512 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 4b0401ebf9dba..9b55b6c6f3bbc 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 52f6536b5ea67..08d68b039bead 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 9d1e88a811f2f..52662ef9eaf5a 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 0b64786ccce54..29d3dc18fa7cc 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 928605356a16e..be797cae7ca97 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 8d2cdf34f373e..b3694bb4216c6 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 ce306c845175a..3b3a2950942d0 100644 --- a/src/test/ui/internal/internal-unstable-const.rs +++ b/src/test/ui/internal/internal-unstable-const.rs @@ -1,10 +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_if_match)] +#![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 { - if true { 4 } else { 5 } //~ loops and conditional expressions are not stable in 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 b2d97b981ba5d..5a2c58f3928dc 100644 --- a/src/test/ui/internal/internal-unstable-const.stderr +++ b/src/test/ui/internal/internal-unstable-const.stderr @@ -1,8 +1,8 @@ -error[E0723]: loops and conditional expressions are not stable in const fn - --> $DIR/internal-unstable-const.rs:7: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 | if true { 4 } else { 5 } - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | unsafe { std::mem::transmute(4u32) } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #57563 for more information = help: add `#![feature(const_fn)]` to the crate attributes to enable diff --git a/src/test/ui/issues/issue-51714.rs b/src/test/ui/issues/issue-51714.rs index 782037a1fe5d4..0dc588d75c654 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 696030850436f..023d9013ab4ed 100644 --- a/src/test/ui/issues/issue-51714.stderr +++ b/src/test/ui/issues/issue-51714.stderr @@ -1,13 +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 - = 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 | @@ -32,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/issues/issue-66706.rs b/src/test/ui/issues/issue-66706.rs index 02305191f6ebc..4585bcc8cd57f 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 ea461cc5d03fa..f0b93ac91111a 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 d21cf3dc72c99..f4af2f0d2dd40 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 345d6c7098112..0000000000000 --- 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 9f3b9651642a2..f21eac37c17b5 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 c475c7de4381b..8e801e3fbb7ab 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 d5756737f1791..71af704c69f0d 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 4c3a00e5f3583..7f343d1a853ac 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 f7af1b506f0db..655d4d7400b78 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) { - match *self {} //~ ERROR `match` 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 563a9afe5bb84..8c76d7eb597b6 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]: `match` is not allowed in a `const fn` +error[E0744]: `?` is not allowed in a `const fn` --> $DIR/hir-const-check.rs:12:9 | -LL | match *self {} - | ^^^^^^^^^^^^^^ - | - = note: see issue #49146 for more information - = help: add `#![feature(const_if_match)]` 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 6ba5cfb1d7177..8b4e2d21331cd 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 17de66f9ad0eb..b0904e41b6f43 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 1b9a4b40a2f02..51a6f4350d32c 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 c8bc5458067d3..8a81e92f04a73 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 75f37ec15c622..1cd515441d13a 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 c32292f0eee8b..8ecd72158d33c 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,