mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Auto merge of #72437 - ecstatic-morse:stabilize-const-if-match, r=oli-obk
Stabilize `#![feature(const_if_match)]` Quoting from the [stabilization report](https://github.com/rust-lang/rust/issues/49146#issuecomment-616301045): > `if` and `match` expressions as well as the short-circuiting logic operators `&&` and `||` will become legal in all [const contexts](https://doc.rust-lang.org/reference/const_eval.html#const-context). A const context is any of the following: > > - The initializer of a `const`, `static`, `static mut` or enum discriminant. > - The body of a `const fn`. > - The value of a const generic (nightly only). > - The length of an array type (`[u8; 3]`) or an array repeat expression (`[0u8; 3]`). > > Furthermore, the short-circuiting logic operators will no longer be lowered to their bitwise equivalents (`&` and `|` respectively) in `const` and `static` initializers (see #57175). As a result, `let` bindings can be used alongside short-circuiting logic in those initializers. Resolves #49146. Ideally, we would resolve 🐳 #66753 before this lands on stable, so it might be worth pushing this back a release. Also, this means we should get the process started for #52000, otherwise people will have no recourse except recursion for iterative `const fn`. r? @oli-obk
This commit is contained in:
commit
c977b8775d
@ -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`.
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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 {
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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<VarDebugInfo<'tcx>>,
|
||||
|
||||
/// 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<VarDebugInfo<'tcx>>,
|
||||
span: Span,
|
||||
control_flow_destroyed: Vec<(Span, String)>,
|
||||
generator_kind: Option<GeneratorKind>,
|
||||
) -> 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,
|
||||
|
@ -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)]
|
||||
|
@ -251,7 +251,6 @@ fn new_body<'tcx>(
|
||||
arg_count,
|
||||
vec![],
|
||||
span,
|
||||
vec![],
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
@ -142,19 +142,6 @@ impl NonConstOp for HeapAllocation {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IfOrMatch;
|
||||
impl NonConstOp for IfOrMatch {
|
||||
fn feature_gate() -> Option<Symbol> {
|
||||
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<Symbol> {
|
||||
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 {
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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| {
|
||||
|
@ -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,
|
||||
);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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> {
|
||||
|
@ -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)]
|
||||
|
@ -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<hir::ConstContext>,
|
||||
def_id: Option<LocalDefId>,
|
||||
}
|
||||
|
||||
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<hir::ConstContext>, f: impl FnOnce(&mut Self)) {
|
||||
fn recurse_into(
|
||||
&mut self,
|
||||
kind: Option<hir::ConstContext>,
|
||||
def_id: Option<LocalDefId>,
|
||||
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>) {
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
// run-pass
|
||||
|
||||
#![feature(const_fn, const_if_match)]
|
||||
#![feature(const_fn)]
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
struct N(u8);
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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 {
|
||||
|
@ -1,13 +1,26 @@
|
||||
error[E0658]: `match` is not allowed in a `static`
|
||||
error[E0507]: cannot move out of static item `settings_dir`
|
||||
--> $DIR/issue-64453.rs:14:37
|
||||
|
|
||||
LL | let settings_data = from_string(settings_dir);
|
||||
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `std::string::String`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/issue-64453.rs:4:31
|
||||
|
|
||||
LL | static settings_dir: String = format!("");
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
|
||||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/issue-64453.rs:4:31
|
||||
|
|
||||
LL | static settings_dir: String = format!("");
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0015, E0507.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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
|
||||
}];
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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`
|
||||
}
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -1,5 +1,3 @@
|
||||
#![feature(const_loop)]
|
||||
|
||||
static _X: () = loop {}; //~ ERROR could not evaluate static initializer
|
||||
|
||||
fn main() {}
|
||||
|
@ -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]`)
|
||||
|
@ -1,6 +1,3 @@
|
||||
#![feature(const_if_match)]
|
||||
#![feature(const_loop)]
|
||||
|
||||
const _: Option<Vec<i32>> = {
|
||||
let mut never_returned = Some(Vec::new());
|
||||
let mut always_returned = None; //~ ERROR destructors cannot be evaluated at compile-time
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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() {}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -1,6 +1,5 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(const_if_match)]
|
||||
#![warn(indirect_structural_match)]
|
||||
|
||||
struct CustomEq;
|
||||
|
@ -1,6 +1,5 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(const_if_match)]
|
||||
#![warn(indirect_structural_match)]
|
||||
//~^ NOTE lint level is defined here
|
||||
|
||||
|
@ -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)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(const_if_match)]
|
||||
#![warn(indirect_structural_match)]
|
||||
|
||||
struct NoEq;
|
||||
|
@ -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!(),
|
||||
| ^^^^^^^
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/57563> for more information
|
||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
||||
error: aborting due to previous error
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0005, E0723.
|
||||
For more information about an error, try `rustc --explain E0005`.
|
||||
For more information about this error, try `rustc --explain E0005`.
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/49146> for more information.
|
||||
--> $DIR/const_short_circuit.rs:9:18
|
||||
|
|
||||
LL | let x = true && false;
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -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
|
||||
|
@ -1,23 +0,0 @@
|
||||
error[E0658]: panicking in constants is unstable
|
||||
--> $DIR/assert.rs:8:15
|
||||
|
|
||||
LL | const _: () = assert!(true);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51999 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
||||
|
@ -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() {}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/49146> for more information
|
||||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
|
||||
= note: see issue #51999 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/49146> for more information
|
||||
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
|
||||
= note: see issue #51999 <https://github.com/rust-lang/rust/issues/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
|
||||
|
@ -3,8 +3,6 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(const_panic)]
|
||||
#![feature(const_if_match)]
|
||||
#![feature(const_loop)]
|
||||
#![feature(const_fn)]
|
||||
|
||||
const X: u32 = 4;
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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<i32>> = 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
|
||||
|
@ -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.
|
||||
|
@ -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<i32> = {
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
// check-pass
|
||||
|
||||
#![feature(const_if_match)]
|
||||
|
||||
enum E {
|
||||
A,
|
||||
B,
|
||||
|
@ -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
|
||||
|
@ -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<bool>) -> 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`
|
||||
}];
|
||||
}
|
||||
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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<Cell<i32>> = {
|
||||
@ -39,7 +36,6 @@ const Z: Option<Cell<i32>> = {
|
||||
z
|
||||
};
|
||||
|
||||
|
||||
fn main() {
|
||||
let x: &'static _ = &X; //~ ERROR temporary value dropped while borrowed
|
||||
let y: &'static _ = &Y; //~ ERROR temporary value dropped while borrowed
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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() {
|
||||
| ^^^^^^^^^^^
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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`
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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
|
||||
};
|
||||
|
@ -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;
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -2,7 +2,6 @@
|
||||
|
||||
// run-pass
|
||||
|
||||
#![feature(const_if_match)]
|
||||
#![feature(const_panic)]
|
||||
|
||||
const X: i32 = {
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,7 +1,5 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(const_if_match)]
|
||||
|
||||
enum Foo {
|
||||
Prob,
|
||||
}
|
||||
|
@ -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<i32> {
|
||||
let x = Some(2);
|
||||
x?; //~ ERROR `?` is not allowed in a `const fn`
|
||||
|
@ -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?;
|
||||
| ^^
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user