diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 4f5310f5285c9..db19baf7a2c64 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1348,7 +1348,7 @@ extern "rust-intrinsic" { /// use std::intrinsics::ctlz; /// /// let x = 0b0001_1100_u8; - /// let num_leading = unsafe { ctlz(x) }; + /// let num_leading = ctlz(x); /// assert_eq!(num_leading, 3); /// ``` /// @@ -1360,7 +1360,7 @@ extern "rust-intrinsic" { /// use std::intrinsics::ctlz; /// /// let x = 0u16; - /// let num_leading = unsafe { ctlz(x) }; + /// let num_leading = ctlz(x); /// assert_eq!(num_leading, 16); /// ``` pub fn ctlz(x: T) -> T; @@ -1391,7 +1391,7 @@ extern "rust-intrinsic" { /// use std::intrinsics::cttz; /// /// let x = 0b0011_1000_u8; - /// let num_trailing = unsafe { cttz(x) }; + /// let num_trailing = cttz(x); /// assert_eq!(num_trailing, 3); /// ``` /// @@ -1403,7 +1403,7 @@ extern "rust-intrinsic" { /// use std::intrinsics::cttz; /// /// let x = 0u16; - /// let num_trailing = unsafe { cttz(x) }; + /// let num_trailing = cttz(x); /// assert_eq!(num_trailing, 16); /// ``` pub fn cttz(x: T) -> T; diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index b2cafc4cede2e..a5f20d08e47be 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -71,7 +71,7 @@ #![feature(cfg_target_has_atomic)] #![feature(concat_idents)] #![feature(const_fn)] -#![feature(const_int_ops)] +#![cfg_attr(stage0, feature(const_int_ops))] #![feature(const_fn_union)] #![feature(custom_attribute)] #![feature(doc_cfg)] @@ -114,9 +114,7 @@ #![feature(const_slice_len)] #![feature(const_str_as_bytes)] #![feature(const_str_len)] -#![feature(const_int_rotate)] -#![feature(const_int_wrapping)] -#![feature(const_int_sign)] +#![cfg_attr(stage0, feature(const_int_rotate))] #![feature(const_int_conversion)] #![feature(const_transmute)] #![feature(reverse_bits)] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 97bf582df5a8c..7ff04410516a3 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -275,7 +275,7 @@ $EndFeature, " ``` "), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() } } @@ -291,7 +291,7 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn count_zeros(self) -> u32 { (!self).count_ones() @@ -312,7 +312,7 @@ assert_eq!(n.leading_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn leading_zeros(self) -> u32 { (self as $UnsignedT).leading_zeros() @@ -333,7 +333,7 @@ assert_eq!(n.trailing_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn trailing_zeros(self) -> u32 { (self as $UnsignedT).trailing_zeros() @@ -357,7 +357,7 @@ let m = ", $rot_result, "; assert_eq!(n.rotate_left(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_rotate")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))] #[inline] pub const fn rotate_left(self, n: u32) -> Self { (self as $UnsignedT).rotate_left(n) as Self @@ -382,7 +382,7 @@ let m = ", $rot_op, "; assert_eq!(n.rotate_right(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_rotate")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))] #[inline] pub const fn rotate_right(self, n: u32) -> Self { (self as $UnsignedT).rotate_right(n) as Self @@ -404,7 +404,7 @@ let m = n.swap_bytes(); assert_eq!(m, ", $swapped, "); ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn swap_bytes(self) -> Self { (self as $UnsignedT).swap_bytes() as Self @@ -454,7 +454,7 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn from_be(x: Self) -> Self { #[cfg(target_endian = "big")] @@ -488,7 +488,7 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn from_le(x: Self) -> Self { #[cfg(target_endian = "little")] @@ -522,7 +522,7 @@ if cfg!(target_endian = \"big\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn to_be(self) -> Self { // or not to be? #[cfg(target_endian = "big")] @@ -556,7 +556,7 @@ if cfg!(target_endian = \"little\") { $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn to_le(self) -> Self { #[cfg(target_endian = "little")] @@ -994,12 +994,15 @@ assert_eq!(", stringify!($SelfT), "::max_value().wrapping_add(2), ", stringify!( $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_add(self, rhs: Self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::overflowing_add(self, rhs) } + #[cfg(not(stage0))] + intrinsics::overflowing_add(self, rhs) } } @@ -1018,12 +1021,15 @@ stringify!($SelfT), "::max_value());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_sub(self, rhs: Self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::overflowing_sub(self, rhs) } + #[cfg(not(stage0))] + intrinsics::overflowing_sub(self, rhs) } } @@ -1041,12 +1047,15 @@ assert_eq!(11i8.wrapping_mul(12), -124);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_mul(self, rhs: Self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::overflowing_mul(self, rhs) } + #[cfg(not(stage0))] + intrinsics::overflowing_mul(self, rhs) } } @@ -1205,7 +1214,7 @@ assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(128), -1);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_shl(self, rhs: u32) -> Self { unsafe { @@ -1233,7 +1242,7 @@ assert_eq!((-128i16).wrapping_shr(64), -128);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_shr(self, rhs: u32) -> Self { unsafe { @@ -1886,7 +1895,6 @@ assert!(!(-10", stringify!($SelfT), ").is_positive());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_sign")] #[inline] pub const fn is_positive(self) -> bool { self > 0 } } @@ -1905,7 +1913,6 @@ assert!(!10", stringify!($SelfT), ".is_negative());", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_sign")] #[inline] pub const fn is_negative(self) -> bool { self < 0 } } @@ -2227,10 +2234,13 @@ Basic usage: assert_eq!(n.count_ones(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn count_ones(self) -> u32 { + #[cfg(stage0)] unsafe { intrinsics::ctpop(self as $ActualT) as u32 } + #[cfg(not(stage0))] + { intrinsics::ctpop(self as $ActualT) as u32 } } } @@ -2245,7 +2255,7 @@ Basic usage: ", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn count_zeros(self) -> u32 { (!self).count_ones() @@ -2265,10 +2275,13 @@ Basic usage: assert_eq!(n.leading_zeros(), 2);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn leading_zeros(self) -> u32 { + #[cfg(stage0)] unsafe { intrinsics::ctlz(self as $ActualT) as u32 } + #[cfg(not(stage0))] + { intrinsics::ctlz(self as $ActualT) as u32 } } } @@ -2286,10 +2299,13 @@ Basic usage: assert_eq!(n.trailing_zeros(), 3);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn trailing_zeros(self) -> u32 { + #[cfg(stage0)] unsafe { intrinsics::cttz(self) as u32 } + #[cfg(not(stage0))] + { intrinsics::cttz(self) as u32 } } } @@ -2310,10 +2326,13 @@ let m = ", $rot_result, "; assert_eq!(n.rotate_left(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_rotate")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))] #[inline] pub const fn rotate_left(self, n: u32) -> Self { + #[cfg(stage0)] unsafe { intrinsics::rotate_left(self, n as $SelfT) } + #[cfg(not(stage0))] + intrinsics::rotate_left(self, n as $SelfT) } } @@ -2335,10 +2354,13 @@ let m = ", $rot_op, "; assert_eq!(n.rotate_right(", $rot, "), m); ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_rotate")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))] #[inline] pub const fn rotate_right(self, n: u32) -> Self { + #[cfg(stage0)] unsafe { intrinsics::rotate_right(self, n as $SelfT) } + #[cfg(not(stage0))] + intrinsics::rotate_right(self, n as $SelfT) } } @@ -2357,10 +2379,13 @@ let m = n.swap_bytes(); assert_eq!(m, ", $swapped, "); ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn swap_bytes(self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::bswap(self as $ActualT) as Self } + #[cfg(not(stage0))] + { intrinsics::bswap(self as $ActualT) as Self } } } @@ -2380,10 +2405,13 @@ let m = n.reverse_bits(); assert_eq!(m, ", $reversed, "); ```"), #[unstable(feature = "reverse_bits", issue = "48763")] - #[rustc_const_unstable(feature = "const_int_conversion")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_conversion"))] #[inline] pub const fn reverse_bits(self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::bitreverse(self as $ActualT) as Self } + #[cfg(not(stage0))] + { intrinsics::bitreverse(self as $ActualT) as Self } } } @@ -2407,7 +2435,7 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn from_be(x: Self) -> Self { #[cfg(target_endian = "big")] @@ -2441,7 +2469,7 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn from_le(x: Self) -> Self { #[cfg(target_endian = "little")] @@ -2475,7 +2503,7 @@ if cfg!(target_endian = \"big\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn to_be(self) -> Self { // or not to be? #[cfg(target_endian = "big")] @@ -2509,7 +2537,7 @@ if cfg!(target_endian = \"little\") { }", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))] #[inline] pub const fn to_le(self) -> Self { #[cfg(target_endian = "little")] @@ -2884,12 +2912,15 @@ assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::ma $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_add(self, rhs: Self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::overflowing_add(self, rhs) } + #[cfg(not(stage0))] + intrinsics::overflowing_add(self, rhs) } } @@ -2907,12 +2938,15 @@ assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::ma $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_sub(self, rhs: Self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::overflowing_sub(self, rhs) } + #[cfg(not(stage0))] + intrinsics::overflowing_sub(self, rhs) } } @@ -2931,12 +2965,15 @@ $EndFeature, " /// assert_eq!(25u8.wrapping_mul(12), 44); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_mul(self, rhs: Self) -> Self { + #[cfg(stage0)] unsafe { intrinsics::overflowing_mul(self, rhs) } + #[cfg(not(stage0))] + intrinsics::overflowing_mul(self, rhs) } doc_comment! { @@ -3081,7 +3118,7 @@ Basic usage: assert_eq!(1", stringify!($SelfT), ".wrapping_shl(128), 1);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_shl(self, rhs: u32) -> Self { unsafe { @@ -3111,7 +3148,7 @@ Basic usage: assert_eq!(128", stringify!($SelfT), ".wrapping_shr(128), 128);", $EndFeature, " ```"), #[stable(feature = "num_wrapping", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_int_wrapping")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))] #[inline] pub const fn wrapping_shr(self, rhs: u32) -> Self { unsafe { diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index a04dd5bb5970f..193b0fe05f002 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -21,7 +21,7 @@ use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext, NonMutatingUs use rustc::middle::lang_items; use rustc::session::config::nightly_options; use syntax::ast::LitKind; -use syntax::feature_gate::{UnstableFeatures, feature_err, emit_feature_err, GateIssue}; +use syntax::feature_gate::{UnstableFeatures, emit_feature_err, GateIssue}; use syntax_pos::{Span, DUMMY_SP}; use std::fmt; @@ -104,7 +104,6 @@ struct Qualifier<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { param_env: ty::ParamEnv<'tcx>, local_qualif: IndexVec>, qualif: Qualif, - const_fn_arg_vars: BitSet, temp_promotion_state: IndexVec, promotion_candidates: Vec } @@ -139,7 +138,6 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { param_env, local_qualif, qualif: Qualif::empty(), - const_fn_arg_vars: BitSet::new_empty(mir.local_decls.len()), temp_promotion_state: temps, promotion_candidates: vec![] } @@ -168,26 +166,6 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { } } - /// Error about extra statements in a constant. - fn statement_like(&mut self) { - self.add(Qualif::NOT_CONST); - if self.mode != Mode::Fn { - let mut err = feature_err( - &self.tcx.sess.parse_sess, - "const_let", - self.span, - GateIssue::Language, - &format!("statements in {}s are unstable", self.mode), - ); - if self.tcx.sess.teach(&err.get_code().unwrap()) { - err.note("Blocks in constants may only contain items (such as constant, function \ - definition, etc...) and a tail expression."); - err.help("To avoid it, you have to replace the non-item object."); - } - err.emit(); - } - } - /// Add the given qualification to self.qualif. fn add(&mut self, qualif: Qualif) { self.qualif = self.qualif | qualif; @@ -233,80 +211,46 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { return; } - if self.tcx.features().const_let { - let mut dest = dest; - let index = loop { - match dest { - // with `const_let` active, we treat all locals equal - Place::Local(index) => break *index, - // projections are transparent for assignments - // we qualify the entire destination at once, even if just a field would have - // stricter qualification - Place::Projection(proj) => { - // Catch more errors in the destination. `visit_place` also checks various - // projection rules like union field access and raw pointer deref - self.visit_place( - dest, - PlaceContext::MutatingUse(MutatingUseContext::Store), - location - ); - dest = &proj.base; - }, - Place::Promoted(..) => bug!("promoteds don't exist yet during promotion"), - Place::Static(..) => { - // Catch more errors in the destination. `visit_place` also checks that we - // do not try to access statics from constants or try to mutate statics - self.visit_place( - dest, - PlaceContext::MutatingUse(MutatingUseContext::Store), - location - ); - return; - } + let mut dest = dest; + let index = loop { + match dest { + // We treat all locals equal in constants + Place::Local(index) => break *index, + // projections are transparent for assignments + // we qualify the entire destination at once, even if just a field would have + // stricter qualification + Place::Projection(proj) => { + // Catch more errors in the destination. `visit_place` also checks various + // projection rules like union field access and raw pointer deref + self.visit_place( + dest, + PlaceContext::MutatingUse(MutatingUseContext::Store), + location + ); + dest = &proj.base; + }, + Place::Promoted(..) => bug!("promoteds don't exist yet during promotion"), + Place::Static(..) => { + // Catch more errors in the destination. `visit_place` also checks that we + // do not try to access statics from constants or try to mutate statics + self.visit_place( + dest, + PlaceContext::MutatingUse(MutatingUseContext::Store), + location + ); + return; } - }; - debug!("store to var {:?}", index); - match &mut self.local_qualif[index] { - // this is overly restrictive, because even full assignments do not clear the qualif - // While we could special case full assignments, this would be inconsistent with - // aggregates where we overwrite all fields via assignments, which would not get - // that feature. - Some(ref mut qualif) => *qualif = *qualif | self.qualif, - // insert new qualification - qualif @ None => *qualif = Some(self.qualif), - } - return; - } - - match *dest { - Place::Local(index) if self.mir.local_kind(index) == LocalKind::Temp || - self.mir.local_kind(index) == LocalKind::ReturnPointer => { - debug!("store to {:?} (temp or return pointer)", index); - store(&mut self.local_qualif[index]) - } - - Place::Projection(box Projection { - base: Place::Local(index), - elem: ProjectionElem::Deref - }) if self.mir.local_kind(index) == LocalKind::Temp - && self.mir.local_decls[index].ty.is_box() - && self.local_qualif[index].map_or(false, |qualif| { - qualif.contains(Qualif::NOT_CONST) - }) => { - // Part of `box expr`, we should've errored - // already for the Box allocation Rvalue. - } - - // This must be an explicit assignment. - _ => { - // Catch more errors in the destination. - self.visit_place( - dest, - PlaceContext::MutatingUse(MutatingUseContext::Store), - location - ); - self.statement_like(); } + }; + debug!("store to var {:?}", index); + match &mut self.local_qualif[index] { + // this is overly restrictive, because even full assignments do not clear the qualif + // While we could special case full assignments, this would be inconsistent with + // aggregates where we overwrite all fields via assignments, which would not get + // that feature. + Some(ref mut qualif) => *qualif = *qualif | self.qualif, + // insert new qualification + qualif @ None => *qualif = Some(self.qualif), } } @@ -347,45 +291,6 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> { TerminatorKind::FalseUnwind { .. } => None, TerminatorKind::Return => { - if !self.tcx.features().const_let { - // Check for unused values. This usually means - // there are extra statements in the AST. - for temp in mir.temps_iter() { - if self.local_qualif[temp].is_none() { - continue; - } - - let state = self.temp_promotion_state[temp]; - if let TempState::Defined { location, uses: 0 } = state { - let data = &mir[location.block]; - let stmt_idx = location.statement_index; - - // Get the span for the initialization. - let source_info = if stmt_idx < data.statements.len() { - data.statements[stmt_idx].source_info - } else { - data.terminator().source_info - }; - self.span = source_info.span; - - // Treat this as a statement in the AST. - self.statement_like(); - } - } - - // Make sure there are no extra unassigned variables. - self.qualif = Qualif::NOT_CONST; - for index in mir.vars_iter() { - if !self.const_fn_arg_vars.contains(index) { - debug!("unassigned variable {:?}", index); - self.assign(&Place::Local(index), Location { - block: bb, - statement_index: usize::MAX, - }); - } - } - } - break; } }; @@ -454,12 +359,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { LocalKind::ReturnPointer => { self.not_const(); } - LocalKind::Var if !self.tcx.features().const_let => { - if self.mode != Mode::Fn { - emit_feature_err(&self.tcx.sess.parse_sess, "const_let", - self.span, GateIssue::Language, - &format!("let bindings in {}s are unstable",self.mode)); - } + LocalKind::Var if self.mode == Mode::Fn => { self.add(Qualif::NOT_CONST); } LocalKind::Var | @@ -569,6 +469,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } } + ProjectionElem::ConstantIndex {..} | + ProjectionElem::Subslice {..} | ProjectionElem::Field(..) | ProjectionElem::Index(_) => { let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx); @@ -598,8 +500,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { this.qualif.restrict(ty, this.tcx, this.param_env); } - ProjectionElem::ConstantIndex {..} | - ProjectionElem::Subslice {..} | ProjectionElem::Downcast(..) => { this.not_const() } @@ -1168,46 +1068,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { debug!("visit_assign: dest={:?} rvalue={:?} location={:?}", dest, rvalue, location); self.visit_rvalue(rvalue, location); - // Check the allowed const fn argument forms. - if let (Mode::ConstFn, &Place::Local(index)) = (self.mode, dest) { - if self.mir.local_kind(index) == LocalKind::Var && - self.const_fn_arg_vars.insert(index) && - !self.tcx.features().const_let { - // Direct use of an argument is permitted. - match *rvalue { - Rvalue::Use(Operand::Copy(Place::Local(local))) | - Rvalue::Use(Operand::Move(Place::Local(local))) => { - if self.mir.local_kind(local) == LocalKind::Arg { - return; - } - } - _ => {} - } - // Avoid a generic error for other uses of arguments. - if self.qualif.contains(Qualif::FN_ARGUMENT) { - let decl = &self.mir.local_decls[index]; - let mut err = feature_err( - &self.tcx.sess.parse_sess, - "const_let", - decl.source_info.span, - GateIssue::Language, - "arguments of constant functions can only be immutable by-value bindings" - ); - if self.tcx.sess.teach(&err.get_code().unwrap()) { - err.note("Constant functions are not allowed to mutate anything. Thus, \ - binding to an argument with a mutable pattern is not allowed."); - err.note("Remove any mutable bindings from the argument list to fix this \ - error. In case you need to mutate the argument, try lazily \ - initializing a global variable instead of using a const fn, or \ - refactoring the code to a functional style to avoid mutation if \ - possible."); - } - err.emit(); - return; - } - } - } - self.assign(dest, location); } diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index c1c5b18915aed..41a042ebcb643 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -65,12 +65,6 @@ pub fn is_min_const_fn( } } - for local in mir.vars_iter() { - return Err(( - mir.local_decls[local].source_info.span, - "local variables in const fn are unstable".into(), - )); - } for local in &mir.local_decls { check_ty(tcx, local.ty, local.source_info.span)?; } @@ -147,7 +141,7 @@ fn check_rvalue( check_operand(tcx, mir, operand, span) } Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) => { - check_place(tcx, mir, place, span, PlaceMode::Read) + check_place(tcx, mir, place, span) } Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { use rustc::ty::cast::CastTy; @@ -213,11 +207,6 @@ fn check_rvalue( } } -enum PlaceMode { - Assign, - Read, -} - fn check_statement( tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &'a Mir<'tcx>, @@ -226,11 +215,11 @@ fn check_statement( let span = statement.source_info.span; match &statement.kind { StatementKind::Assign(place, rval) => { - check_place(tcx, mir, place, span, PlaceMode::Assign)?; + check_place(tcx, mir, place, span)?; check_rvalue(tcx, mir, rval, span) } - StatementKind::FakeRead(_, place) => check_place(tcx, mir, place, span, PlaceMode::Read), + StatementKind::FakeRead(_, place) => check_place(tcx, mir, place, span), // just an assignment StatementKind::SetDiscriminant { .. } => Ok(()), @@ -256,7 +245,7 @@ fn check_operand( ) -> McfResult { match operand { Operand::Move(place) | Operand::Copy(place) => { - check_place(tcx, mir, place, span, PlaceMode::Read) + check_place(tcx, mir, place, span) } Operand::Constant(_) => Ok(()), } @@ -267,29 +256,17 @@ fn check_place( mir: &'a Mir<'tcx>, place: &Place<'tcx>, span: Span, - mode: PlaceMode, ) -> McfResult { match place { - Place::Local(l) => match mode { - PlaceMode::Assign => match mir.local_kind(*l) { - LocalKind::Temp | LocalKind::ReturnPointer => Ok(()), - LocalKind::Arg | LocalKind::Var => { - Err((span, "assignments in const fn are unstable".into())) - } - }, - PlaceMode::Read => Ok(()), - }, + Place::Local(_) => Ok(()), // promoteds are always fine, they are essentially constants Place::Promoted(_) => Ok(()), Place::Static(_) => Err((span, "cannot access `static` items in const fn".into())), Place::Projection(proj) => { match proj.elem { + | ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } | ProjectionElem::Deref | ProjectionElem::Field(..) | ProjectionElem::Index(_) => { - check_place(tcx, mir, &proj.base, span, mode) - } - // slice patterns are unstable - | ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => { - return Err((span, "slice patterns in const fn are unstable".into())) + check_place(tcx, mir, &proj.base, span) } | ProjectionElem::Downcast(..) => { Err((span, "`match` or `if let` in `const fn` is unstable".into())) @@ -311,10 +288,10 @@ fn check_terminator( | TerminatorKind::Resume => Ok(()), TerminatorKind::Drop { location, .. } => { - check_place(tcx, mir, location, span, PlaceMode::Read) + check_place(tcx, mir, location, span) } TerminatorKind::DropAndReplace { location, value, .. } => { - check_place(tcx, mir, location, span, PlaceMode::Read)?; + check_place(tcx, mir, location, span)?; check_operand(tcx, mir, value, span) }, @@ -342,15 +319,11 @@ fn check_terminator( // some intrinsics are waved through if called inside the // standard library. Users never need to call them directly match tcx.fn_sig(def_id).abi() { - abi::Abi::RustIntrinsic => match &tcx.item_name(def_id).as_str()[..] { - | "size_of" - | "min_align_of" - | "needs_drop" - => {}, - _ => return Err(( + abi::Abi::RustIntrinsic => if !is_intrinsic_whitelisted(tcx, def_id) { + return Err(( span, "can only call a curated list of intrinsics in `min_const_fn`".into(), - )), + )) }, abi::Abi::Rust if tcx.is_min_const_fn(def_id) => {}, abi::Abi::Rust => return Err(( @@ -390,3 +363,30 @@ fn check_terminator( }, } } + +/// Returns true if the `def_id` refers to an intrisic which we've whitelisted +/// for being called from stable `const fn`s (`min_const_fn`). +/// +/// Adding more intrinsics requires sign-off from @rust-lang/lang. +fn is_intrinsic_whitelisted(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool { + match &tcx.item_name(def_id).as_str()[..] { + | "size_of" + | "min_align_of" + | "needs_drop" + // Arithmetic: + | "overflowing_add" // ~> .wrapping_add + | "overflowing_sub" // ~> .wrapping_sub + | "overflowing_mul" // ~> .wrapping_mul + | "unchecked_shl" // ~> .wrapping_shl + | "unchecked_shr" // ~> .wrapping_shr + | "rotate_left" // ~> .rotate_left + | "rotate_right" // ~> .rotate_right + | "ctpop" // ~> .count_ones + | "ctlz" // ~> .leading_zeros + | "cttz" // ~> .trailing_zeros + | "bswap" // ~> .swap_bytes + | "bitreverse" // ~> .reverse_bits + => true, + _ => false, + } +} diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 821c30b4fa709..04d18ff7aa372 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -66,6 +66,18 @@ fn equate_intrinsic_type<'a, 'tcx>( require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(def_id)), fty); } +/// Returns whether the given intrinsic is unsafe to call or not. +pub fn intrisic_operation_unsafety(intrinsic: &str) -> hir::Unsafety { + match intrinsic { + "size_of" | "min_align_of" | "needs_drop" | + "overflowing_add" | "overflowing_sub" | "overflowing_mul" | + "rotate_left" | "rotate_right" | + "ctpop" | "ctlz" | "cttz" | "bswap" | "bitreverse" + => hir::Unsafety::Normal, + _ => hir::Unsafety::Unsafe, + } +} + /// Remember to add all intrinsics here, in librustc_codegen_llvm/intrinsic.rs, /// and in libcore/intrinsics.rs pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -117,10 +129,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } else if &name[..] == "abort" || &name[..] == "unreachable" { (0, Vec::new(), tcx.types.never, hir::Unsafety::Unsafe) } else { - let unsafety = match &name[..] { - "size_of" | "min_align_of" | "needs_drop" => hir::Unsafety::Normal, - _ => hir::Unsafety::Unsafe, - }; + let unsafety = intrisic_operation_unsafety(&name[..]); let (n_tps, inputs, output) = match &name[..] { "breakpoint" => (0, Vec::new(), tcx.mk_unit()), "size_of" | diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1a5d164873d32..870c6dd8bc1f6 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -80,7 +80,7 @@ mod closure; mod callee; mod compare_method; mod generator_interior; -mod intrinsic; +pub mod intrinsic; mod op; use astconv::{AstConv, PathSeg}; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e0e173901ef38..2ac52bcda76f7 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -16,6 +16,7 @@ use astconv::{AstConv, Bounds}; use constrained_type_params as ctp; +use check::intrinsic::intrisic_operation_unsafety; use lint; use middle::lang_items::SizedTraitLangItem; use middle::resolve_lifetime as rl; @@ -2080,10 +2081,7 @@ fn compute_sig_of_foreign_fn_decl<'a, 'tcx>( abi: abi::Abi, ) -> ty::PolyFnSig<'tcx> { let unsafety = if abi == abi::Abi::RustIntrinsic { - match &*tcx.item_name(def_id).as_str() { - "size_of" | "min_align_of" | "needs_drop" => hir::Unsafety::Normal, - _ => hir::Unsafety::Unsafe, - } + intrisic_operation_unsafety(&*tcx.item_name(def_id).as_str()) } else { hir::Unsafety::Unsafe }; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ccfce672e5f9e..701565191b960 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -242,8 +242,8 @@ #![feature(char_error_internals)] #![feature(compiler_builtins_lib)] #![feature(concat_idents)] -#![feature(const_int_ops)] -#![feature(const_ip)] +#![cfg_attr(stage0, feature(const_int_ops))] +#![cfg_attr(stage0, feature(const_ip))] #![feature(const_raw_ptr_deref)] #![feature(const_cstr_unchecked)] #![feature(core_intrinsics)] diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 52a29f4885f56..f98113e0896f7 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -328,7 +328,7 @@ impl Ipv4Addr { /// let addr = Ipv4Addr::new(127, 0, 0, 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_ip")] + #[cfg_attr(stage0, rustc_const_unstable(feature = "const_ip"))] pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { Ipv4Addr { inner: c::in_addr { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index cddec3eb23a5a..a7b391f2d1a4c 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -193,9 +193,6 @@ declare_features! ( // Allows the definition of `const` functions with some advanced features. (active, const_fn, "1.2.0", Some(24111), None), - // Allows let bindings and destructuring in `const` functions and constants. - (active, const_let, "1.22.1", Some(48821), None), - // Allows accessing fields of unions inside `const` functions. (active, const_fn_union, "1.27.0", Some(51909), None), @@ -688,6 +685,10 @@ declare_features! ( (accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None), // `#[cfg_attr(predicate, multiple, attributes, here)]` (accepted, cfg_attr_multi, "1.33.0", Some(54881), None), + // Allows let bindings, assignments and destructuring in `const` functions and constants. + // As long as control flow is not implemented in const eval, `&&` and `||` may not be used + // at the same time as let bindings. + (accepted, const_let, "1.33.0", Some(48821), None), ); // If you change this, please modify `src/doc/unstable-book` as well. You must diff --git a/src/test/compile-fail/const-fn-error.rs b/src/test/compile-fail/const-fn-error.rs index 9913138693c94..da6036a04a549 100644 --- a/src/test/compile-fail/const-fn-error.rs +++ b/src/test/compile-fail/const-fn-error.rs @@ -1,4 +1,4 @@ -#![feature(const_fn, const_let)] +#![feature(const_fn)] const X : usize = 2; diff --git a/src/test/run-pass/const-int-conversion.rs b/src/test/run-pass/const-int-conversion.rs index 2b4904cc6c39a..19d65860179b2 100644 --- a/src/test/run-pass/const-int-conversion.rs +++ b/src/test/run-pass/const-int-conversion.rs @@ -1,4 +1,4 @@ -#![feature(const_int_conversion, const_int_ops, reverse_bits)] +#![feature(const_int_conversion, reverse_bits)] const REVERSE: u32 = 0x12345678_u32.reverse_bits(); const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]); @@ -21,4 +21,3 @@ fn main() { assert_eq!(TO_LE_BYTES, ident([0x78, 0x56, 0x34, 0x12])); assert_eq!(TO_NE_BYTES, ident([0x80, 0, 0, 0])); } - diff --git a/src/test/run-pass/const-int-rotate.rs b/src/test/run-pass/const-int-rotate.rs index 68c77f27a3193..c014e97ef19b8 100644 --- a/src/test/run-pass/const-int-rotate.rs +++ b/src/test/run-pass/const-int-rotate.rs @@ -1,5 +1,3 @@ -#![feature(const_int_rotate)] - const LEFT: u32 = 0x10000b3u32.rotate_left(8); const RIGHT: u32 = 0xb301u32.rotate_right(8); diff --git a/src/test/run-pass/const-int-sign.rs b/src/test/run-pass/const-int-sign.rs index ae55c1a9b0e39..9d656a0203069 100644 --- a/src/test/run-pass/const-int-sign.rs +++ b/src/test/run-pass/const-int-sign.rs @@ -1,5 +1,3 @@ -#![feature(const_int_sign)] - const NEGATIVE_A: bool = (-10i32).is_negative(); const NEGATIVE_B: bool = 10i32.is_negative(); const POSITIVE_A: bool= (-10i32).is_positive(); diff --git a/src/test/run-pass/const-int-wrapping.rs b/src/test/run-pass/const-int-wrapping.rs index 504a654c0db65..5ab712015dfc3 100644 --- a/src/test/run-pass/const-int-wrapping.rs +++ b/src/test/run-pass/const-int-wrapping.rs @@ -1,5 +1,3 @@ -#![feature(const_int_wrapping)] - const ADD_A: u32 = 200u32.wrapping_add(55); const ADD_B: u32 = 200u32.wrapping_add(u32::max_value()); diff --git a/src/test/run-pass/consts/const-endianess.rs b/src/test/run-pass/consts/const-endianess.rs index dfc6678ba289d..cbe6d864c9c3a 100644 --- a/src/test/run-pass/consts/const-endianess.rs +++ b/src/test/run-pass/consts/const-endianess.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_int_ops)] #![feature(test)] extern crate test; @@ -8,7 +7,6 @@ use test::black_box as b; const BE_U32: u32 = 55u32.to_be(); const LE_U32: u32 = 55u32.to_le(); - fn main() { assert_eq!(BE_U32, b(55u32).to_be()); assert_eq!(LE_U32, b(55u32).to_le()); diff --git a/src/test/run-pass/ctfe/bswap-const.rs b/src/test/run-pass/ctfe/bswap-const.rs index 90e97c8edbdd5..3145c21acc988 100644 --- a/src/test/run-pass/ctfe/bswap-const.rs +++ b/src/test/run-pass/ctfe/bswap-const.rs @@ -4,9 +4,9 @@ use std::intrinsics; -const SWAPPED_U8: u8 = unsafe { intrinsics::bswap(0x12_u8) }; -const SWAPPED_U16: u16 = unsafe { intrinsics::bswap(0x12_34_u16) }; -const SWAPPED_I32: i32 = unsafe { intrinsics::bswap(0x12_34_56_78_i32) }; +const SWAPPED_U8: u8 = intrinsics::bswap(0x12_u8); +const SWAPPED_U16: u16 = intrinsics::bswap(0x12_34_u16); +const SWAPPED_I32: i32 = intrinsics::bswap(0x12_34_56_78_i32); fn main() { assert_eq!(SWAPPED_U8, 0x12); diff --git a/src/test/run-pass/ctfe/const-block-non-item-statement-3.rs b/src/test/run-pass/ctfe/const-block-non-item-statement-3.rs index 90295414d3efc..10a4c31f24ed4 100644 --- a/src/test/run-pass/ctfe/const-block-non-item-statement-3.rs +++ b/src/test/run-pass/ctfe/const-block-non-item-statement-3.rs @@ -1,8 +1,8 @@ // run-pass #![allow(dead_code)] -#![feature(const_let)] - type Array = [u32; { let x = 2; 5 }]; -pub fn main() {} +pub fn main() { + let _: Array = [0; 5]; +} diff --git a/src/test/run-pass/ctfe/const-block-non-item-statement.rs b/src/test/run-pass/ctfe/const-block-non-item-statement.rs index 21ce08ab69c73..a1b9b586ad038 100644 --- a/src/test/run-pass/ctfe/const-block-non-item-statement.rs +++ b/src/test/run-pass/ctfe/const-block-non-item-statement.rs @@ -1,10 +1,11 @@ // run-pass #![allow(dead_code)] -#![feature(const_let)] - +#[repr(u8)] enum Foo { Bar = { let x = 1; 3 } } -pub fn main() {} +pub fn main() { + assert_eq!(3, Foo::Bar as u8); +} diff --git a/src/test/run-pass/ctfe/issue-37550.rs b/src/test/run-pass/ctfe/issue-37550.rs index 732c34dff5a80..04865830df2eb 100644 --- a/src/test/run-pass/ctfe/issue-37550.rs +++ b/src/test/run-pass/ctfe/issue-37550.rs @@ -2,7 +2,7 @@ #![allow(dead_code)] #![allow(unused_variables)] -#![feature(const_fn, const_let)] +#![feature(const_fn)] const fn x() { let t = true; diff --git a/src/test/run-pass/ctfe/locals-in-const-fn.rs b/src/test/run-pass/ctfe/locals-in-const-fn.rs index e527e1e88c8da..95d50171a847b 100644 --- a/src/test/run-pass/ctfe/locals-in-const-fn.rs +++ b/src/test/run-pass/ctfe/locals-in-const-fn.rs @@ -2,8 +2,6 @@ // https://github.com/rust-lang/rust/issues/48821 -#![feature(const_fn, const_let)] - const fn foo(i: usize) -> usize { let x = i; x diff --git a/src/test/run-pass/intrinsics/intrinsics-integer.rs b/src/test/run-pass/intrinsics/intrinsics-integer.rs index 66e07f8683a87..0154f04995029 100644 --- a/src/test/run-pass/intrinsics/intrinsics-integer.rs +++ b/src/test/run-pass/intrinsics/intrinsics-integer.rs @@ -16,63 +16,63 @@ mod rusti { } pub fn main() { - unsafe { - use rusti::*; - - assert_eq!(ctpop(0u8), 0); assert_eq!(ctpop(0i8), 0); - assert_eq!(ctpop(0u16), 0); assert_eq!(ctpop(0i16), 0); - assert_eq!(ctpop(0u32), 0); assert_eq!(ctpop(0i32), 0); - assert_eq!(ctpop(0u64), 0); assert_eq!(ctpop(0i64), 0); - assert_eq!(ctpop(0u128), 0); assert_eq!(ctpop(0i128), 0); - - assert_eq!(ctpop(1u8), 1); assert_eq!(ctpop(1i8), 1); - assert_eq!(ctpop(1u16), 1); assert_eq!(ctpop(1i16), 1); - assert_eq!(ctpop(1u32), 1); assert_eq!(ctpop(1i32), 1); - assert_eq!(ctpop(1u64), 1); assert_eq!(ctpop(1i64), 1); - assert_eq!(ctpop(1u128), 1); assert_eq!(ctpop(1i128), 1); - - assert_eq!(ctpop(10u8), 2); assert_eq!(ctpop(10i8), 2); - assert_eq!(ctpop(10u16), 2); assert_eq!(ctpop(10i16), 2); - assert_eq!(ctpop(10u32), 2); assert_eq!(ctpop(10i32), 2); - assert_eq!(ctpop(10u64), 2); assert_eq!(ctpop(10i64), 2); - assert_eq!(ctpop(10u128), 2); assert_eq!(ctpop(10i128), 2); - - assert_eq!(ctpop(100u8), 3); assert_eq!(ctpop(100i8), 3); - assert_eq!(ctpop(100u16), 3); assert_eq!(ctpop(100i16), 3); - assert_eq!(ctpop(100u32), 3); assert_eq!(ctpop(100i32), 3); - assert_eq!(ctpop(100u64), 3); assert_eq!(ctpop(100i64), 3); - assert_eq!(ctpop(100u128), 3); assert_eq!(ctpop(100i128), 3); - - assert_eq!(ctpop(-1i8 as u8), 8); assert_eq!(ctpop(-1i8), 8); - assert_eq!(ctpop(-1i16 as u16), 16); assert_eq!(ctpop(-1i16), 16); - assert_eq!(ctpop(-1i32 as u32), 32); assert_eq!(ctpop(-1i32), 32); - assert_eq!(ctpop(-1i64 as u64), 64); assert_eq!(ctpop(-1i64), 64); - assert_eq!(ctpop(-1i128 as u128), 128); assert_eq!(ctpop(-1i128), 128); - - assert_eq!(ctlz(0u8), 8); assert_eq!(ctlz(0i8), 8); - assert_eq!(ctlz(0u16), 16); assert_eq!(ctlz(0i16), 16); - assert_eq!(ctlz(0u32), 32); assert_eq!(ctlz(0i32), 32); - assert_eq!(ctlz(0u64), 64); assert_eq!(ctlz(0i64), 64); - assert_eq!(ctlz(0u128), 128); assert_eq!(ctlz(0i128), 128); - - assert_eq!(ctlz(1u8), 7); assert_eq!(ctlz(1i8), 7); - assert_eq!(ctlz(1u16), 15); assert_eq!(ctlz(1i16), 15); - assert_eq!(ctlz(1u32), 31); assert_eq!(ctlz(1i32), 31); - assert_eq!(ctlz(1u64), 63); assert_eq!(ctlz(1i64), 63); - assert_eq!(ctlz(1u128), 127); assert_eq!(ctlz(1i128), 127); - - assert_eq!(ctlz(10u8), 4); assert_eq!(ctlz(10i8), 4); - assert_eq!(ctlz(10u16), 12); assert_eq!(ctlz(10i16), 12); - assert_eq!(ctlz(10u32), 28); assert_eq!(ctlz(10i32), 28); - assert_eq!(ctlz(10u64), 60); assert_eq!(ctlz(10i64), 60); - assert_eq!(ctlz(10u128), 124); assert_eq!(ctlz(10i128), 124); - - assert_eq!(ctlz(100u8), 1); assert_eq!(ctlz(100i8), 1); - assert_eq!(ctlz(100u16), 9); assert_eq!(ctlz(100i16), 9); - assert_eq!(ctlz(100u32), 25); assert_eq!(ctlz(100i32), 25); - assert_eq!(ctlz(100u64), 57); assert_eq!(ctlz(100i64), 57); - assert_eq!(ctlz(100u128), 121); assert_eq!(ctlz(100i128), 121); + use rusti::*; + + assert_eq!(ctpop(0u8), 0); assert_eq!(ctpop(0i8), 0); + assert_eq!(ctpop(0u16), 0); assert_eq!(ctpop(0i16), 0); + assert_eq!(ctpop(0u32), 0); assert_eq!(ctpop(0i32), 0); + assert_eq!(ctpop(0u64), 0); assert_eq!(ctpop(0i64), 0); + assert_eq!(ctpop(0u128), 0); assert_eq!(ctpop(0i128), 0); + + assert_eq!(ctpop(1u8), 1); assert_eq!(ctpop(1i8), 1); + assert_eq!(ctpop(1u16), 1); assert_eq!(ctpop(1i16), 1); + assert_eq!(ctpop(1u32), 1); assert_eq!(ctpop(1i32), 1); + assert_eq!(ctpop(1u64), 1); assert_eq!(ctpop(1i64), 1); + assert_eq!(ctpop(1u128), 1); assert_eq!(ctpop(1i128), 1); + + assert_eq!(ctpop(10u8), 2); assert_eq!(ctpop(10i8), 2); + assert_eq!(ctpop(10u16), 2); assert_eq!(ctpop(10i16), 2); + assert_eq!(ctpop(10u32), 2); assert_eq!(ctpop(10i32), 2); + assert_eq!(ctpop(10u64), 2); assert_eq!(ctpop(10i64), 2); + assert_eq!(ctpop(10u128), 2); assert_eq!(ctpop(10i128), 2); + + assert_eq!(ctpop(100u8), 3); assert_eq!(ctpop(100i8), 3); + assert_eq!(ctpop(100u16), 3); assert_eq!(ctpop(100i16), 3); + assert_eq!(ctpop(100u32), 3); assert_eq!(ctpop(100i32), 3); + assert_eq!(ctpop(100u64), 3); assert_eq!(ctpop(100i64), 3); + assert_eq!(ctpop(100u128), 3); assert_eq!(ctpop(100i128), 3); + + assert_eq!(ctpop(-1i8 as u8), 8); assert_eq!(ctpop(-1i8), 8); + assert_eq!(ctpop(-1i16 as u16), 16); assert_eq!(ctpop(-1i16), 16); + assert_eq!(ctpop(-1i32 as u32), 32); assert_eq!(ctpop(-1i32), 32); + assert_eq!(ctpop(-1i64 as u64), 64); assert_eq!(ctpop(-1i64), 64); + assert_eq!(ctpop(-1i128 as u128), 128); assert_eq!(ctpop(-1i128), 128); + + assert_eq!(ctlz(0u8), 8); assert_eq!(ctlz(0i8), 8); + assert_eq!(ctlz(0u16), 16); assert_eq!(ctlz(0i16), 16); + assert_eq!(ctlz(0u32), 32); assert_eq!(ctlz(0i32), 32); + assert_eq!(ctlz(0u64), 64); assert_eq!(ctlz(0i64), 64); + assert_eq!(ctlz(0u128), 128); assert_eq!(ctlz(0i128), 128); + + assert_eq!(ctlz(1u8), 7); assert_eq!(ctlz(1i8), 7); + assert_eq!(ctlz(1u16), 15); assert_eq!(ctlz(1i16), 15); + assert_eq!(ctlz(1u32), 31); assert_eq!(ctlz(1i32), 31); + assert_eq!(ctlz(1u64), 63); assert_eq!(ctlz(1i64), 63); + assert_eq!(ctlz(1u128), 127); assert_eq!(ctlz(1i128), 127); + + assert_eq!(ctlz(10u8), 4); assert_eq!(ctlz(10i8), 4); + assert_eq!(ctlz(10u16), 12); assert_eq!(ctlz(10i16), 12); + assert_eq!(ctlz(10u32), 28); assert_eq!(ctlz(10i32), 28); + assert_eq!(ctlz(10u64), 60); assert_eq!(ctlz(10i64), 60); + assert_eq!(ctlz(10u128), 124); assert_eq!(ctlz(10i128), 124); + + assert_eq!(ctlz(100u8), 1); assert_eq!(ctlz(100i8), 1); + assert_eq!(ctlz(100u16), 9); assert_eq!(ctlz(100i16), 9); + assert_eq!(ctlz(100u32), 25); assert_eq!(ctlz(100i32), 25); + assert_eq!(ctlz(100u64), 57); assert_eq!(ctlz(100i64), 57); + assert_eq!(ctlz(100u128), 121); assert_eq!(ctlz(100i128), 121); + unsafe { assert_eq!(ctlz_nonzero(1u8), 7); assert_eq!(ctlz_nonzero(1i8), 7); assert_eq!(ctlz_nonzero(1u16), 15); assert_eq!(ctlz_nonzero(1i16), 15); assert_eq!(ctlz_nonzero(1u32), 31); assert_eq!(ctlz_nonzero(1i32), 31); @@ -90,37 +90,39 @@ pub fn main() { assert_eq!(ctlz_nonzero(100u32), 25); assert_eq!(ctlz_nonzero(100i32), 25); assert_eq!(ctlz_nonzero(100u64), 57); assert_eq!(ctlz_nonzero(100i64), 57); assert_eq!(ctlz_nonzero(100u128), 121); assert_eq!(ctlz_nonzero(100i128), 121); + } - assert_eq!(cttz(-1i8 as u8), 0); assert_eq!(cttz(-1i8), 0); - assert_eq!(cttz(-1i16 as u16), 0); assert_eq!(cttz(-1i16), 0); - assert_eq!(cttz(-1i32 as u32), 0); assert_eq!(cttz(-1i32), 0); - assert_eq!(cttz(-1i64 as u64), 0); assert_eq!(cttz(-1i64), 0); - assert_eq!(cttz(-1i128 as u128), 0); assert_eq!(cttz(-1i128), 0); - - assert_eq!(cttz(0u8), 8); assert_eq!(cttz(0i8), 8); - assert_eq!(cttz(0u16), 16); assert_eq!(cttz(0i16), 16); - assert_eq!(cttz(0u32), 32); assert_eq!(cttz(0i32), 32); - assert_eq!(cttz(0u64), 64); assert_eq!(cttz(0i64), 64); - assert_eq!(cttz(0u128), 128); assert_eq!(cttz(0i128), 128); - - assert_eq!(cttz(1u8), 0); assert_eq!(cttz(1i8), 0); - assert_eq!(cttz(1u16), 0); assert_eq!(cttz(1i16), 0); - assert_eq!(cttz(1u32), 0); assert_eq!(cttz(1i32), 0); - assert_eq!(cttz(1u64), 0); assert_eq!(cttz(1i64), 0); - assert_eq!(cttz(1u128), 0); assert_eq!(cttz(1i128), 0); - - assert_eq!(cttz(10u8), 1); assert_eq!(cttz(10i8), 1); - assert_eq!(cttz(10u16), 1); assert_eq!(cttz(10i16), 1); - assert_eq!(cttz(10u32), 1); assert_eq!(cttz(10i32), 1); - assert_eq!(cttz(10u64), 1); assert_eq!(cttz(10i64), 1); - assert_eq!(cttz(10u128), 1); assert_eq!(cttz(10i128), 1); - - assert_eq!(cttz(100u8), 2); assert_eq!(cttz(100i8), 2); - assert_eq!(cttz(100u16), 2); assert_eq!(cttz(100i16), 2); - assert_eq!(cttz(100u32), 2); assert_eq!(cttz(100i32), 2); - assert_eq!(cttz(100u64), 2); assert_eq!(cttz(100i64), 2); - assert_eq!(cttz(100u128), 2); assert_eq!(cttz(100i128), 2); + assert_eq!(cttz(-1i8 as u8), 0); assert_eq!(cttz(-1i8), 0); + assert_eq!(cttz(-1i16 as u16), 0); assert_eq!(cttz(-1i16), 0); + assert_eq!(cttz(-1i32 as u32), 0); assert_eq!(cttz(-1i32), 0); + assert_eq!(cttz(-1i64 as u64), 0); assert_eq!(cttz(-1i64), 0); + assert_eq!(cttz(-1i128 as u128), 0); assert_eq!(cttz(-1i128), 0); + + assert_eq!(cttz(0u8), 8); assert_eq!(cttz(0i8), 8); + assert_eq!(cttz(0u16), 16); assert_eq!(cttz(0i16), 16); + assert_eq!(cttz(0u32), 32); assert_eq!(cttz(0i32), 32); + assert_eq!(cttz(0u64), 64); assert_eq!(cttz(0i64), 64); + assert_eq!(cttz(0u128), 128); assert_eq!(cttz(0i128), 128); + + assert_eq!(cttz(1u8), 0); assert_eq!(cttz(1i8), 0); + assert_eq!(cttz(1u16), 0); assert_eq!(cttz(1i16), 0); + assert_eq!(cttz(1u32), 0); assert_eq!(cttz(1i32), 0); + assert_eq!(cttz(1u64), 0); assert_eq!(cttz(1i64), 0); + assert_eq!(cttz(1u128), 0); assert_eq!(cttz(1i128), 0); + + assert_eq!(cttz(10u8), 1); assert_eq!(cttz(10i8), 1); + assert_eq!(cttz(10u16), 1); assert_eq!(cttz(10i16), 1); + assert_eq!(cttz(10u32), 1); assert_eq!(cttz(10i32), 1); + assert_eq!(cttz(10u64), 1); assert_eq!(cttz(10i64), 1); + assert_eq!(cttz(10u128), 1); assert_eq!(cttz(10i128), 1); + + assert_eq!(cttz(100u8), 2); assert_eq!(cttz(100i8), 2); + assert_eq!(cttz(100u16), 2); assert_eq!(cttz(100i16), 2); + assert_eq!(cttz(100u32), 2); assert_eq!(cttz(100i32), 2); + assert_eq!(cttz(100u64), 2); assert_eq!(cttz(100i64), 2); + assert_eq!(cttz(100u128), 2); assert_eq!(cttz(100i128), 2); + unsafe { assert_eq!(cttz_nonzero(-1i8 as u8), 0); assert_eq!(cttz_nonzero(-1i8), 0); assert_eq!(cttz_nonzero(-1i16 as u16), 0); assert_eq!(cttz_nonzero(-1i16), 0); assert_eq!(cttz_nonzero(-1i32 as u32), 0); assert_eq!(cttz_nonzero(-1i32), 0); @@ -144,27 +146,27 @@ pub fn main() { assert_eq!(cttz_nonzero(100u32), 2); assert_eq!(cttz_nonzero(100i32), 2); assert_eq!(cttz_nonzero(100u64), 2); assert_eq!(cttz_nonzero(100i64), 2); assert_eq!(cttz_nonzero(100u128), 2); assert_eq!(cttz_nonzero(100i128), 2); - - assert_eq!(bswap(0x0Au8), 0x0A); // no-op - assert_eq!(bswap(0x0Ai8), 0x0A); // no-op - assert_eq!(bswap(0x0A0Bu16), 0x0B0A); - assert_eq!(bswap(0x0A0Bi16), 0x0B0A); - assert_eq!(bswap(0x0ABBCC0Du32), 0x0DCCBB0A); - assert_eq!(bswap(0x0ABBCC0Di32), 0x0DCCBB0A); - assert_eq!(bswap(0x0122334455667708u64), 0x0877665544332201); - assert_eq!(bswap(0x0122334455667708i64), 0x0877665544332201); - assert_eq!(bswap(0x0122334455667708u128), 0x08776655443322010000000000000000); - assert_eq!(bswap(0x0122334455667708i128), 0x08776655443322010000000000000000); - - assert_eq!(bitreverse(0x0Au8), 0x50); - assert_eq!(bitreverse(0x0Ai8), 0x50); - assert_eq!(bitreverse(0x0A0Cu16), 0x3050); - assert_eq!(bitreverse(0x0A0Ci16), 0x3050); - assert_eq!(bitreverse(0x0ABBCC0Eu32), 0x7033DD50); - assert_eq!(bitreverse(0x0ABBCC0Ei32), 0x7033DD50); - assert_eq!(bitreverse(0x0122334455667708u64), 0x10EE66AA22CC4480); - assert_eq!(bitreverse(0x0122334455667708i64), 0x10EE66AA22CC4480); - assert_eq!(bitreverse(0x0122334455667708u128), 0x10EE66AA22CC44800000000000000000); - assert_eq!(bitreverse(0x0122334455667708i128), 0x10EE66AA22CC44800000000000000000); } + + assert_eq!(bswap(0x0Au8), 0x0A); // no-op + assert_eq!(bswap(0x0Ai8), 0x0A); // no-op + assert_eq!(bswap(0x0A0Bu16), 0x0B0A); + assert_eq!(bswap(0x0A0Bi16), 0x0B0A); + assert_eq!(bswap(0x0ABBCC0Du32), 0x0DCCBB0A); + assert_eq!(bswap(0x0ABBCC0Di32), 0x0DCCBB0A); + assert_eq!(bswap(0x0122334455667708u64), 0x0877665544332201); + assert_eq!(bswap(0x0122334455667708i64), 0x0877665544332201); + assert_eq!(bswap(0x0122334455667708u128), 0x08776655443322010000000000000000); + assert_eq!(bswap(0x0122334455667708i128), 0x08776655443322010000000000000000); + + assert_eq!(bitreverse(0x0Au8), 0x50); + assert_eq!(bitreverse(0x0Ai8), 0x50); + assert_eq!(bitreverse(0x0A0Cu16), 0x3050); + assert_eq!(bitreverse(0x0A0Ci16), 0x3050); + assert_eq!(bitreverse(0x0ABBCC0Eu32), 0x7033DD50); + assert_eq!(bitreverse(0x0ABBCC0Ei32), 0x7033DD50); + assert_eq!(bitreverse(0x0122334455667708u64), 0x10EE66AA22CC4480); + assert_eq!(bitreverse(0x0122334455667708i64), 0x10EE66AA22CC4480); + assert_eq!(bitreverse(0x0122334455667708u128), 0x10EE66AA22CC44800000000000000000); + assert_eq!(bitreverse(0x0122334455667708i128), 0x10EE66AA22CC44800000000000000000); } diff --git a/src/test/ui/bad/bad-intrinsic-monomorphization.rs b/src/test/ui/bad/bad-intrinsic-monomorphization.rs index b56e1ea039cf1..a29723f34b432 100644 --- a/src/test/ui/bad/bad-intrinsic-monomorphization.rs +++ b/src/test/ui/bad/bad-intrinsic-monomorphization.rs @@ -14,7 +14,7 @@ use std::intrinsics; #[derive(Copy, Clone)] pub struct Foo(i64); -pub unsafe fn test_cttz(v: Foo) -> Foo { +pub fn test_cttz(v: Foo) -> Foo { intrinsics::cttz(v) //~^ ERROR `cttz` intrinsic: expected basic integer type, found `Foo` } diff --git a/src/test/ui/check-static-values-constraints.rs b/src/test/ui/check-static-values-constraints.rs index eb0fc39e1bf15..acfb3b5e44bab 100644 --- a/src/test/ui/check-static-values-constraints.rs +++ b/src/test/ui/check-static-values-constraints.rs @@ -78,6 +78,7 @@ struct MyOwned; static STATIC11: Box = box MyOwned; //~^ ERROR allocations are not allowed in statics +//~| ERROR static contains unimplemented expression type static mut STATIC12: UnsafeStruct = UnsafeStruct; @@ -92,12 +93,16 @@ static mut STATIC14: SafeStruct = SafeStruct { static STATIC15: &'static [Box] = &[ box MyOwned, //~ ERROR allocations are not allowed in statics + //~| ERROR contains unimplemented expression box MyOwned, //~ ERROR allocations are not allowed in statics + //~| ERROR contains unimplemented expression ]; static STATIC16: (&'static Box, &'static Box) = ( &box MyOwned, //~ ERROR allocations are not allowed in statics + //~| ERROR contains unimplemented expression &box MyOwned, //~ ERROR allocations are not allowed in statics + //~| ERROR contains unimplemented expression ); static mut STATIC17: SafeEnum = SafeEnum::Variant1; @@ -105,9 +110,11 @@ static mut STATIC17: SafeEnum = SafeEnum::Variant1; static STATIC19: Box = box 3; //~^ ERROR allocations are not allowed in statics + //~| ERROR contains unimplemented expression pub fn main() { let y = { static x: Box = box 3; x }; //~^ ERROR allocations are not allowed in statics - //~^^ ERROR cannot move out of static item + //~| ERROR cannot move out of static item + //~| ERROR contains unimplemented expression } diff --git a/src/test/ui/check-static-values-constraints.stderr b/src/test/ui/check-static-values-constraints.stderr index 450a9ba0c0d11..5b1f265c34aef 100644 --- a/src/test/ui/check-static-values-constraints.stderr +++ b/src/test/ui/check-static-values-constraints.stderr @@ -13,55 +13,97 @@ error[E0010]: allocations are not allowed in statics LL | static STATIC11: Box = box MyOwned; | ^^^^^^^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:79:37 + | +LL | static STATIC11: Box = box MyOwned; + | ^^^^^^^ + error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/check-static-values-constraints.rs:89:32 + --> $DIR/check-static-values-constraints.rs:90:32 | LL | field2: SafeEnum::Variant4("str".to_string()) | ^^^^^^^^^^^^^^^^^ error[E0010]: allocations are not allowed in statics - --> $DIR/check-static-values-constraints.rs:94:5 + --> $DIR/check-static-values-constraints.rs:95:5 | LL | box MyOwned, //~ ERROR allocations are not allowed in statics | ^^^^^^^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:95:9 + | +LL | box MyOwned, //~ ERROR allocations are not allowed in statics + | ^^^^^^^ + error[E0010]: allocations are not allowed in statics - --> $DIR/check-static-values-constraints.rs:95:5 + --> $DIR/check-static-values-constraints.rs:97:5 | LL | box MyOwned, //~ ERROR allocations are not allowed in statics | ^^^^^^^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:97:9 + | +LL | box MyOwned, //~ ERROR allocations are not allowed in statics + | ^^^^^^^ + error[E0010]: allocations are not allowed in statics - --> $DIR/check-static-values-constraints.rs:99:6 + --> $DIR/check-static-values-constraints.rs:102:6 | LL | &box MyOwned, //~ ERROR allocations are not allowed in statics | ^^^^^^^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:102:10 + | +LL | &box MyOwned, //~ ERROR allocations are not allowed in statics + | ^^^^^^^ + error[E0010]: allocations are not allowed in statics - --> $DIR/check-static-values-constraints.rs:100:6 + --> $DIR/check-static-values-constraints.rs:104:6 | LL | &box MyOwned, //~ ERROR allocations are not allowed in statics | ^^^^^^^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:104:10 + | +LL | &box MyOwned, //~ ERROR allocations are not allowed in statics + | ^^^^^^^ + error[E0010]: allocations are not allowed in statics - --> $DIR/check-static-values-constraints.rs:106:5 + --> $DIR/check-static-values-constraints.rs:111:5 | LL | box 3; | ^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:111:9 + | +LL | box 3; + | ^ + error[E0507]: cannot move out of static item - --> $DIR/check-static-values-constraints.rs:110:45 + --> $DIR/check-static-values-constraints.rs:116:45 | LL | let y = { static x: Box = box 3; x }; | ^ cannot move out of static item error[E0010]: allocations are not allowed in statics - --> $DIR/check-static-values-constraints.rs:110:38 + --> $DIR/check-static-values-constraints.rs:116:38 | LL | let y = { static x: Box = box 3; x }; | ^^^^^ allocation not allowed in statics -error: aborting due to 10 previous errors +error[E0019]: static contains unimplemented expression type + --> $DIR/check-static-values-constraints.rs:116:42 + | +LL | let y = { static x: Box = box 3; x }; + | ^ + +error: aborting due to 17 previous errors -Some errors occurred: E0010, E0015, E0493, E0507. +Some errors occurred: E0010, E0015, E0019, E0493, E0507. For more information about an error, try `rustc --explain E0010`. diff --git a/src/test/ui/consts/const-block-non-item-statement-2.rs b/src/test/ui/consts/const-block-non-item-statement-2.rs deleted file mode 100644 index 58a6cf6dcfdeb..0000000000000 --- a/src/test/ui/consts/const-block-non-item-statement-2.rs +++ /dev/null @@ -1,18 +0,0 @@ -const A: usize = { 1; 2 }; -//~^ ERROR statements in constants are unstable - -const B: usize = { { } 2 }; -//~^ ERROR statements in constants are unstable - -macro_rules! foo { - () => (()) //~ ERROR statements in constants are unstable -} -const C: usize = { foo!(); 2 }; - -const D: usize = { let x = 4; 2 }; -//~^ ERROR let bindings in constants are unstable -//~| ERROR statements in constants are unstable -//~| ERROR let bindings in constants are unstable -//~| ERROR statements in constants are unstable - -pub fn main() {} diff --git a/src/test/ui/consts/const-block-non-item-statement-2.stderr b/src/test/ui/consts/const-block-non-item-statement-2.stderr deleted file mode 100644 index e0c61a953f50b..0000000000000 --- a/src/test/ui/consts/const-block-non-item-statement-2.stderr +++ /dev/null @@ -1,62 +0,0 @@ -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:1:20 - | -LL | const A: usize = { 1; 2 }; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:4:20 - | -LL | const B: usize = { { } 2 }; - | ^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:8:12 - | -LL | () => (()) //~ ERROR statements in constants are unstable - | ^^ -LL | } -LL | const C: usize = { foo!(); 2 }; - | ------- in this macro invocation - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:12:28 - | -LL | const D: usize = { let x = 4; 2 }; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:12:28 - | -LL | const D: usize = { let x = 4; 2 }; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:12:1 - | -LL | const D: usize = { let x = 4; 2 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-2.rs:12:1 - | -LL | const D: usize = { let x = 4; 2 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 7 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const-block-non-item-statement-3.rs b/src/test/ui/consts/const-block-non-item-statement-3.rs deleted file mode 100644 index 867840925b2d5..0000000000000 --- a/src/test/ui/consts/const-block-non-item-statement-3.rs +++ /dev/null @@ -1,7 +0,0 @@ -type Array = [u32; { let x = 2; 5 }]; -//~^ ERROR let bindings in constants are unstable -//~| ERROR statements in constants are unstable -//~| ERROR let bindings in constants are unstable -//~| ERROR statements in constants are unstable - -pub fn main() {} diff --git a/src/test/ui/consts/const-block-non-item-statement-3.stderr b/src/test/ui/consts/const-block-non-item-statement-3.stderr deleted file mode 100644 index 0a549bc0c8ded..0000000000000 --- a/src/test/ui/consts/const-block-non-item-statement-3.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-3.rs:1:31 - | -LL | type Array = [u32; { let x = 2; 5 }]; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-3.rs:1:31 - | -LL | type Array = [u32; { let x = 2; 5 }]; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-3.rs:1:20 - | -LL | type Array = [u32; { let x = 2; 5 }]; - | ^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement-3.rs:1:20 - | -LL | type Array = [u32; { let x = 2; 5 }]; - | ^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const-block-non-item-statement.rs b/src/test/ui/consts/const-block-non-item-statement.rs index 2db9e2413e5b5..5ecf9a049842d 100644 --- a/src/test/ui/consts/const-block-non-item-statement.rs +++ b/src/test/ui/consts/const-block-non-item-statement.rs @@ -1,9 +1,23 @@ +// compile-pass + enum Foo { Bar = { let x = 1; 3 } - //~^ ERROR let bindings in constants are unstable - //~| ERROR statements in constants are unstable - //~| ERROR let bindings in constants are unstable - //~| ERROR statements in constants are unstable } + +const A: usize = { 1; 2 }; + +const B: usize = { { } 2 }; + +macro_rules! foo { + () => (()) +} + +const C: usize = { foo!(); 2 }; + +const D: usize = { let x = 4; 2 }; + +type Array = [u32; { let x = 2; 5 }]; +type Array2 = [u32; { let mut x = 2; x = 3; x}]; + pub fn main() {} diff --git a/src/test/ui/consts/const-block-non-item-statement.stderr b/src/test/ui/consts/const-block-non-item-statement.stderr deleted file mode 100644 index f0d751e07561c..0000000000000 --- a/src/test/ui/consts/const-block-non-item-statement.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement.rs:2:21 - | -LL | Bar = { let x = 1; 3 } - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement.rs:2:21 - | -LL | Bar = { let x = 1; 3 } - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement.rs:2:11 - | -LL | Bar = { let x = 1; 3 } - | ^^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/const-block-non-item-statement.rs:2:11 - | -LL | Bar = { let x = 1; 3 } - | ^^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.rs b/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.rs index ba8d032367ef8..4d3c714481a29 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.rs +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.rs @@ -2,7 +2,6 @@ // The test should never compile successfully #![feature(const_raw_ptr_deref)] -#![feature(const_let)] use std::cell::UnsafeCell; diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr b/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr index 6ca9d688bd062..be1be6c060071 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr @@ -1,5 +1,5 @@ error[E0019]: static contains unimplemented expression type - --> $DIR/assign-to-static-within-other-static-2.rs:17:5 + --> $DIR/assign-to-static-within-other-static-2.rs:16:5 | LL | *FOO.0.get() = 5; //~ ERROR contains unimplemented expression type | ^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs index 9fe17bfc6a06e..b4c416b1c55f0 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.rs @@ -2,7 +2,6 @@ // The test should never compile successfully #![feature(const_raw_ptr_deref)] -#![feature(const_let)] use std::cell::UnsafeCell; diff --git a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr index 2ab9765305f47..31e49dc10ca60 100644 --- a/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr +++ b/src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr @@ -1,5 +1,5 @@ error: cannot mutate statics in the initializer of another static - --> $DIR/assign-to-static-within-other-static.rs:11:5 + --> $DIR/assign-to-static-within-other-static.rs:10:5 | LL | FOO = 5; //~ ERROR cannot mutate statics in the initializer of another static | ^^^^^^^ diff --git a/src/test/ui/consts/const-eval/const_let.rs b/src/test/ui/consts/const-eval/const_let.rs index 9e6952733bb0b..63321b9120076 100644 --- a/src/test/ui/consts/const-eval/const_let.rs +++ b/src/test/ui/consts/const-eval/const_let.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - fn main() {} struct FakeNeedsDrop; diff --git a/src/test/ui/consts/const-eval/const_let.stderr b/src/test/ui/consts/const-eval/const_let.stderr index e128ca07d8659..00de97e6fb3a0 100644 --- a/src/test/ui/consts/const-eval/const_let.stderr +++ b/src/test/ui/consts/const-eval/const_let.stderr @@ -1,11 +1,11 @@ error[E0019]: constant contains unimplemented expression type - --> $DIR/const_let.rs:15:55 + --> $DIR/const_let.rs:13:55 | LL | const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x }; | ^ error[E0019]: constant contains unimplemented expression type - --> $DIR/const_let.rs:19:35 + --> $DIR/const_let.rs:17:35 | LL | const Z: () = { let mut x = None; x = Some(FakeNeedsDrop); }; | ^ diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs index 0d5530acc9582..a2a45af7cb086 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.rs +++ b/src/test/ui/consts/const-eval/infinite_loop.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - fn main() { // Tests the Collatz conjecture with an incorrect base case (0 instead of 1). // The value of `n` will loop indefinitely (4 - 2 - 1 - 4). diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr index 90d2159d7b551..422c2bab6ea90 100644 --- a/src/test/ui/consts/const-eval/infinite_loop.stderr +++ b/src/test/ui/consts/const-eval/infinite_loop.stderr @@ -1,5 +1,5 @@ error[E0019]: constant contains unimplemented expression type - --> $DIR/infinite_loop.rs:9:9 + --> $DIR/infinite_loop.rs:7:9 | LL | / while n != 0 { //~ ERROR constant contains unimplemented expression type LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; @@ -8,7 +8,7 @@ LL | | } | |_________^ warning: Constant evaluating a complex constant, this might take some time - --> $DIR/infinite_loop.rs:6:18 + --> $DIR/infinite_loop.rs:4:18 | LL | let _ = [(); { | __________________^ @@ -21,7 +21,7 @@ LL | | }]; | |_____^ error[E0080]: evaluation of constant value failed - --> $DIR/infinite_loop.rs:10:20 + --> $DIR/infinite_loop.rs:8:20 | LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; | ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate diff --git a/src/test/ui/consts/const-eval/issue-52475.rs b/src/test/ui/consts/const-eval/issue-52475.rs index 2e3d6fb9e84be..aafdd5fe61782 100644 --- a/src/test/ui/consts/const-eval/issue-52475.rs +++ b/src/test/ui/consts/const-eval/issue-52475.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - fn main() { let _ = [(); { //~^ WARNING Constant evaluating a complex constant, this might take some time diff --git a/src/test/ui/consts/const-eval/issue-52475.stderr b/src/test/ui/consts/const-eval/issue-52475.stderr index 329ea8a21f989..4f1b2ab4c8f46 100644 --- a/src/test/ui/consts/const-eval/issue-52475.stderr +++ b/src/test/ui/consts/const-eval/issue-52475.stderr @@ -1,5 +1,5 @@ error[E0019]: constant contains unimplemented expression type - --> $DIR/issue-52475.rs:8:9 + --> $DIR/issue-52475.rs:6:9 | LL | / while n < 5 { //~ ERROR constant contains unimplemented expression type LL | | n = (n + 1) % 5; //~ ERROR evaluation of constant value failed @@ -8,7 +8,7 @@ LL | | } | |_________^ warning: Constant evaluating a complex constant, this might take some time - --> $DIR/issue-52475.rs:4:18 + --> $DIR/issue-52475.rs:2:18 | LL | let _ = [(); { | __________________^ @@ -21,7 +21,7 @@ LL | | }]; | |_____^ error[E0080]: evaluation of constant value failed - --> $DIR/issue-52475.rs:9:17 + --> $DIR/issue-52475.rs:7:17 | LL | n = (n + 1) % 5; //~ ERROR evaluation of constant value failed | ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs b/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs index 62090f4180d36..32f0062168b3d 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.rs @@ -2,7 +2,6 @@ // The test should never compile successfully #![feature(const_raw_ptr_deref)] -#![feature(const_let)] use std::cell::UnsafeCell; diff --git a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr index 12d6e3be40a99..9fad6868d2038 100644 --- a/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr +++ b/src/test/ui/consts/const-eval/mod-static-with-const-fn.stderr @@ -1,11 +1,11 @@ error[E0019]: static contains unimplemented expression type - --> $DIR/mod-static-with-const-fn.rs:19:5 + --> $DIR/mod-static-with-const-fn.rs:18:5 | LL | *FOO.0.get() = 5; | ^^^^^^^^^^^^^^^^ error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/mod-static-with-const-fn.rs:22:5 + --> $DIR/mod-static-with-const-fn.rs:21:5 | LL | foo(); | ^^^^^ diff --git a/src/test/ui/consts/const-eval/ub-upvars.rs b/src/test/ui/consts/const-eval/ub-upvars.rs index 16df0c1b0cc0e..9b7bca6b72d61 100644 --- a/src/test/ui/consts/const-eval/ub-upvars.rs +++ b/src/test/ui/consts/const-eval/ub-upvars.rs @@ -1,4 +1,4 @@ -#![feature(const_transmute,const_let)] +#![feature(const_transmute)] #![allow(const_err)] // make sure we cannot allow away the errors tested here use std::mem; diff --git a/src/test/ui/consts/const-fn-destructuring-arg.rs b/src/test/ui/consts/const-fn-destructuring-arg.rs index 7f818079a19d1..dcf89f90e31da 100644 --- a/src/test/ui/consts/const-fn-destructuring-arg.rs +++ b/src/test/ui/consts/const-fn-destructuring-arg.rs @@ -1,17 +1,7 @@ -// test that certain things are disallowed in constant functions +// compile-pass -#![feature(const_fn)] - -// no destructuring -const fn i(( - a, - //~^ ERROR arguments of constant functions can only be immutable by-value bindings - b - //~^ ERROR arguments of constant functions can only be immutable by-value bindings - ): (u32, u32)) -> u32 { +const fn i((a, b): (u32, u32)) -> u32 { a + b - //~^ ERROR let bindings in constant functions are unstable - //~| ERROR let bindings in constant functions are unstable } fn main() {} diff --git a/src/test/ui/consts/const-fn-destructuring-arg.stderr b/src/test/ui/consts/const-fn-destructuring-arg.stderr deleted file mode 100644 index db63e8308045a..0000000000000 --- a/src/test/ui/consts/const-fn-destructuring-arg.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0658]: arguments of constant functions can only be immutable by-value bindings (see issue #48821) - --> $DIR/const-fn-destructuring-arg.rs:7:13 - | -LL | a, - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: arguments of constant functions can only be immutable by-value bindings (see issue #48821) - --> $DIR/const-fn-destructuring-arg.rs:9:13 - | -LL | b - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-destructuring-arg.rs:12:5 - | -LL | a + b - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-destructuring-arg.rs:12:9 - | -LL | a + b - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/consts/const-fn-not-safe-for-const.rs b/src/test/ui/consts/const-fn-not-safe-for-const.rs index fe672e7b3e6da..085ff5c58e60c 100644 --- a/src/test/ui/consts/const-fn-not-safe-for-const.rs +++ b/src/test/ui/consts/const-fn-not-safe-for-const.rs @@ -27,13 +27,9 @@ const fn get_Y_addr() -> &'static u32 { } const fn get() -> u32 { - let x = 22; //~ ERROR let bindings in constant functions are unstable -//~^ ERROR statements in constant functions - let y = 44; //~ ERROR let bindings in constant functions are unstable -//~^ ERROR statements in constant functions + let x = 22; + let y = 44; x + y -//~^ ERROR let bindings in constant functions are unstable -//~| ERROR let bindings in constant functions are unstable } fn main() {} diff --git a/src/test/ui/consts/const-fn-not-safe-for-const.stderr b/src/test/ui/consts/const-fn-not-safe-for-const.stderr index 8cc4c38526238..2003b137c272b 100644 --- a/src/test/ui/consts/const-fn-not-safe-for-const.stderr +++ b/src/test/ui/consts/const-fn-not-safe-for-const.stderr @@ -16,55 +16,7 @@ error[E0013]: constant functions cannot refer to statics, use a constant instead LL | &Y | ^^ -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-not-safe-for-const.rs:30:13 - | -LL | let x = 22; //~ ERROR let bindings in constant functions are unstable - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-not-safe-for-const.rs:30:13 - | -LL | let x = 22; //~ ERROR let bindings in constant functions are unstable - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-not-safe-for-const.rs:32:13 - | -LL | let y = 44; //~ ERROR let bindings in constant functions are unstable - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-not-safe-for-const.rs:32:13 - | -LL | let y = 44; //~ ERROR let bindings in constant functions are unstable - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-not-safe-for-const.rs:34:5 - | -LL | x + y - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constant functions are unstable (see issue #48821) - --> $DIR/const-fn-not-safe-for-const.rs:34:9 - | -LL | x + y - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 9 previous errors +error: aborting due to 3 previous errors -Some errors occurred: E0013, E0015, E0658. +Some errors occurred: E0013, E0015. For more information about an error, try `rustc --explain E0013`. diff --git a/src/test/ui/consts/const-int-unchecked.rs b/src/test/ui/consts/const-int-unchecked.rs index aeac6c37dcbab..8ee029b6cc390 100644 --- a/src/test/ui/consts/const-int-unchecked.rs +++ b/src/test/ui/consts/const-int-unchecked.rs @@ -2,10 +2,119 @@ use std::intrinsics; -const SHR: u8 = unsafe { intrinsics::unchecked_shr(5_u8, 8) }; +// The documentation of `unchecked_shl` states that it: +// +// Performs an unchecked left shift, resulting in undefined behavior when +// y < 0 or y >= N, where N is the width of T in bits. +// +// So we check this for a few `y`. + +// unsigned types: + +const SHL_U8: u8 = unsafe { intrinsics::unchecked_shl(5_u8, 8) }; +//~^ ERROR any use of this value will cause an error +const SHL_U16: u16 = unsafe { intrinsics::unchecked_shl(5_u16, 16) }; +//~^ ERROR any use of this value will cause an error +const SHL_U32: u32 = unsafe { intrinsics::unchecked_shl(5_u32, 32) }; +//~^ ERROR any use of this value will cause an error +const SHL_U64: u64 = unsafe { intrinsics::unchecked_shl(5_u64, 64) }; +//~^ ERROR any use of this value will cause an error +const SHL_U128: u128 = unsafe { intrinsics::unchecked_shl(5_u128, 128) }; +//~^ ERROR any use of this value will cause an error + +// signed types: + +const SHL_I8: i8 = unsafe { intrinsics::unchecked_shl(5_i8, 8) }; +//~^ ERROR any use of this value will cause an error +const SHL_I16: i16 = unsafe { intrinsics::unchecked_shl(5_16, 16) }; +//~^ ERROR any use of this value will cause an error +const SHL_I32: i32 = unsafe { intrinsics::unchecked_shl(5_i32, 32) }; +//~^ ERROR any use of this value will cause an error +const SHL_I64: i64 = unsafe { intrinsics::unchecked_shl(5_i64, 64) }; +//~^ ERROR any use of this value will cause an error +const SHL_I128: i128 = unsafe { intrinsics::unchecked_shl(5_i128, 128) }; +//~^ ERROR any use of this value will cause an error + +// and make sure we capture y < 0: + +const SHL_I8_NEG: i8 = unsafe { intrinsics::unchecked_shl(5_i8, -1) }; +//~^ ERROR any use of this value will cause an error +const SHL_I16_NEG: i16 = unsafe { intrinsics::unchecked_shl(5_16, -1) }; +//~^ ERROR any use of this value will cause an error +const SHL_I32_NEG: i32 = unsafe { intrinsics::unchecked_shl(5_i32, -1) }; +//~^ ERROR any use of this value will cause an error +const SHL_I64_NEG: i64 = unsafe { intrinsics::unchecked_shl(5_i64, -1) }; +//~^ ERROR any use of this value will cause an error +const SHL_I128_NEG: i128 = unsafe { intrinsics::unchecked_shl(5_i128, -1) }; +//~^ ERROR any use of this value will cause an error + +// and that there's no special relation to the value -1 by picking some +// negative values at random: + +const SHL_I8_NEG_RANDOM: i8 = unsafe { intrinsics::unchecked_shl(5_i8, -6) }; +//~^ ERROR any use of this value will cause an error +const SHL_I16_NEG_RANDOM: i16 = unsafe { intrinsics::unchecked_shl(5_16, -13) }; +//~^ ERROR any use of this value will cause an error +const SHL_I32_NEG_RANDOM: i32 = unsafe { intrinsics::unchecked_shl(5_i32, -25) }; +//~^ ERROR any use of this value will cause an error +const SHL_I64_NEG_RANDOM: i64 = unsafe { intrinsics::unchecked_shl(5_i64, -30) }; +//~^ ERROR any use of this value will cause an error +const SHL_I128_NEG_RANDOM: i128 = unsafe { intrinsics::unchecked_shl(5_i128, -93) }; +//~^ ERROR any use of this value will cause an error + +// Repeat it all over for `unchecked_shr` + +// unsigned types: + +const SHR_U8: u8 = unsafe { intrinsics::unchecked_shr(5_u8, 8) }; +//~^ ERROR any use of this value will cause an error +const SHR_U16: u16 = unsafe { intrinsics::unchecked_shr(5_u16, 16) }; +//~^ ERROR any use of this value will cause an error +const SHR_U32: u32 = unsafe { intrinsics::unchecked_shr(5_u32, 32) }; +//~^ ERROR any use of this value will cause an error +const SHR_U64: u64 = unsafe { intrinsics::unchecked_shr(5_u64, 64) }; +//~^ ERROR any use of this value will cause an error +const SHR_U128: u128 = unsafe { intrinsics::unchecked_shr(5_u128, 128) }; +//~^ ERROR any use of this value will cause an error + +// signed types: + +const SHR_I8: i8 = unsafe { intrinsics::unchecked_shr(5_i8, 8) }; +//~^ ERROR any use of this value will cause an error +const SHR_I16: i16 = unsafe { intrinsics::unchecked_shr(5_16, 16) }; +//~^ ERROR any use of this value will cause an error +const SHR_I32: i32 = unsafe { intrinsics::unchecked_shr(5_i32, 32) }; +//~^ ERROR any use of this value will cause an error +const SHR_I64: i64 = unsafe { intrinsics::unchecked_shr(5_i64, 64) }; +//~^ ERROR any use of this value will cause an error +const SHR_I128: i128 = unsafe { intrinsics::unchecked_shr(5_i128, 128) }; +//~^ ERROR any use of this value will cause an error + +// and make sure we capture y < 0: + +const SHR_I8_NEG: i8 = unsafe { intrinsics::unchecked_shr(5_i8, -1) }; +//~^ ERROR any use of this value will cause an error +const SHR_I16_NEG: i16 = unsafe { intrinsics::unchecked_shr(5_16, -1) }; +//~^ ERROR any use of this value will cause an error +const SHR_I32_NEG: i32 = unsafe { intrinsics::unchecked_shr(5_i32, -1) }; +//~^ ERROR any use of this value will cause an error +const SHR_I64_NEG: i64 = unsafe { intrinsics::unchecked_shr(5_i64, -1) }; +//~^ ERROR any use of this value will cause an error +const SHR_I128_NEG: i128 = unsafe { intrinsics::unchecked_shr(5_i128, -1) }; +//~^ ERROR any use of this value will cause an error + +// and that there's no special relation to the value -1 by picking some +// negative values at random: + +const SHR_I8_NEG_RANDOM: i8 = unsafe { intrinsics::unchecked_shr(5_i8, -6) }; +//~^ ERROR any use of this value will cause an error +const SHR_I16_NEG_RANDOM: i16 = unsafe { intrinsics::unchecked_shr(5_16, -13) }; +//~^ ERROR any use of this value will cause an error +const SHR_I32_NEG_RANDOM: i32 = unsafe { intrinsics::unchecked_shr(5_i32, -25) }; +//~^ ERROR any use of this value will cause an error +const SHR_I64_NEG_RANDOM: i64 = unsafe { intrinsics::unchecked_shr(5_i64, -30) }; //~^ ERROR any use of this value will cause an error -const SHL: u8 = unsafe { intrinsics::unchecked_shl(5_u8, 8) }; +const SHR_I128_NEG_RANDOM: i128 = unsafe { intrinsics::unchecked_shr(5_i128, -93) }; //~^ ERROR any use of this value will cause an error -fn main() { -} +fn main() {} diff --git a/src/test/ui/consts/const-int-unchecked.stderr b/src/test/ui/consts/const-int-unchecked.stderr index dd28cc4d533e9..4382d9174b757 100644 --- a/src/test/ui/consts/const-int-unchecked.stderr +++ b/src/test/ui/consts/const-int-unchecked.stderr @@ -1,20 +1,324 @@ error: any use of this value will cause an error - --> $DIR/const-int-unchecked.rs:5:1 + --> $DIR/const-int-unchecked.rs:14:1 | -LL | const SHR: u8 = unsafe { intrinsics::unchecked_shr(5_u8, 8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^^^ - | | - | Overflowing shift by 8 in unchecked_shr +LL | const SHL_U8: u8 = unsafe { intrinsics::unchecked_shl(5_u8, 8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^^^ + | | + | Overflowing shift by 8 in unchecked_shl | = note: #[deny(const_err)] on by default error: any use of this value will cause an error - --> $DIR/const-int-unchecked.rs:7:1 + --> $DIR/const-int-unchecked.rs:16:1 | -LL | const SHL: u8 = unsafe { intrinsics::unchecked_shl(5_u8, 8) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^^^ - | | - | Overflowing shift by 8 in unchecked_shl +LL | const SHL_U16: u16 = unsafe { intrinsics::unchecked_shl(5_u16, 16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 16 in unchecked_shl -error: aborting due to 2 previous errors +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:18:1 + | +LL | const SHL_U32: u32 = unsafe { intrinsics::unchecked_shl(5_u32, 32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 32 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:20:1 + | +LL | const SHL_U64: u64 = unsafe { intrinsics::unchecked_shl(5_u64, 64) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 64 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:22:1 + | +LL | const SHL_U128: u128 = unsafe { intrinsics::unchecked_shl(5_u128, 128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------^^^ + | | + | Overflowing shift by 128 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:27:1 + | +LL | const SHL_I8: i8 = unsafe { intrinsics::unchecked_shl(5_i8, 8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^^^ + | | + | Overflowing shift by 8 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:29:1 + | +LL | const SHL_I16: i16 = unsafe { intrinsics::unchecked_shl(5_16, 16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 16 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:31:1 + | +LL | const SHL_I32: i32 = unsafe { intrinsics::unchecked_shl(5_i32, 32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 32 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:33:1 + | +LL | const SHL_I64: i64 = unsafe { intrinsics::unchecked_shl(5_i64, 64) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 64 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:35:1 + | +LL | const SHL_I128: i128 = unsafe { intrinsics::unchecked_shl(5_i128, 128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------^^^ + | | + | Overflowing shift by 128 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:40:1 + | +LL | const SHL_I8_NEG: i8 = unsafe { intrinsics::unchecked_shl(5_i8, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 255 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:42:1 + | +LL | const SHL_I16_NEG: i16 = unsafe { intrinsics::unchecked_shl(5_16, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 65535 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:44:1 + | +LL | const SHL_I32_NEG: i32 = unsafe { intrinsics::unchecked_shl(5_i32, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 4294967295 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:46:1 + | +LL | const SHL_I64_NEG: i64 = unsafe { intrinsics::unchecked_shl(5_i64, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 18446744073709551615 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:48:1 + | +LL | const SHL_I128_NEG: i128 = unsafe { intrinsics::unchecked_shl(5_i128, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^^ + | | + | Overflowing shift by 340282366920938463463374607431768211455 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:54:1 + | +LL | const SHL_I8_NEG_RANDOM: i8 = unsafe { intrinsics::unchecked_shl(5_i8, -6) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 250 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:56:1 + | +LL | const SHL_I16_NEG_RANDOM: i16 = unsafe { intrinsics::unchecked_shl(5_16, -13) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 65523 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:58:1 + | +LL | const SHL_I32_NEG_RANDOM: i32 = unsafe { intrinsics::unchecked_shl(5_i32, -25) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^^ + | | + | Overflowing shift by 4294967271 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:60:1 + | +LL | const SHL_I64_NEG_RANDOM: i64 = unsafe { intrinsics::unchecked_shl(5_i64, -30) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^^ + | | + | Overflowing shift by 18446744073709551586 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:62:1 + | +LL | const SHL_I128_NEG_RANDOM: i128 = unsafe { intrinsics::unchecked_shl(5_i128, -93) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------^^^ + | | + | Overflowing shift by 340282366920938463463374607431768211363 in unchecked_shl + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:69:1 + | +LL | const SHR_U8: u8 = unsafe { intrinsics::unchecked_shr(5_u8, 8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^^^ + | | + | Overflowing shift by 8 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:71:1 + | +LL | const SHR_U16: u16 = unsafe { intrinsics::unchecked_shr(5_u16, 16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 16 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:73:1 + | +LL | const SHR_U32: u32 = unsafe { intrinsics::unchecked_shr(5_u32, 32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 32 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:75:1 + | +LL | const SHR_U64: u64 = unsafe { intrinsics::unchecked_shr(5_u64, 64) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 64 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:77:1 + | +LL | const SHR_U128: u128 = unsafe { intrinsics::unchecked_shr(5_u128, 128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------^^^ + | | + | Overflowing shift by 128 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:82:1 + | +LL | const SHR_I8: i8 = unsafe { intrinsics::unchecked_shr(5_i8, 8) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------------------------^^^ + | | + | Overflowing shift by 8 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:84:1 + | +LL | const SHR_I16: i16 = unsafe { intrinsics::unchecked_shr(5_16, 16) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 16 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:86:1 + | +LL | const SHR_I32: i32 = unsafe { intrinsics::unchecked_shr(5_i32, 32) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 32 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:88:1 + | +LL | const SHR_I64: i64 = unsafe { intrinsics::unchecked_shr(5_i64, 64) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 64 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:90:1 + | +LL | const SHR_I128: i128 = unsafe { intrinsics::unchecked_shr(5_i128, 128) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------^^^ + | | + | Overflowing shift by 128 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:95:1 + | +LL | const SHR_I8_NEG: i8 = unsafe { intrinsics::unchecked_shr(5_i8, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 255 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:97:1 + | +LL | const SHR_I16_NEG: i16 = unsafe { intrinsics::unchecked_shr(5_16, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 65535 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:99:1 + | +LL | const SHR_I32_NEG: i32 = unsafe { intrinsics::unchecked_shr(5_i32, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 4294967295 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:101:1 + | +LL | const SHR_I64_NEG: i64 = unsafe { intrinsics::unchecked_shr(5_i64, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 18446744073709551615 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:103:1 + | +LL | const SHR_I128_NEG: i128 = unsafe { intrinsics::unchecked_shr(5_i128, -1) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^^ + | | + | Overflowing shift by 340282366920938463463374607431768211455 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:109:1 + | +LL | const SHR_I8_NEG_RANDOM: i8 = unsafe { intrinsics::unchecked_shr(5_i8, -6) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------------------^^^ + | | + | Overflowing shift by 250 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:111:1 + | +LL | const SHR_I16_NEG_RANDOM: i16 = unsafe { intrinsics::unchecked_shr(5_16, -13) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------------------^^^ + | | + | Overflowing shift by 65523 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:113:1 + | +LL | const SHR_I32_NEG_RANDOM: i32 = unsafe { intrinsics::unchecked_shr(5_i32, -25) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^^ + | | + | Overflowing shift by 4294967271 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:115:1 + | +LL | const SHR_I64_NEG_RANDOM: i64 = unsafe { intrinsics::unchecked_shr(5_i64, -30) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------------------------^^^ + | | + | Overflowing shift by 18446744073709551586 in unchecked_shr + +error: any use of this value will cause an error + --> $DIR/const-int-unchecked.rs:117:1 + | +LL | const SHR_I128_NEG_RANDOM: i128 = unsafe { intrinsics::unchecked_shr(5_i128, -93) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------------------^^^ + | | + | Overflowing shift by 340282366920938463463374607431768211363 in unchecked_shr + +error: aborting due to 40 previous errors diff --git a/src/test/ui/consts/const_let_assign.rs b/src/test/ui/consts/const_let_assign.rs index a3c53a451e106..0b09b8469fd75 100644 --- a/src/test/ui/consts/const_let_assign.rs +++ b/src/test/ui/consts/const_let_assign.rs @@ -1,7 +1,5 @@ // compile-pass -#![feature(const_let)] - struct S(i32); const A: () = { diff --git a/src/test/ui/consts/const_let_assign2.rs b/src/test/ui/consts/const_let_assign2.rs index 0de7396501adc..1c44237e49b7a 100644 --- a/src/test/ui/consts/const_let_assign2.rs +++ b/src/test/ui/consts/const_let_assign2.rs @@ -1,8 +1,5 @@ // compile-pass -#![feature(const_let)] -#![feature(const_fn)] - pub struct AA { pub data: [u8; 10], } diff --git a/src/test/ui/consts/const_let_assign3.rs b/src/test/ui/consts/const_let_assign3.rs index c2ed6cd85ab5c..cbe73923e9c42 100644 --- a/src/test/ui/consts/const_let_assign3.rs +++ b/src/test/ui/consts/const_let_assign3.rs @@ -1,4 +1,3 @@ -#![feature(const_let)] #![feature(const_fn)] struct S { @@ -18,6 +17,15 @@ const FOO: S = { s }; +type Array = [u32; { + let mut x = 2; + let y = &mut x; +//~^ ERROR references in constants may only refer to immutable values + *y = 42; +//~^ ERROR constant contains unimplemented expression type + *y +}]; + fn main() { assert_eq!(FOO.state, 3); } diff --git a/src/test/ui/consts/const_let_assign3.stderr b/src/test/ui/consts/const_let_assign3.stderr index 0f294616d255c..6649fb997cce4 100644 --- a/src/test/ui/consts/const_let_assign3.stderr +++ b/src/test/ui/consts/const_let_assign3.stderr @@ -1,16 +1,28 @@ error[E0019]: constant function contains unimplemented expression type - --> $DIR/const_let_assign3.rs:10:9 + --> $DIR/const_let_assign3.rs:9:9 | LL | self.state = x; | ^^^^^^^^^^^^^^ error[E0017]: references in constants may only refer to immutable values - --> $DIR/const_let_assign3.rs:17:5 + --> $DIR/const_let_assign3.rs:16:5 | LL | s.foo(3); //~ ERROR references in constants may only refer to immutable values | ^ constants require immutable values -error: aborting due to 2 previous errors +error[E0017]: references in constants may only refer to immutable values + --> $DIR/const_let_assign3.rs:22:13 + | +LL | let y = &mut x; + | ^^^^^^ constants require immutable values + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const_let_assign3.rs:24:5 + | +LL | *y = 42; + | ^^^^^^^ + +error: aborting due to 4 previous errors Some errors occurred: E0017, E0019. For more information about an error, try `rustc --explain E0017`. diff --git a/src/test/ui/consts/const_let_eq.rs b/src/test/ui/consts/const_let_eq.rs index 8739cb80e9403..a2364c392f26b 100644 --- a/src/test/ui/consts/const_let_eq.rs +++ b/src/test/ui/consts/const_let_eq.rs @@ -1,5 +1,3 @@ -#![feature(const_let, const_fn)] - // run-pass struct Foo(T); diff --git a/src/test/ui/consts/const_let_eq_float.rs b/src/test/ui/consts/const_let_eq_float.rs index 2c7262df367a3..c48f54e567b2c 100644 --- a/src/test/ui/consts/const_let_eq_float.rs +++ b/src/test/ui/consts/const_let_eq_float.rs @@ -1,6 +1,6 @@ // compile-pass -#![feature(const_let, const_fn)] +#![feature(const_fn)] struct Foo(T); struct Bar { x: T } diff --git a/src/test/ui/consts/const_let_irrefutable.rs b/src/test/ui/consts/const_let_irrefutable.rs new file mode 100644 index 0000000000000..424a16f7ed39b --- /dev/null +++ b/src/test/ui/consts/const_let_irrefutable.rs @@ -0,0 +1,11 @@ +// compile-pass + +fn main() {} + +const fn tup((a, b): (i32, i32)) -> i32 { + a + b +} + +const fn array([a, b]: [i32; 2]) -> i32 { + a + b +} diff --git a/src/test/ui/consts/const_let_refutable.rs b/src/test/ui/consts/const_let_refutable.rs new file mode 100644 index 0000000000000..345f682868fbc --- /dev/null +++ b/src/test/ui/consts/const_let_refutable.rs @@ -0,0 +1,5 @@ +fn main() {} + +const fn slice([a, b]: &[i32]) -> i32 { //~ ERROR refutable pattern in function argument + a + b +} diff --git a/src/test/ui/consts/const_let_refutable.stderr b/src/test/ui/consts/const_let_refutable.stderr new file mode 100644 index 0000000000000..c5d2ba02a70c6 --- /dev/null +++ b/src/test/ui/consts/const_let_refutable.stderr @@ -0,0 +1,9 @@ +error[E0005]: refutable pattern in function argument: `&[]` not covered + --> $DIR/const_let_refutable.rs:3:16 + | +LL | const fn slice([a, b]: &[i32]) -> i32 { //~ ERROR refutable pattern in function argument + | ^^^^^^ pattern `&[]` not covered + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0005`. diff --git a/src/test/ui/consts/const_short_circuit.rs b/src/test/ui/consts/const_short_circuit.rs index cc49e4696e58f..1e7b7ed319355 100644 --- a/src/test/ui/consts/const_short_circuit.rs +++ b/src/test/ui/consts/const_short_circuit.rs @@ -1,4 +1,4 @@ -#![feature(underscore_const_names, const_let)] +#![feature(underscore_const_names)] const _: bool = false && false; const _: bool = true && false; diff --git a/src/test/ui/consts/dangling-alloc-id-ice.rs b/src/test/ui/consts/dangling-alloc-id-ice.rs index 695d33b690898..dbc50f1fbd4b4 100644 --- a/src/test/ui/consts/dangling-alloc-id-ice.rs +++ b/src/test/ui/consts/dangling-alloc-id-ice.rs @@ -1,7 +1,5 @@ // https://github.com/rust-lang/rust/issues/55223 -#![feature(const_let)] - union Foo<'a> { y: &'a (), long_live_the_unit: &'static (), diff --git a/src/test/ui/consts/dangling-alloc-id-ice.stderr b/src/test/ui/consts/dangling-alloc-id-ice.stderr index a5fa88e5e6832..2cd8711f03d31 100644 --- a/src/test/ui/consts/dangling-alloc-id-ice.stderr +++ b/src/test/ui/consts/dangling-alloc-id-ice.stderr @@ -1,5 +1,5 @@ error: any use of this value will cause an error - --> $DIR/dangling-alloc-id-ice.rs:10:1 + --> $DIR/dangling-alloc-id-ice.rs:8:1 | LL | / const FOO: &() = { //~ ERROR any use of this value will cause an error LL | | let y = (); diff --git a/src/test/ui/consts/dangling_raw_ptr.rs b/src/test/ui/consts/dangling_raw_ptr.rs index 7fc773412f2f8..c2d8e6d421a28 100644 --- a/src/test/ui/consts/dangling_raw_ptr.rs +++ b/src/test/ui/consts/dangling_raw_ptr.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - const FOO: *const u32 = { //~ ERROR any use of this value will cause an error let x = 42; &x diff --git a/src/test/ui/consts/dangling_raw_ptr.stderr b/src/test/ui/consts/dangling_raw_ptr.stderr index 3b20936f8ae97..091f1f785cb02 100644 --- a/src/test/ui/consts/dangling_raw_ptr.stderr +++ b/src/test/ui/consts/dangling_raw_ptr.stderr @@ -1,5 +1,5 @@ error: any use of this value will cause an error - --> $DIR/dangling_raw_ptr.rs:3:1 + --> $DIR/dangling_raw_ptr.rs:1:1 | LL | / const FOO: *const u32 = { //~ ERROR any use of this value will cause an error LL | | let x = 42; diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs index 238b5f7e31003..05cf3d5f1f173 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn.rs @@ -96,7 +96,7 @@ const fn foo30_2(x: *mut u32) -> usize { x as usize } const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } } //~^ ERROR `if`, `match`, `&&` and `||` are not stable in const fn const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn -const fn foo30_6() -> bool { let x = true; x } //~ ERROR local variables in const fn +const fn foo30_6() -> bool { let x = true; x } const fn foo36(a: bool, b: bool) -> bool { a && b } //~^ ERROR `if`, `match`, `&&` and `||` are not stable in const fn const fn foo37(a: bool, b: bool) -> bool { a || b } diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr index 1c68df513b697..2cae714fbf727 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr @@ -112,12 +112,6 @@ error: `if`, `match`, `&&` and `||` are not stable in const fn LL | const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn | ^^^^^^^^^^^ -error: local variables in const fn are unstable - --> $DIR/min_const_fn.rs:99:34 - | -LL | const fn foo30_6() -> bool { let x = true; x } //~ ERROR local variables in const fn - | ^ - error: `if`, `match`, `&&` and `||` are not stable in const fn --> $DIR/min_const_fn.rs:100:44 | @@ -208,6 +202,6 @@ error: function pointers in const fn are unstable LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo } | ^^^^ -error: aborting due to 35 previous errors +error: aborting due to 34 previous errors For more information about this error, try `rustc --explain E0493`. diff --git a/src/test/ui/consts/min_const_fn/mutable_borrow.rs b/src/test/ui/consts/min_const_fn/mutable_borrow.rs index 3dd76b630a883..89acfea6ed8ff 100644 --- a/src/test/ui/consts/min_const_fn/mutable_borrow.rs +++ b/src/test/ui/consts/min_const_fn/mutable_borrow.rs @@ -1,6 +1,6 @@ const fn mutable_ref_in_const() -> u8 { - let mut a = 0; //~ ERROR local variables in const fn - let b = &mut a; + let mut a = 0; + let b = &mut a; //~ ERROR mutable references in const fn *b } @@ -8,8 +8,8 @@ struct X; impl X { const fn inherent_mutable_ref_in_const() -> u8 { - let mut a = 0; //~ ERROR local variables in const fn - let b = &mut a; + let mut a = 0; + let b = &mut a; //~ ERROR mutable references in const fn *b } } diff --git a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr index fa46f5c804fe0..5ce0f30dc6e1f 100644 --- a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr +++ b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr @@ -1,14 +1,14 @@ -error: local variables in const fn are unstable - --> $DIR/mutable_borrow.rs:2:9 +error: mutable references in const fn are unstable + --> $DIR/mutable_borrow.rs:3:9 | -LL | let mut a = 0; //~ ERROR local variables in const fn - | ^^^^^ +LL | let b = &mut a; //~ ERROR mutable references in const fn + | ^ -error: local variables in const fn are unstable - --> $DIR/mutable_borrow.rs:11:13 +error: mutable references in const fn are unstable + --> $DIR/mutable_borrow.rs:12:13 | -LL | let mut a = 0; //~ ERROR local variables in const fn - | ^^^^^ +LL | let b = &mut a; //~ ERROR mutable references in const fn + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/consts/partial_qualif.rs b/src/test/ui/consts/partial_qualif.rs index 4ce41f80f82c8..32c68e69f4bed 100644 --- a/src/test/ui/consts/partial_qualif.rs +++ b/src/test/ui/consts/partial_qualif.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - use std::cell::Cell; const FOO: &(Cell, bool) = { diff --git a/src/test/ui/consts/partial_qualif.stderr b/src/test/ui/consts/partial_qualif.stderr index d695f64e2c3b5..967fb83b78b08 100644 --- a/src/test/ui/consts/partial_qualif.stderr +++ b/src/test/ui/consts/partial_qualif.stderr @@ -1,5 +1,5 @@ error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead - --> $DIR/partial_qualif.rs:8:5 + --> $DIR/partial_qualif.rs:6:5 | LL | &{a} //~ ERROR cannot borrow a constant which may contain interior mutability | ^^^^ diff --git a/src/test/ui/consts/projection_qualif.rs b/src/test/ui/consts/projection_qualif.rs index 5863429a2f2c5..dedb7db592089 100644 --- a/src/test/ui/consts/projection_qualif.rs +++ b/src/test/ui/consts/projection_qualif.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - use std::cell::Cell; const FOO: &u32 = { diff --git a/src/test/ui/consts/projection_qualif.stderr b/src/test/ui/consts/projection_qualif.stderr index cc3635a979b37..410c51c4b54e1 100644 --- a/src/test/ui/consts/projection_qualif.stderr +++ b/src/test/ui/consts/projection_qualif.stderr @@ -1,17 +1,17 @@ error[E0017]: references in constants may only refer to immutable values - --> $DIR/projection_qualif.rs:8:27 + --> $DIR/projection_qualif.rs:6:27 | LL | let b: *mut u32 = &mut a; //~ ERROR may only refer to immutable values | ^^^^^^ constants require immutable values error[E0019]: constant contains unimplemented expression type - --> $DIR/projection_qualif.rs:9:18 + --> $DIR/projection_qualif.rs:7:18 | LL | unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants | ^^^^^^ error[E0658]: dereferencing raw pointers in constants is unstable (see issue #51911) - --> $DIR/projection_qualif.rs:9:18 + --> $DIR/projection_qualif.rs:7:18 | LL | unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants | ^^^^^^ diff --git a/src/test/ui/consts/promote_const_let.rs b/src/test/ui/consts/promote_const_let.rs index 8de9b00eb111d..a8a6d4d99c6ff 100644 --- a/src/test/ui/consts/promote_const_let.rs +++ b/src/test/ui/consts/promote_const_let.rs @@ -1,8 +1,10 @@ -#![feature(const_let)] - fn main() { let x: &'static u32 = { let y = 42; &y //~ ERROR does not live long enough }; + let x: &'static u32 = &{ //~ ERROR does not live long enough + let y = 42; + y + }; } diff --git a/src/test/ui/consts/promote_const_let.stderr b/src/test/ui/consts/promote_const_let.stderr index 6bbb7495fb0dc..d37bd49186032 100644 --- a/src/test/ui/consts/promote_const_let.stderr +++ b/src/test/ui/consts/promote_const_let.stderr @@ -1,5 +1,5 @@ error[E0597]: `y` does not live long enough - --> $DIR/promote_const_let.rs:6:10 + --> $DIR/promote_const_let.rs:4:10 | LL | &y //~ ERROR does not live long enough | ^ borrowed value does not live long enough @@ -8,6 +8,20 @@ LL | }; | = note: borrowed value must be valid for the static lifetime... -error: aborting due to previous error +error[E0597]: borrowed value does not live long enough + --> $DIR/promote_const_let.rs:6:28 + | +LL | let x: &'static u32 = &{ //~ ERROR does not live long enough + | ____________________________^ +LL | | let y = 42; +LL | | y +LL | | }; + | |_____^ temporary value does not live long enough +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/consts/qualif_overwrite.rs b/src/test/ui/consts/qualif_overwrite.rs index 806a74ee4530b..430eea37de73c 100644 --- a/src/test/ui/consts/qualif_overwrite.rs +++ b/src/test/ui/consts/qualif_overwrite.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - use std::cell::Cell; // this is overly conservative. The reset to `None` should clear `a` of all qualifications diff --git a/src/test/ui/consts/qualif_overwrite.stderr b/src/test/ui/consts/qualif_overwrite.stderr index 4fac64bf8063f..30479139e314c 100644 --- a/src/test/ui/consts/qualif_overwrite.stderr +++ b/src/test/ui/consts/qualif_overwrite.stderr @@ -1,5 +1,5 @@ error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead - --> $DIR/qualif_overwrite.rs:12:5 + --> $DIR/qualif_overwrite.rs:10:5 | LL | &{a} //~ ERROR cannot borrow a constant which may contain interior mutability | ^^^^ diff --git a/src/test/ui/consts/qualif_overwrite_2.rs b/src/test/ui/consts/qualif_overwrite_2.rs index 29557a3da4781..fa79b5c14a736 100644 --- a/src/test/ui/consts/qualif_overwrite_2.rs +++ b/src/test/ui/consts/qualif_overwrite_2.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - use std::cell::Cell; // const qualification is not smart enough to know about fields and always assumes that there might diff --git a/src/test/ui/consts/qualif_overwrite_2.stderr b/src/test/ui/consts/qualif_overwrite_2.stderr index 181b728c7b76f..8276db99a12c0 100644 --- a/src/test/ui/consts/qualif_overwrite_2.stderr +++ b/src/test/ui/consts/qualif_overwrite_2.stderr @@ -1,5 +1,5 @@ error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead - --> $DIR/qualif_overwrite_2.rs:10:5 + --> $DIR/qualif_overwrite_2.rs:8:5 | LL | &{a.0} //~ ERROR cannot borrow a constant which may contain interior mutability | ^^^^^^ diff --git a/src/test/ui/consts/static_mut_containing_mut_ref2.rs b/src/test/ui/consts/static_mut_containing_mut_ref2.rs index 4180b1e295ab0..ef378fa84518e 100644 --- a/src/test/ui/consts/static_mut_containing_mut_ref2.rs +++ b/src/test/ui/consts/static_mut_containing_mut_ref2.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - static mut STDERR_BUFFER_SPACE: u8 = 0; pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; diff --git a/src/test/ui/consts/static_mut_containing_mut_ref2.stderr b/src/test/ui/consts/static_mut_containing_mut_ref2.stderr index f0ae1545056b7..72186571d697e 100644 --- a/src/test/ui/consts/static_mut_containing_mut_ref2.stderr +++ b/src/test/ui/consts/static_mut_containing_mut_ref2.stderr @@ -1,11 +1,11 @@ error[E0017]: references in statics may only refer to immutable values - --> $DIR/static_mut_containing_mut_ref2.rs:5:46 + --> $DIR/static_mut_containing_mut_ref2.rs:3:46 | LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values error[E0019]: static contains unimplemented expression type - --> $DIR/static_mut_containing_mut_ref2.rs:5:45 + --> $DIR/static_mut_containing_mut_ref2.rs:3:45 | LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/consts/static_mut_containing_mut_ref3.rs b/src/test/ui/consts/static_mut_containing_mut_ref3.rs index 0bc7faa9afdec..c24c7e2792079 100644 --- a/src/test/ui/consts/static_mut_containing_mut_ref3.rs +++ b/src/test/ui/consts/static_mut_containing_mut_ref3.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - static mut FOO: (u8, u8) = (42, 43); static mut BAR: () = unsafe { FOO.0 = 99; }; diff --git a/src/test/ui/consts/static_mut_containing_mut_ref3.stderr b/src/test/ui/consts/static_mut_containing_mut_ref3.stderr index cae53c6fee9dd..e88e49b097af2 100644 --- a/src/test/ui/consts/static_mut_containing_mut_ref3.stderr +++ b/src/test/ui/consts/static_mut_containing_mut_ref3.stderr @@ -1,5 +1,5 @@ error[E0080]: could not evaluate static initializer - --> $DIR/static_mut_containing_mut_ref3.rs:5:31 + --> $DIR/static_mut_containing_mut_ref3.rs:3:31 | LL | static mut BAR: () = unsafe { FOO.0 = 99; }; | ^^^^^^^^^^ tried to modify a static's initial value from another static's initializer diff --git a/src/test/ui/error-codes/E0010-teach.rs b/src/test/ui/error-codes/E0010-teach.rs index fc5dffb37cfe7..da51035ab5550 100644 --- a/src/test/ui/error-codes/E0010-teach.rs +++ b/src/test/ui/error-codes/E0010-teach.rs @@ -4,5 +4,6 @@ #![allow(warnings)] const CON : Box = box 0; //~ ERROR E0010 +//~^ ERROR constant contains unimplemented expression type fn main() {} diff --git a/src/test/ui/error-codes/E0010-teach.stderr b/src/test/ui/error-codes/E0010-teach.stderr index da0aadfded5f8..77e7b5ec0e860 100644 --- a/src/test/ui/error-codes/E0010-teach.stderr +++ b/src/test/ui/error-codes/E0010-teach.stderr @@ -6,6 +6,16 @@ LL | const CON : Box = box 0; //~ ERROR E0010 | = note: The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and therefore cannot be done at compile time. -error: aborting due to previous error +error[E0019]: constant contains unimplemented expression type + --> $DIR/E0010-teach.rs:6:28 + | +LL | const CON : Box = box 0; //~ ERROR E0010 + | ^ + | + = note: A function call isn't allowed in the const's initialization expression because the expression's value must be known at compile-time. + = note: Remember: you can't use a function call inside a const's initialization expression! However, you can use it anywhere else. + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0010`. +Some errors occurred: E0010, E0019. +For more information about an error, try `rustc --explain E0010`. diff --git a/src/test/ui/error-codes/E0010.rs b/src/test/ui/error-codes/E0010.rs index e62997640f473..3398e2c28ba6b 100644 --- a/src/test/ui/error-codes/E0010.rs +++ b/src/test/ui/error-codes/E0010.rs @@ -2,5 +2,6 @@ #![allow(warnings)] const CON : Box = box 0; //~ ERROR E0010 +//~^ ERROR constant contains unimplemented expression type fn main() {} diff --git a/src/test/ui/error-codes/E0010.stderr b/src/test/ui/error-codes/E0010.stderr index b4b490922c45f..1364693109e08 100644 --- a/src/test/ui/error-codes/E0010.stderr +++ b/src/test/ui/error-codes/E0010.stderr @@ -4,6 +4,13 @@ error[E0010]: allocations are not allowed in constants LL | const CON : Box = box 0; //~ ERROR E0010 | ^^^^^ allocation not allowed in constants -error: aborting due to previous error +error[E0019]: constant contains unimplemented expression type + --> $DIR/E0010.rs:4:28 + | +LL | const CON : Box = box 0; //~ ERROR E0010 + | ^ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0010`. +Some errors occurred: E0010, E0019. +For more information about an error, try `rustc --explain E0010`. diff --git a/src/test/ui/feature-gates/feature-gate-const_let.rs b/src/test/ui/feature-gates/feature-gate-const_let.rs deleted file mode 100644 index 74cefd7c0670d..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-const_let.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Test use of const let without feature gate. - -const FOO: usize = { - //~^ ERROR statements in constants are unstable - //~| ERROR: let bindings in constants are unstable - let x = 42; - //~^ ERROR statements in constants are unstable - //~| ERROR: let bindings in constants are unstable - 42 -}; - -static BAR: usize = { - //~^ ERROR statements in statics are unstable - //~| ERROR: let bindings in statics are unstable - let x = 42; - //~^ ERROR statements in statics are unstable - //~| ERROR: let bindings in statics are unstable - 42 -}; - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-const_let.stderr b/src/test/ui/feature-gates/feature-gate-const_let.stderr deleted file mode 100644 index 56312999a5fd8..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-const_let.stderr +++ /dev/null @@ -1,91 +0,0 @@ -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:6:13 - | -LL | let x = 42; - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:6:13 - | -LL | let x = 42; - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:3:1 - | -LL | / const FOO: usize = { -LL | | //~^ ERROR statements in constants are unstable -LL | | //~| ERROR: let bindings in constants are unstable -LL | | let x = 42; -... | -LL | | 42 -LL | | }; - | |__^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:3:1 - | -LL | / const FOO: usize = { -LL | | //~^ ERROR statements in constants are unstable -LL | | //~| ERROR: let bindings in constants are unstable -LL | | let x = 42; -... | -LL | | 42 -LL | | }; - | |__^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in statics are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:15:13 - | -LL | let x = 42; - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:15:13 - | -LL | let x = 42; - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in statics are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:12:1 - | -LL | / static BAR: usize = { -LL | | //~^ ERROR statements in statics are unstable -LL | | //~| ERROR: let bindings in statics are unstable -LL | | let x = 42; -... | -LL | | 42 -LL | | }; - | |__^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/feature-gate-const_let.rs:12:1 - | -LL | / static BAR: usize = { -LL | | //~^ ERROR statements in statics are unstable -LL | | //~| ERROR: let bindings in statics are unstable -LL | | let x = 42; -... | -LL | | 42 -LL | | }; - | |__^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 8 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-underscore_const_names.rs b/src/test/ui/feature-gates/feature-gate-underscore_const_names.rs index a82b356c75216..6b97c24a47ed2 100644 --- a/src/test/ui/feature-gates/feature-gate-underscore_const_names.rs +++ b/src/test/ui/feature-gates/feature-gate-underscore_const_names.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - trait Trt {} struct Str {} diff --git a/src/test/ui/feature-gates/feature-gate-underscore_const_names.stderr b/src/test/ui/feature-gates/feature-gate-underscore_const_names.stderr index b3658208828e9..d608f3d37cf2a 100644 --- a/src/test/ui/feature-gates/feature-gate-underscore_const_names.stderr +++ b/src/test/ui/feature-gates/feature-gate-underscore_const_names.stderr @@ -1,5 +1,5 @@ error[E0658]: naming constants with `_` is unstable (see issue #54912) - --> $DIR/feature-gate-underscore_const_names.rs:8:1 + --> $DIR/feature-gate-underscore_const_names.rs:6:1 | LL | / const _ : () = { LL | | //~^ ERROR is unstable diff --git a/src/test/ui/issues/issue-18118.rs b/src/test/ui/issues/issue-18118.rs index 7bbea191cd167..f58a3de281f1a 100644 --- a/src/test/ui/issues/issue-18118.rs +++ b/src/test/ui/issues/issue-18118.rs @@ -1,11 +1,6 @@ pub fn main() { const z: &'static isize = { - //~^ ERROR let bindings in constants are unstable - //~| ERROR statements in constants are unstable let p = 3; - //~^ ERROR let bindings in constants are unstable - //~| ERROR statements in constants are unstable &p //~ ERROR `p` does not live long enough - //~^ ERROR let bindings in constants are unstable }; } diff --git a/src/test/ui/issues/issue-18118.stderr b/src/test/ui/issues/issue-18118.stderr index 1383cdb4438c9..9b21ece341a9f 100644 --- a/src/test/ui/issues/issue-18118.stderr +++ b/src/test/ui/issues/issue-18118.stderr @@ -1,67 +1,13 @@ -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/issue-18118.rs:5:17 - | -LL | let p = 3; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/issue-18118.rs:5:17 - | -LL | let p = 3; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/issue-18118.rs:8:9 - | -LL | &p //~ ERROR `p` does not live long enough - | ^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: let bindings in constants are unstable (see issue #48821) - --> $DIR/issue-18118.rs:2:5 - | -LL | / const z: &'static isize = { -LL | | //~^ ERROR let bindings in constants are unstable -LL | | //~| ERROR statements in constants are unstable -LL | | let p = 3; -... | -LL | | //~^ ERROR let bindings in constants are unstable -LL | | }; - | |______^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/issue-18118.rs:2:5 - | -LL | / const z: &'static isize = { -LL | | //~^ ERROR let bindings in constants are unstable -LL | | //~| ERROR statements in constants are unstable -LL | | let p = 3; -... | -LL | | //~^ ERROR let bindings in constants are unstable -LL | | }; - | |______^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - error[E0597]: `p` does not live long enough - --> $DIR/issue-18118.rs:8:10 + --> $DIR/issue-18118.rs:4:10 | LL | &p //~ ERROR `p` does not live long enough | ^ borrowed value does not live long enough -LL | //~^ ERROR let bindings in constants are unstable LL | }; | - borrowed value only lives until here | = note: borrowed value must be valid for the static lifetime... -error: aborting due to 6 previous errors +error: aborting due to previous error -Some errors occurred: E0597, E0658. -For more information about an error, try `rustc --explain E0597`. +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/issues/issue-32829-2.rs b/src/test/ui/issues/issue-32829-2.rs index 9db9d30411d6f..c93c84b5fb773 100644 --- a/src/test/ui/issues/issue-32829-2.rs +++ b/src/test/ui/issues/issue-32829-2.rs @@ -1,11 +1,8 @@ // ignore-tidy-linelength -#![feature(const_fn)] - const bad : u32 = { { 5; - //~^ ERROR statements in constants are unstable 0 } }; @@ -13,8 +10,7 @@ const bad : u32 = { const bad_two : u32 = { { invalid(); - //~^ ERROR statements in constants are unstable - //~^^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants + //~^ ERROR: calls in constants are limited to constant functions, tuple structs and tuple variants 0 } }; @@ -22,7 +18,6 @@ const bad_two : u32 = { const bad_three : u32 = { { valid(); - //~^ ERROR statements in constants are unstable 0 } }; @@ -30,7 +25,6 @@ const bad_three : u32 = { static bad_four : u32 = { { 5; - //~^ ERROR statements in statics are unstable 0 } }; @@ -39,7 +33,6 @@ static bad_five : u32 = { { invalid(); //~^ ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants - //~| ERROR statements in statics are unstable 0 } }; @@ -47,7 +40,6 @@ static bad_five : u32 = { static bad_six : u32 = { { valid(); - //~^ ERROR statements in statics are unstable 0 } }; @@ -55,7 +47,6 @@ static bad_six : u32 = { static mut bad_seven : u32 = { { 5; - //~^ ERROR statements in statics are unstable 0 } }; @@ -63,8 +54,7 @@ static mut bad_seven : u32 = { static mut bad_eight : u32 = { { invalid(); - //~^ ERROR statements in statics are unstable - //~| ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants + //~^ ERROR: calls in statics are limited to constant functions, tuple structs and tuple variants 0 } }; @@ -72,7 +62,6 @@ static mut bad_eight : u32 = { static mut bad_nine : u32 = { { valid(); - //~^ ERROR statements in statics are unstable 0 } }; diff --git a/src/test/ui/issues/issue-32829-2.stderr b/src/test/ui/issues/issue-32829-2.stderr index 7fe0261281830..8d7423f29ae97 100644 --- a/src/test/ui/issues/issue-32829-2.stderr +++ b/src/test/ui/issues/issue-32829-2.stderr @@ -1,94 +1,21 @@ -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:7:9 - | -LL | 5; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-32829-2.rs:15:9 + --> $DIR/issue-32829-2.rs:12:9 | LL | invalid(); | ^^^^^^^^^ -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:15:9 - | -LL | invalid(); - | ^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in constants are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:24:9 - | -LL | valid(); - | ^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:32:9 - | -LL | 5; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-32829-2.rs:40:9 + --> $DIR/issue-32829-2.rs:34:9 | LL | invalid(); | ^^^^^^^^^ -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:40:9 - | -LL | invalid(); - | ^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:49:9 - | -LL | valid(); - | ^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:57:9 - | -LL | 5; - | ^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-32829-2.rs:65:9 + --> $DIR/issue-32829-2.rs:56:9 | LL | invalid(); | ^^^^^^^^^ -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:65:9 - | -LL | invalid(); - | ^^^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error[E0658]: statements in statics are unstable (see issue #48821) - --> $DIR/issue-32829-2.rs:74:9 - | -LL | valid(); - | ^^^^^^^ - | - = help: add #![feature(const_let)] to the crate attributes to enable - -error: aborting due to 12 previous errors +error: aborting due to 3 previous errors -Some errors occurred: E0015, E0658. -For more information about an error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-37550.rs b/src/test/ui/issues/issue-37550.rs index 12282f3e54887..505c030b96712 100644 --- a/src/test/ui/issues/issue-37550.rs +++ b/src/test/ui/issues/issue-37550.rs @@ -1,6 +1,6 @@ const fn x() { - let t = true; //~ ERROR local variables in const fn - let x = || t; + let t = true; + let x = || t; //~ ERROR function pointers in const fn are unstable } fn main() {} diff --git a/src/test/ui/issues/issue-37550.stderr b/src/test/ui/issues/issue-37550.stderr index d42f72ad3fac8..d2b03416cb73c 100644 --- a/src/test/ui/issues/issue-37550.stderr +++ b/src/test/ui/issues/issue-37550.stderr @@ -1,7 +1,7 @@ -error: local variables in const fn are unstable - --> $DIR/issue-37550.rs:2:9 +error: function pointers in const fn are unstable + --> $DIR/issue-37550.rs:3:9 | -LL | let t = true; //~ ERROR local variables in const fn +LL | let x = || t; //~ ERROR function pointers in const fn are unstable | ^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-7364.rs b/src/test/ui/issues/issue-7364.rs index 3f9c2ef48a7af..52ec9e42be782 100644 --- a/src/test/ui/issues/issue-7364.rs +++ b/src/test/ui/issues/issue-7364.rs @@ -6,5 +6,6 @@ use std::cell::RefCell; static boxed: Box> = box RefCell::new(0); //~^ ERROR allocations are not allowed in statics //~| ERROR `std::cell::RefCell` cannot be shared between threads safely [E0277] +//~| ERROR static contains unimplemented expression type fn main() { } diff --git a/src/test/ui/issues/issue-7364.stderr b/src/test/ui/issues/issue-7364.stderr index 0e4d6ff1d71fa..52a99ce36b870 100644 --- a/src/test/ui/issues/issue-7364.stderr +++ b/src/test/ui/issues/issue-7364.stderr @@ -4,6 +4,12 @@ error[E0010]: allocations are not allowed in statics LL | static boxed: Box> = box RefCell::new(0); | ^^^^^^^^^^^^^^^^^^^ allocation not allowed in statics +error[E0019]: static contains unimplemented expression type + --> $DIR/issue-7364.rs:6:41 + | +LL | static boxed: Box> = box RefCell::new(0); + | ^^^^^^^^^^^^^^^ + error[E0277]: `std::cell::RefCell` cannot be shared between threads safely --> $DIR/issue-7364.rs:6:1 | @@ -15,7 +21,7 @@ LL | static boxed: Box> = box RefCell::new(0); = note: required because it appears within the type `std::boxed::Box>` = note: shared static variables must have a type that implements `Sync` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -Some errors occurred: E0010, E0277. +Some errors occurred: E0010, E0019, E0277. For more information about an error, try `rustc --explain E0010`. diff --git a/src/test/ui/static/static-mut-not-constant.rs b/src/test/ui/static/static-mut-not-constant.rs index 2091fffd418ee..84d401c9fa61d 100644 --- a/src/test/ui/static/static-mut-not-constant.rs +++ b/src/test/ui/static/static-mut-not-constant.rs @@ -2,5 +2,6 @@ static mut a: Box = box 3; //~^ ERROR allocations are not allowed in statics +//~| ERROR static contains unimplemented expression type fn main() {} diff --git a/src/test/ui/static/static-mut-not-constant.stderr b/src/test/ui/static/static-mut-not-constant.stderr index a0fa245156f87..d2c6ba6a2f85a 100644 --- a/src/test/ui/static/static-mut-not-constant.stderr +++ b/src/test/ui/static/static-mut-not-constant.stderr @@ -4,6 +4,13 @@ error[E0010]: allocations are not allowed in statics LL | static mut a: Box = box 3; | ^^^^^ allocation not allowed in statics -error: aborting due to previous error +error[E0019]: static contains unimplemented expression type + --> $DIR/static-mut-not-constant.rs:3:32 + | +LL | static mut a: Box = box 3; + | ^ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0010`. +Some errors occurred: E0010, E0019. +For more information about an error, try `rustc --explain E0010`. diff --git a/src/test/ui/underscore_const_names.rs b/src/test/ui/underscore_const_names.rs index 811d166ed65a7..1db022e886208 100644 --- a/src/test/ui/underscore_const_names.rs +++ b/src/test/ui/underscore_const_names.rs @@ -1,6 +1,5 @@ // compile-pass -#![feature(const_let)] #![feature(underscore_const_names)] trait Trt {} diff --git a/src/test/ui/unsafe/ranged_ints2_const.rs b/src/test/ui/unsafe/ranged_ints2_const.rs index a61e3329bdce8..788f49f743cda 100644 --- a/src/test/ui/unsafe/ranged_ints2_const.rs +++ b/src/test/ui/unsafe/ranged_ints2_const.rs @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, const_let, const_fn)] +#![feature(rustc_attrs)] #[rustc_layout_scalar_valid_range_start(1)] #[repr(transparent)] @@ -8,13 +8,13 @@ fn main() { const fn foo() -> NonZero { let mut x = unsafe { NonZero(1) }; - let y = &mut x.0; //~ ERROR references in constant functions may only refer to immutable + let y = &mut x.0; //~ ERROR references in const fn are unstable //~^ ERROR mutation of layout constrained field is unsafe unsafe { NonZero(1) } } const fn bar() -> NonZero { let mut x = unsafe { NonZero(1) }; - let y = unsafe { &mut x.0 }; //~ ERROR references in constant functions may only refer to immut + let y = unsafe { &mut x.0 }; //~ ERROR mutable references in const fn are unstable unsafe { NonZero(1) } } diff --git a/src/test/ui/unsafe/ranged_ints2_const.stderr b/src/test/ui/unsafe/ranged_ints2_const.stderr index f79792ffba9be..39a55190b17de 100644 --- a/src/test/ui/unsafe/ranged_ints2_const.stderr +++ b/src/test/ui/unsafe/ranged_ints2_const.stderr @@ -1,24 +1,23 @@ -error[E0017]: references in constant functions may only refer to immutable values - --> $DIR/ranged_ints2_const.rs:11:13 +error: mutable references in const fn are unstable + --> $DIR/ranged_ints2_const.rs:11:9 | -LL | let y = &mut x.0; //~ ERROR references in constant functions may only refer to immutable - | ^^^^^^^^ constant functions require immutable values +LL | let y = &mut x.0; //~ ERROR references in const fn are unstable + | ^ -error[E0017]: references in constant functions may only refer to immutable values - --> $DIR/ranged_ints2_const.rs:18:22 +error: mutable references in const fn are unstable + --> $DIR/ranged_ints2_const.rs:18:9 | -LL | let y = unsafe { &mut x.0 }; //~ ERROR references in constant functions may only refer to immut - | ^^^^^^^^ constant functions require immutable values +LL | let y = unsafe { &mut x.0 }; //~ ERROR mutable references in const fn are unstable + | ^ error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block --> $DIR/ranged_ints2_const.rs:11:13 | -LL | let y = &mut x.0; //~ ERROR references in constant functions may only refer to immutable +LL | let y = &mut x.0; //~ ERROR references in const fn are unstable | ^^^^^^^^ mutation of layout constrained field | = note: mutating layout constrained fields cannot statically be checked for valid values error: aborting due to 3 previous errors -Some errors occurred: E0017, E0133. -For more information about an error, try `rustc --explain E0017`. +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints3_const.rs b/src/test/ui/unsafe/ranged_ints3_const.rs index 6497b611224b6..7b03d8eda9380 100644 --- a/src/test/ui/unsafe/ranged_ints3_const.rs +++ b/src/test/ui/unsafe/ranged_ints3_const.rs @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, const_let, const_fn)] +#![feature(rustc_attrs)] use std::cell::Cell; diff --git a/src/test/ui/unsafe/ranged_ints4_const.rs b/src/test/ui/unsafe/ranged_ints4_const.rs index f589e4739baf1..f09168c3d3f9c 100644 --- a/src/test/ui/unsafe/ranged_ints4_const.rs +++ b/src/test/ui/unsafe/ranged_ints4_const.rs @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, const_let, const_fn)] +#![feature(rustc_attrs)] #[rustc_layout_scalar_valid_range_start(1)] #[repr(transparent)] diff --git a/src/test/ui/write-to-static-mut-in-static.rs b/src/test/ui/write-to-static-mut-in-static.rs index 3c34a7704e0df..43c63fed8cef1 100644 --- a/src/test/ui/write-to-static-mut-in-static.rs +++ b/src/test/ui/write-to-static-mut-in-static.rs @@ -1,5 +1,3 @@ -#![feature(const_let)] - pub static mut A: u32 = 0; pub static mut B: () = unsafe { A = 1; }; //~^ ERROR could not evaluate static initializer diff --git a/src/test/ui/write-to-static-mut-in-static.stderr b/src/test/ui/write-to-static-mut-in-static.stderr index 7be83b8dafcfd..eba1c609d2f83 100644 --- a/src/test/ui/write-to-static-mut-in-static.stderr +++ b/src/test/ui/write-to-static-mut-in-static.stderr @@ -1,23 +1,23 @@ error[E0080]: could not evaluate static initializer - --> $DIR/write-to-static-mut-in-static.rs:4:33 + --> $DIR/write-to-static-mut-in-static.rs:2:33 | LL | pub static mut B: () = unsafe { A = 1; }; | ^^^^^ tried to modify a static's initial value from another static's initializer error[E0391]: cycle detected when const-evaluating `C` - --> $DIR/write-to-static-mut-in-static.rs:7:34 + --> $DIR/write-to-static-mut-in-static.rs:5:34 | LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ^^^^^ | note: ...which requires const-evaluating `C`... - --> $DIR/write-to-static-mut-in-static.rs:7:1 + --> $DIR/write-to-static-mut-in-static.rs:5:1 | LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires const-evaluating `C`, completing the cycle note: cycle used when const-evaluating + checking `C` - --> $DIR/write-to-static-mut-in-static.rs:7:1 + --> $DIR/write-to-static-mut-in-static.rs:5:1 | LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^