diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index e1b605979972d..2cbf242fcf28d 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -317,7 +317,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { { self.error_emitted = Some(guar); } - self.check_op_spanned(ops::StaticAccess, span) } /// Returns whether this place can possibly escape the evaluation of the current const/static diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index df8313d0e7038..6eb33c29e1d89 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -16,7 +16,6 @@ use rustc_middle::ty::{ suggest_constraining_type_param, }; use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind}; -use rustc_session::parse::feature_err; use rustc_span::symbol::sym; use rustc_span::{BytePos, Pos, Span, Symbol}; use rustc_trait_selection::traits::SelectionContext; @@ -477,33 +476,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast { } } -/// An access to a (non-thread-local) `static`. -#[derive(Debug)] -pub(crate) struct StaticAccess; -impl<'tcx> NonConstOp<'tcx> for StaticAccess { - fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status { - if let hir::ConstContext::Static(_) = ccx.const_kind() { - Status::Allowed - } else { - Status::Unstable(sym::const_refs_to_static) - } - } - - #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable - fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { - let mut err = feature_err( - &ccx.tcx.sess, - sym::const_refs_to_static, - span, - format!("referencing statics in {}s is unstable", ccx.const_kind(),), - ); - err - .note("`static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.") - .help("to fix this, the value can be extracted to a `const` and then used."); - err - } -} - /// An access to a thread-local `static`. #[derive(Debug)] pub(crate) struct ThreadLocalAccess; diff --git a/compiler/rustc_error_codes/src/error_codes/E0013.md b/compiler/rustc_error_codes/src/error_codes/E0013.md index 9f4848343ff1c..c4d65225ece90 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0013.md +++ b/compiler/rustc_error_codes/src/error_codes/E0013.md @@ -5,7 +5,7 @@ variable cannot refer to a static variable. Erroneous code example: -```compile_fail,E0658 +``` static X: i32 = 42; const Y: i32 = X; ``` diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 70e92f545c639..5ff002dd7d2bf 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -151,6 +151,8 @@ declare_features! ( (accepted, const_raw_ptr_deref, "1.58.0", Some(51911)), /// Allows references to types with interior mutability within constants (accepted, const_refs_to_cell, "CURRENT_RUSTC_VERSION", Some(80384)), + /// Allows creating pointers and references to `static` items in constants. + (accepted, const_refs_to_static, "CURRENT_RUSTC_VERSION", Some(119618)), /// Allows implementing `Copy` for closures where possible (RFC 2132). (accepted, copy_closures, "1.26.0", Some(44490)), /// Allows `crate` in paths. diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 63b4b272f76c9..91b072b56db2b 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -407,8 +407,6 @@ declare_features! ( (unstable, const_for, "1.56.0", Some(87575)), /// Be more precise when looking for live drops in a const context. (unstable, const_precise_live_drops, "1.46.0", Some(73255)), - /// Allows creating pointers and references to `static` items in constants. - (unstable, const_refs_to_static, "1.78.0", Some(119618)), /// Allows `impl const Trait for T` syntax. (unstable, const_trait_impl, "1.42.0", Some(67792)), /// Allows the `?` operator in const contexts. diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 3879f350e9473..6b4c0e9c0b9b9 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -764,7 +764,6 @@ ui/consts/issue-46553.rs ui/consts/issue-47789.rs ui/consts/issue-50439.rs ui/consts/issue-52023-array-size-pointer-cast.rs -ui/consts/issue-52060.rs ui/consts/issue-54224.rs ui/consts/issue-54348.rs ui/consts/issue-54387.rs @@ -3830,7 +3829,6 @@ ui/stability-attribute/issue-28388-3.rs ui/stability-attribute/issue-99286-stable-intrinsics.rs ui/static/auxiliary/issue_24843.rs ui/static/issue-1660.rs -ui/static/issue-18118-2.rs ui/static/issue-18118.rs ui/static/issue-24446.rs ui/static/issue-24843.rs diff --git a/tests/ui/asm/aarch64/type-check-4.rs b/tests/ui/asm/aarch64/type-check-4.rs index 1169c3dcfa843..c24567bd5b002 100644 --- a/tests/ui/asm/aarch64/type-check-4.rs +++ b/tests/ui/asm/aarch64/type-check-4.rs @@ -1,31 +1,27 @@ //@ only-aarch64 -//@ compile-flags: -C target-feature=+neon +//@ build-fail -#![feature(repr_simd)] - -use std::arch::aarch64::float64x2_t; -use std::arch::{asm, global_asm}; - -#[repr(simd)] -#[derive(Copy, Clone)] -struct Simd256bit([f64; 4]); +use std::arch::global_asm; fn main() {} // Constants must be... constant -static S: i32 = 1; +static mut S: i32 = 1; const fn const_foo(x: i32) -> i32 { x } const fn const_bar(x: T) -> T { x } -global_asm!("{}", const S); -//~^ ERROR referencing statics +global_asm!("{}", const unsafe { S }); +//~^ ERROR: evaluation of constant value failed +//~| mutable global memory global_asm!("{}", const const_foo(0)); -global_asm!("{}", const const_foo(S)); -//~^ ERROR referencing statics +global_asm!("{}", const const_foo(unsafe { S })); +//~^ ERROR: evaluation of constant value failed +//~| mutable global memory global_asm!("{}", const const_bar(0)); -global_asm!("{}", const const_bar(S)); -//~^ ERROR referencing statics +global_asm!("{}", const const_bar(unsafe { S })); +//~^ ERROR: evaluation of constant value failed +//~| mutable global memory diff --git a/tests/ui/asm/aarch64/type-check-4.stderr b/tests/ui/asm/aarch64/type-check-4.stderr index 89eb8467cdefd..8c22dfcdb5ed6 100644 --- a/tests/ui/asm/aarch64/type-check-4.stderr +++ b/tests/ui/asm/aarch64/type-check-4.stderr @@ -1,39 +1,21 @@ -error[E0658]: referencing statics in constants is unstable - --> $DIR/type-check-4.rs:24:25 +error[E0080]: evaluation of constant value failed + --> $DIR/type-check-4.rs:17:34 | -LL | global_asm!("{}", const S); - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. +LL | global_asm!("{}", const unsafe { S }); + | ^ constant accesses mutable global memory -error[E0658]: referencing statics in constants is unstable - --> $DIR/type-check-4.rs:27:35 - | -LL | global_asm!("{}", const const_foo(S)); - | ^ +error[E0080]: evaluation of constant value failed + --> $DIR/type-check-4.rs:21:44 | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. +LL | global_asm!("{}", const const_foo(unsafe { S })); + | ^ constant accesses mutable global memory -error[E0658]: referencing statics in constants is unstable - --> $DIR/type-check-4.rs:30:35 - | -LL | global_asm!("{}", const const_bar(S)); - | ^ +error[E0080]: evaluation of constant value failed + --> $DIR/type-check-4.rs:25:44 | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. +LL | global_asm!("{}", const const_bar(unsafe { S })); + | ^ constant accesses mutable global memory error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/asm/const-refs-to-static.rs b/tests/ui/asm/const-refs-to-static.rs index 9fc010b576309..ce2c5b3246ec8 100644 --- a/tests/ui/asm/const-refs-to-static.rs +++ b/tests/ui/asm/const-refs-to-static.rs @@ -2,8 +2,6 @@ //@ ignore-nvptx64 //@ ignore-spirv -#![feature(const_refs_to_static)] - use std::arch::{asm, global_asm}; use std::ptr::addr_of; diff --git a/tests/ui/asm/const-refs-to-static.stderr b/tests/ui/asm/const-refs-to-static.stderr index 8fd69da0d1e92..10e1ca5bd6068 100644 --- a/tests/ui/asm/const-refs-to-static.stderr +++ b/tests/ui/asm/const-refs-to-static.stderr @@ -1,5 +1,5 @@ error: invalid type for `const` operand - --> $DIR/const-refs-to-static.rs:12:19 + --> $DIR/const-refs-to-static.rs:10:19 | LL | global_asm!("{}", const addr_of!(FOO)); | ^^^^^^------------- @@ -9,7 +9,7 @@ LL | global_asm!("{}", const addr_of!(FOO)); = help: `const` operands must be of an integer type error: invalid type for `const` operand - --> $DIR/const-refs-to-static.rs:17:25 + --> $DIR/const-refs-to-static.rs:15:25 | LL | unsafe { asm!("{}", const addr_of!(FOO)) }; | ^^^^^^------------- diff --git a/tests/ui/asm/x86_64/type-check-4.rs b/tests/ui/asm/x86_64/type-check-4.rs index 9503cd6d8ab2b..ebc6edc07e4cd 100644 --- a/tests/ui/asm/x86_64/type-check-4.rs +++ b/tests/ui/asm/x86_64/type-check-4.rs @@ -1,26 +1,27 @@ //@ only-x86_64 -//@ compile-flags: -C target-feature=+avx512f +//@ build-fail -use std::arch::{asm, global_asm}; - -use std::arch::x86_64::{_mm256_setzero_ps, _mm_setzero_ps}; +use std::arch::global_asm; fn main() {} // Constants must be... constant -static S: i32 = 1; +static mut S: i32 = 1; const fn const_foo(x: i32) -> i32 { x } const fn const_bar(x: T) -> T { x } -global_asm!("{}", const S); -//~^ ERROR referencing statics +global_asm!("{}", const unsafe { S }); +//~^ ERROR evaluation of constant value failed +//~| mutable global memory global_asm!("{}", const const_foo(0)); -global_asm!("{}", const const_foo(S)); -//~^ ERROR referencing statics +global_asm!("{}", const const_foo(unsafe { S })); +//~^ ERROR evaluation of constant value failed +//~| mutable global memory global_asm!("{}", const const_bar(0)); -global_asm!("{}", const const_bar(S)); -//~^ ERROR referencing statics +global_asm!("{}", const const_bar(unsafe { S })); +//~^ ERROR evaluation of constant value failed +//~| mutable global memory diff --git a/tests/ui/asm/x86_64/type-check-4.stderr b/tests/ui/asm/x86_64/type-check-4.stderr index f1bbc9e7d33de..8c22dfcdb5ed6 100644 --- a/tests/ui/asm/x86_64/type-check-4.stderr +++ b/tests/ui/asm/x86_64/type-check-4.stderr @@ -1,39 +1,21 @@ -error[E0658]: referencing statics in constants is unstable - --> $DIR/type-check-4.rs:19:25 +error[E0080]: evaluation of constant value failed + --> $DIR/type-check-4.rs:17:34 | -LL | global_asm!("{}", const S); - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. +LL | global_asm!("{}", const unsafe { S }); + | ^ constant accesses mutable global memory -error[E0658]: referencing statics in constants is unstable - --> $DIR/type-check-4.rs:22:35 - | -LL | global_asm!("{}", const const_foo(S)); - | ^ +error[E0080]: evaluation of constant value failed + --> $DIR/type-check-4.rs:21:44 | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. +LL | global_asm!("{}", const const_foo(unsafe { S })); + | ^ constant accesses mutable global memory -error[E0658]: referencing statics in constants is unstable - --> $DIR/type-check-4.rs:25:35 - | -LL | global_asm!("{}", const const_bar(S)); - | ^ +error[E0080]: evaluation of constant value failed + --> $DIR/type-check-4.rs:25:44 | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. +LL | global_asm!("{}", const const_bar(unsafe { S })); + | ^ constant accesses mutable global memory error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-fn-not-safe-for-const.rs b/tests/ui/consts/const-fn-not-safe-for-const.rs index 6d8404880ca30..8a0cd86819edf 100644 --- a/tests/ui/consts/const-fn-not-safe-for-const.rs +++ b/tests/ui/consts/const-fn-not-safe-for-const.rs @@ -18,12 +18,10 @@ static Y: u32 = 0; const fn get_Y() -> u32 { Y - //~^ ERROR referencing statics in constant functions } const fn get_Y_addr() -> &'static u32 { &Y - //~^ ERROR referencing statics in constant functions } const fn get() -> u32 { diff --git a/tests/ui/consts/const-fn-not-safe-for-const.stderr b/tests/ui/consts/const-fn-not-safe-for-const.stderr index 7d7e94da86f7a..674e05a0ba99a 100644 --- a/tests/ui/consts/const-fn-not-safe-for-const.stderr +++ b/tests/ui/consts/const-fn-not-safe-for-const.stderr @@ -6,31 +6,6 @@ LL | random() | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error[E0658]: referencing statics in constant functions is unstable - --> $DIR/const-fn-not-safe-for-const.rs:20:5 - | -LL | Y - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error[E0658]: referencing statics in constant functions is unstable - --> $DIR/const-fn-not-safe-for-const.rs:25:6 - | -LL | &Y - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: 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/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs b/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs index 7bf178484cc76..2539fcccb8486 100644 --- a/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs +++ b/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs @@ -1,7 +1,6 @@ //@ normalize-stderr-test: "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" //@ normalize-stderr-test: "( 0x[0-9a-f][0-9a-f] │)? ([0-9a-f][0-9a-f] |__ |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> " HEX_DUMP" //@ normalize-stderr-test: "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP" -#![feature(const_refs_to_static)] use std::sync::Mutex; diff --git a/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.stderr b/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.stderr index 4ea6fa62475e8..aebac56f8c5cf 100644 --- a/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.stderr +++ b/tests/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/mut_ref_in_final_dynamic_check.rs:19:1 + --> $DIR/mut_ref_in_final_dynamic_check.rs:18:1 | LL | const MUT: Option<&mut i32> = helper(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..0: encountered reference to mutable memory in `const` @@ -10,7 +10,7 @@ LL | const MUT: Option<&mut i32> = helper(); } error[E0080]: it is undefined behavior to use this value - --> $DIR/mut_ref_in_final_dynamic_check.rs:26:1 + --> $DIR/mut_ref_in_final_dynamic_check.rs:25:1 | LL | const INT2PTR: Option<&mut i32> = helper_int2ptr(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..0: encountered a dangling reference (0x2a[noalloc] has no provenance) @@ -21,7 +21,7 @@ LL | const INT2PTR: Option<&mut i32> = helper_int2ptr(); } error[E0080]: it is undefined behavior to use this value - --> $DIR/mut_ref_in_final_dynamic_check.rs:28:1 + --> $DIR/mut_ref_in_final_dynamic_check.rs:27:1 | LL | static INT2PTR_STATIC: Option<&mut i32> = helper_int2ptr(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..0: encountered a dangling reference (0x2a[noalloc] has no provenance) @@ -32,7 +32,7 @@ LL | static INT2PTR_STATIC: Option<&mut i32> = helper_int2ptr(); } error[E0080]: it is undefined behavior to use this value - --> $DIR/mut_ref_in_final_dynamic_check.rs:35:1 + --> $DIR/mut_ref_in_final_dynamic_check.rs:34:1 | LL | const DANGLING: Option<&mut i32> = helper_dangling(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..0: encountered a dangling reference (use-after-free) @@ -43,7 +43,7 @@ LL | const DANGLING: Option<&mut i32> = helper_dangling(); } error[E0080]: it is undefined behavior to use this value - --> $DIR/mut_ref_in_final_dynamic_check.rs:36:1 + --> $DIR/mut_ref_in_final_dynamic_check.rs:35:1 | LL | static DANGLING_STATIC: Option<&mut i32> = helper_dangling(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ..0: encountered a dangling reference (use-after-free) diff --git a/tests/ui/consts/const-ref-to-static-linux-vtable.rs b/tests/ui/consts/const-ref-to-static-linux-vtable.rs index b9d29d0c1f43e..87af63d41ab6e 100644 --- a/tests/ui/consts/const-ref-to-static-linux-vtable.rs +++ b/tests/ui/consts/const-ref-to-static-linux-vtable.rs @@ -1,6 +1,6 @@ -//@check-pass +//@ check-pass //! This is the reduced version of the "Linux kernel vtable" use-case. -#![feature(const_refs_to_static)] + use std::ptr::addr_of_mut; #[repr(C)] diff --git a/tests/ui/consts/const_refs_to_static-ice-121413.rs b/tests/ui/consts/const_refs_to_static-ice-121413.rs index 8fc3912efd08e..5b2d27ae85342 100644 --- a/tests/ui/consts/const_refs_to_static-ice-121413.rs +++ b/tests/ui/consts/const_refs_to_static-ice-121413.rs @@ -3,7 +3,6 @@ // issue: rust-lang/rust#121413 //@ compile-flags: -Zextra-const-ub-checks // ignore-tidy-linelength -#![feature(const_refs_to_static)] const REF_INTERIOR_MUT: &usize = { //~^ HELP consider importing this struct static FOO: Sync = AtomicUsize::new(0); diff --git a/tests/ui/consts/const_refs_to_static-ice-121413.stderr b/tests/ui/consts/const_refs_to_static-ice-121413.stderr index fbe32a70293aa..c977c698a92e9 100644 --- a/tests/ui/consts/const_refs_to_static-ice-121413.stderr +++ b/tests/ui/consts/const_refs_to_static-ice-121413.stderr @@ -1,5 +1,5 @@ error[E0433]: failed to resolve: use of undeclared type `AtomicUsize` - --> $DIR/const_refs_to_static-ice-121413.rs:9:24 + --> $DIR/const_refs_to_static-ice-121413.rs:8:24 | LL | static FOO: Sync = AtomicUsize::new(0); | ^^^^^^^^^^^ use of undeclared type `AtomicUsize` @@ -10,7 +10,7 @@ LL + use std::sync::atomic::AtomicUsize; | warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/const_refs_to_static-ice-121413.rs:9:17 + --> $DIR/const_refs_to_static-ice-121413.rs:8:17 | LL | static FOO: Sync = AtomicUsize::new(0); | ^^^^ @@ -24,7 +24,7 @@ LL | static FOO: dyn Sync = AtomicUsize::new(0); | +++ error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time - --> $DIR/const_refs_to_static-ice-121413.rs:9:17 + --> $DIR/const_refs_to_static-ice-121413.rs:8:17 | LL | static FOO: Sync = AtomicUsize::new(0); | ^^^^ doesn't have a size known at compile-time @@ -32,7 +32,7 @@ LL | static FOO: Sync = AtomicUsize::new(0); = help: the trait `Sized` is not implemented for `(dyn Sync + 'static)` error[E0277]: the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time - --> $DIR/const_refs_to_static-ice-121413.rs:9:24 + --> $DIR/const_refs_to_static-ice-121413.rs:8:24 | LL | static FOO: Sync = AtomicUsize::new(0); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time diff --git a/tests/ui/consts/const_refs_to_static.rs b/tests/ui/consts/const_refs_to_static.rs index f41725b786eb3..3c59697e8eda4 100644 --- a/tests/ui/consts/const_refs_to_static.rs +++ b/tests/ui/consts/const_refs_to_static.rs @@ -1,5 +1,4 @@ //@ run-pass -#![feature(const_refs_to_static)] static S: i32 = 0; static mut S_MUT: i32 = 0; diff --git a/tests/ui/consts/const_refs_to_static_fail.rs b/tests/ui/consts/const_refs_to_static_fail.rs index a69902c34392d..44e848ab63777 100644 --- a/tests/ui/consts/const_refs_to_static_fail.rs +++ b/tests/ui/consts/const_refs_to_static_fail.rs @@ -1,6 +1,8 @@ //@ normalize-stderr-test: "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" //@ normalize-stderr-test: "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> "HEX_DUMP" -#![feature(const_refs_to_static, sync_unsafe_cell)] + +#![feature(sync_unsafe_cell)] + use std::cell::SyncUnsafeCell; static S: SyncUnsafeCell = SyncUnsafeCell::new(0); diff --git a/tests/ui/consts/const_refs_to_static_fail.stderr b/tests/ui/consts/const_refs_to_static_fail.stderr index cdabd86b183e9..297561dbcf137 100644 --- a/tests/ui/consts/const_refs_to_static_fail.stderr +++ b/tests/ui/consts/const_refs_to_static_fail.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/const_refs_to_static_fail.rs:9:1 + --> $DIR/const_refs_to_static_fail.rs:11:1 | LL | const C1: &SyncUnsafeCell = &S; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` @@ -10,13 +10,13 @@ LL | const C1: &SyncUnsafeCell = &S; } note: erroneous constant encountered - --> $DIR/const_refs_to_static_fail.rs:12:14 + --> $DIR/const_refs_to_static_fail.rs:14:14 | LL | assert!(*C1.get() == 0); | ^^ error[E0080]: evaluation of constant value failed - --> $DIR/const_refs_to_static_fail.rs:16:13 + --> $DIR/const_refs_to_static_fail.rs:18:13 | LL | assert!(*C2 == 0); | ^^^ constant accesses mutable global memory diff --git a/tests/ui/consts/const_refs_to_static_fail_invalid.rs b/tests/ui/consts/const_refs_to_static_fail_invalid.rs index c58606d2ebb5f..a160862a0fa69 100644 --- a/tests/ui/consts/const_refs_to_static_fail_invalid.rs +++ b/tests/ui/consts/const_refs_to_static_fail_invalid.rs @@ -1,6 +1,5 @@ //@ normalize-stderr-test: "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" //@ normalize-stderr-test: "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> "HEX_DUMP" -#![feature(const_refs_to_static)] #![allow(static_mut_refs)] fn invalid() { diff --git a/tests/ui/consts/const_refs_to_static_fail_invalid.stderr b/tests/ui/consts/const_refs_to_static_fail_invalid.stderr index d5bb4847746eb..0153f501174b2 100644 --- a/tests/ui/consts/const_refs_to_static_fail_invalid.stderr +++ b/tests/ui/consts/const_refs_to_static_fail_invalid.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/const_refs_to_static_fail_invalid.rs:9:5 + --> $DIR/const_refs_to_static_fail_invalid.rs:8:5 | LL | const C: &bool = unsafe { std::mem::transmute(&S) }; | ^^^^^^^^^^^^^^ constructing invalid value at .: encountered 0x0a, but expected a boolean @@ -10,7 +10,7 @@ LL | const C: &bool = unsafe { std::mem::transmute(&S) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/const_refs_to_static_fail_invalid.rs:25:5 + --> $DIR/const_refs_to_static_fail_invalid.rs:24:5 | LL | const C: &i8 = unsafe { &S }; | ^^^^^^^^^^^^ constructing invalid value: encountered reference to `extern` static in `const` @@ -21,7 +21,7 @@ LL | const C: &i8 = unsafe { &S }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/const_refs_to_static_fail_invalid.rs:39:5 + --> $DIR/const_refs_to_static_fail_invalid.rs:38:5 | LL | const C: &i32 = unsafe { &S_MUT }; | ^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` @@ -32,19 +32,19 @@ LL | const C: &i32 = unsafe { &S_MUT }; } error: could not evaluate constant pattern - --> $DIR/const_refs_to_static_fail_invalid.rs:15:9 + --> $DIR/const_refs_to_static_fail_invalid.rs:14:9 | LL | C => {} | ^ error: could not evaluate constant pattern - --> $DIR/const_refs_to_static_fail_invalid.rs:31:9 + --> $DIR/const_refs_to_static_fail_invalid.rs:30:9 | LL | C => {} | ^ error: could not evaluate constant pattern - --> $DIR/const_refs_to_static_fail_invalid.rs:46:9 + --> $DIR/const_refs_to_static_fail_invalid.rs:45:9 | LL | C => {} | ^ diff --git a/tests/ui/consts/issue-17718-const-bad-values.rs b/tests/ui/consts/issue-17718-const-bad-values.rs index 52f8c9bf149a6..fca6cb0853791 100644 --- a/tests/ui/consts/issue-17718-const-bad-values.rs +++ b/tests/ui/consts/issue-17718-const-bad-values.rs @@ -1,10 +1,15 @@ +//@ normalize-stderr-32bit: "\(size: \d+, align: \d+\)" -> "(size: $$PTR, align: $$PTR)" +//@ normalize-stderr-64bit: "\(size: \d+, align: \d+\)" -> "(size: $$PTR, align: $$PTR)" +//@ normalize-stderr-test: "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> "HEX_DUMP" + #![allow(static_mut_refs)] const C1: &'static mut [usize] = &mut []; //~^ ERROR: mutable references are not allowed -static mut S: usize = 3; -const C2: &'static mut usize = unsafe { &mut S }; -//~^ ERROR: referencing statics in constants +static mut S: i32 = 3; +const C2: &'static mut i32 = unsafe { &mut S }; +//~^ ERROR: it is undefined behavior to use this value +//~| reference to mutable memory fn main() {} diff --git a/tests/ui/consts/issue-17718-const-bad-values.stderr b/tests/ui/consts/issue-17718-const-bad-values.stderr index 57fcb1c7e9a52..102491e90bac1 100644 --- a/tests/ui/consts/issue-17718-const-bad-values.stderr +++ b/tests/ui/consts/issue-17718-const-bad-values.stderr @@ -1,22 +1,21 @@ error[E0764]: mutable references are not allowed in the final value of constants - --> $DIR/issue-17718-const-bad-values.rs:3:34 + --> $DIR/issue-17718-const-bad-values.rs:7:34 | LL | const C1: &'static mut [usize] = &mut []; | ^^^^^^^ -error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-17718-const-bad-values.rs:7:46 +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-17718-const-bad-values.rs:11:1 | -LL | const C2: &'static mut usize = unsafe { &mut S }; - | ^ +LL | const C2: &'static mut i32 = unsafe { &mut S }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: $PTR, align: $PTR) { + HEX_DUMP + } error: aborting due to 2 previous errors -Some errors have detailed explanations: E0658, E0764. -For more information about an error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0080, E0764. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/issue-17718-references.rs b/tests/ui/consts/issue-17718-references.rs index 6a8955f463433..120ec28c40490 100644 --- a/tests/ui/consts/issue-17718-references.rs +++ b/tests/ui/consts/issue-17718-references.rs @@ -1,23 +1,26 @@ +//@ check-pass #![allow(warnings)] -struct Struct { a: usize } +struct Struct { + a: usize, +} const C: usize = 1; static S: usize = 1; const T1: &'static usize = &C; -const T2: &'static usize = &S; //~ ERROR: referencing statics in constants +const T2: &'static usize = &S; static T3: &'static usize = &C; static T4: &'static usize = &S; const T5: usize = C; -const T6: usize = S; //~ ERROR: referencing statics in constants +const T6: usize = S; static T7: usize = C; static T8: usize = S; const T9: Struct = Struct { a: C }; const T10: Struct = Struct { a: S }; -//~^ ERROR: referencing statics in constants + static T11: Struct = Struct { a: C }; static T12: Struct = Struct { a: S }; diff --git a/tests/ui/consts/issue-17718-references.stderr b/tests/ui/consts/issue-17718-references.stderr deleted file mode 100644 index 8b57220378123..0000000000000 --- a/tests/ui/consts/issue-17718-references.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-17718-references.rs:9:29 - | -LL | const T2: &'static usize = &S; - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-17718-references.rs:14:19 - | -LL | const T6: usize = S; - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-17718-references.rs:19:33 - | -LL | const T10: Struct = Struct { a: S }; - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/consts/issue-52060.rs b/tests/ui/consts/issue-52060.rs deleted file mode 100644 index 0f16ede040010..0000000000000 --- a/tests/ui/consts/issue-52060.rs +++ /dev/null @@ -1,7 +0,0 @@ -// Regression test for https://github.com/rust-lang/rust/issues/52060 -// The compiler shouldn't ICE in this case -static A: &'static [u32] = &[1]; -static B: [u32; 1] = [0; A.len()]; -//~^ ERROR referencing statics in constants - -fn main() {} diff --git a/tests/ui/consts/issue-52060.stderr b/tests/ui/consts/issue-52060.stderr deleted file mode 100644 index 644a5314622d9..0000000000000 --- a/tests/ui/consts/issue-52060.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-52060.rs:4:26 - | -LL | static B: [u32; 1] = [0; A.len()]; - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/consts/min_const_fn/min_const_fn.rs b/tests/ui/consts/min_const_fn/min_const_fn.rs index ed5aa40b66c38..e6d9d184e041a 100644 --- a/tests/ui/consts/min_const_fn/min_const_fn.rs +++ b/tests/ui/consts/min_const_fn/min_const_fn.rs @@ -74,8 +74,8 @@ const fn foo11_2(t: T) -> T { t } // not ok static BAR: u32 = 42; -const fn foo25() -> u32 { BAR } //~ ERROR referencing statics in constant functions -const fn foo26() -> &'static u32 { &BAR } //~ ERROR referencing statics in constant functions +const fn foo25() -> u32 { BAR } +const fn foo26() -> &'static u32 { &BAR } const fn foo30(x: *const u32) -> usize { x as usize } //~^ ERROR pointers cannot be cast to integers const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } } diff --git a/tests/ui/consts/min_const_fn/min_const_fn.stderr b/tests/ui/consts/min_const_fn/min_const_fn.stderr index c02f8c76d4418..0e939e5121aa9 100644 --- a/tests/ui/consts/min_const_fn/min_const_fn.stderr +++ b/tests/ui/consts/min_const_fn/min_const_fn.stderr @@ -22,30 +22,6 @@ LL | const fn into_inner_s(self) -> T { self.0 } | | | the destructor for this type cannot be evaluated in constant functions -error[E0658]: referencing statics in constant functions is unstable - --> $DIR/min_const_fn.rs:77:27 - | -LL | const fn foo25() -> u32 { BAR } - | ^^^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error[E0658]: referencing statics in constant functions is unstable - --> $DIR/min_const_fn.rs:78:37 - | -LL | const fn foo26() -> &'static u32 { &BAR } - | ^^^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - error: pointers cannot be cast to integers during const eval --> $DIR/min_const_fn.rs:79:42 | @@ -98,7 +74,6 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {} | | | the destructor for this type cannot be evaluated in constant functions -error: aborting due to 11 previous errors +error: aborting due to 9 previous errors -Some errors have detailed explanations: E0493, E0658. -For more information about an error, try `rustc --explain E0493`. +For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static.stderr index df910546d11ad..f8e0606fbd778 100644 --- a/tests/ui/consts/miri_unleashed/const_refers_to_static.stderr +++ b/tests/ui/consts/miri_unleashed/const_refers_to_static.stderr @@ -29,36 +29,11 @@ LL | const REF_INTERIOR_MUT: &usize = { warning: skipping const checks | -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static.rs:10:5 - | -LL | FOO.fetch_add(1, Ordering::Relaxed) - | ^^^ help: skipping check that does not even have a feature gate --> $DIR/const_refers_to_static.rs:10:5 | LL | FOO.fetch_add(1, Ordering::Relaxed) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static.rs:15:17 - | -LL | unsafe { *(&FOO as *const _ as *const usize) } - | ^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static.rs:19:32 - | -LL | const READ_MUT: u32 = unsafe { MUTABLE }; - | ^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static.rs:25:18 - | -LL | unsafe { &*(&FOO as *const _ as *const usize) } - | ^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static.rs:30:25 - | -LL | const REF_IMMUT: &u8 = &MY_STATIC; - | ^^^^^^^^^ error: aborting due to 4 previous errors; 1 warning emitted diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr index 7a7b7bc57da72..147d3f238f777 100644 --- a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr +++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr @@ -61,29 +61,6 @@ error: could not evaluate constant pattern LL | U8_MUT3 => true, | ^^^^^^^ -warning: skipping const checks - | -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static_cross_crate.rs:14:15 - | -LL | unsafe { &static_cross_crate::ZERO } - | ^^^^^^^^^^^^^^^^^^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static_cross_crate.rs:19:15 - | -LL | unsafe { &static_cross_crate::ZERO[0] } - | ^^^^^^^^^^^^^^^^^^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static_cross_crate.rs:25:17 - | -LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/const_refers_to_static_cross_crate.rs:29:15 - | -LL | match static_cross_crate::OPT_ZERO { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors; 1 warning emitted +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/miri_unleashed/mutable_references.rs b/tests/ui/consts/miri_unleashed/mutable_references.rs index 6ac61e6700160..a60058cc5c01b 100644 --- a/tests/ui/consts/miri_unleashed/mutable_references.rs +++ b/tests/ui/consts/miri_unleashed/mutable_references.rs @@ -27,9 +27,12 @@ const BLUNT: &mut i32 = &mut 42; //~^ ERROR: it is undefined behavior to use this value //~| pointing to read-only memory -const SUBTLE: &mut i32 = unsafe { static mut STATIC: i32 = 0; &mut STATIC }; -//~^ ERROR: it is undefined behavior to use this value -//~| static +const SUBTLE: &mut i32 = unsafe { + //~^ ERROR: it is undefined behavior to use this value + //~| constructing invalid value: encountered reference to mutable memory in `const` + static mut STATIC: i32 = 0; + &mut STATIC +}; // # Interior mutability @@ -105,7 +108,6 @@ const RAW_MUT_CAST: SyncPtr = SyncPtr { x: &mut 42 as *mut _ as *const _ }; const RAW_MUT_COERCE: SyncPtr = SyncPtr { x: &mut 0 }; //~^ ERROR mutable pointer in final value - fn main() { unsafe { *MEH.x.get() = 99; diff --git a/tests/ui/consts/miri_unleashed/mutable_references.stderr b/tests/ui/consts/miri_unleashed/mutable_references.stderr index 874dd0389d455..ce5cedac8bcd3 100644 --- a/tests/ui/consts/miri_unleashed/mutable_references.stderr +++ b/tests/ui/consts/miri_unleashed/mutable_references.stderr @@ -46,7 +46,7 @@ LL | const BLUNT: &mut i32 = &mut 42; error[E0080]: it is undefined behavior to use this value --> $DIR/mutable_references.rs:30:1 | -LL | const SUBTLE: &mut i32 = unsafe { static mut STATIC: i32 = 0; &mut STATIC }; +LL | const SUBTLE: &mut i32 = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. @@ -55,7 +55,7 @@ LL | const SUBTLE: &mut i32 = unsafe { static mut STATIC: i32 = 0; &mut STATIC } } error[E0080]: it is undefined behavior to use this value - --> $DIR/mutable_references.rs:40:1 + --> $DIR/mutable_references.rs:43:1 | LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) }; | ^^^^^^^^^^^^^^^ constructing invalid value at .x.: encountered `UnsafeCell` in read-only memory @@ -66,7 +66,7 @@ LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/mutable_references.rs:46:1 + --> $DIR/mutable_references.rs:49:1 | LL | const MUH: Meh = Meh { | ^^^^^^^^^^^^^^ constructing invalid value at .x.: encountered `UnsafeCell` in read-only memory @@ -77,7 +77,7 @@ LL | const MUH: Meh = Meh { } error[E0080]: it is undefined behavior to use this value - --> $DIR/mutable_references.rs:58:1 + --> $DIR/mutable_references.rs:61:1 | LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at ...x: encountered `UnsafeCell` in read-only memory @@ -88,7 +88,7 @@ LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/mutable_references.rs:65:1 + --> $DIR/mutable_references.rs:68:1 | LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory @@ -99,7 +99,7 @@ LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const } error[E0080]: it is undefined behavior to use this value - --> $DIR/mutable_references.rs:72:1 + --> $DIR/mutable_references.rs:75:1 | LL | const POINTS_TO_MUTABLE: &i32 = unsafe { &MUTABLE }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` @@ -110,37 +110,37 @@ LL | const POINTS_TO_MUTABLE: &i32 = unsafe { &MUTABLE }; } error[E0080]: evaluation of constant value failed - --> $DIR/mutable_references.rs:75:43 + --> $DIR/mutable_references.rs:78:43 | LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF }; | ^^^^^^^^^^^^^ constant accesses mutable global memory error: encountered mutable pointer in final value of constant - --> $DIR/mutable_references.rs:79:1 + --> $DIR/mutable_references.rs:82:1 | LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: encountered mutable pointer in final value of constant - --> $DIR/mutable_references.rs:82:1 + --> $DIR/mutable_references.rs:85:1 | LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: encountered mutable pointer in final value of constant - --> $DIR/mutable_references.rs:102:1 + --> $DIR/mutable_references.rs:105:1 | LL | const RAW_MUT_CAST: SyncPtr = SyncPtr { x: &mut 42 as *mut _ as *const _ }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: encountered mutable pointer in final value of constant - --> $DIR/mutable_references.rs:105:1 + --> $DIR/mutable_references.rs:108:1 | LL | const RAW_MUT_COERCE: SyncPtr = SyncPtr { x: &mut 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item - --> $DIR/mutable_references.rs:113:5 + --> $DIR/mutable_references.rs:115:5 | LL | *OH_YES = 99; | ^^^^^^^^^^^^ cannot assign @@ -172,63 +172,48 @@ help: skipping check that does not even have a feature gate | LL | const BLUNT: &mut i32 = &mut 42; | ^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/mutable_references.rs:30:68 - | -LL | const SUBTLE: &mut i32 = unsafe { static mut STATIC: i32 = 0; &mut STATIC }; - | ^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:40:28 + --> $DIR/mutable_references.rs:43:28 | LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) }; | ^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:49:8 + --> $DIR/mutable_references.rs:52:8 | LL | x: &UnsafeCell::new(42), | ^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:58:27 + --> $DIR/mutable_references.rs:61:27 | LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/mutable_references.rs:72:43 - | -LL | const POINTS_TO_MUTABLE: &i32 = unsafe { &MUTABLE }; - | ^^^^^^^ -help: skipping check for `const_refs_to_static` feature - --> $DIR/mutable_references.rs:75:45 - | -LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF }; - | ^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:79:45 + --> $DIR/mutable_references.rs:82:45 | LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _; | ^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:82:46 + --> $DIR/mutable_references.rs:85:46 | LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _; | ^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:87:47 + --> $DIR/mutable_references.rs:90:47 | LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; | ^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:99:51 + --> $DIR/mutable_references.rs:102:51 | LL | const RAW_SYNC: SyncPtr = SyncPtr { x: &AtomicI32::new(42) }; | ^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:102:49 + --> $DIR/mutable_references.rs:105:49 | LL | const RAW_MUT_CAST: SyncPtr = SyncPtr { x: &mut 42 as *mut _ as *const _ }; | ^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:105:51 + --> $DIR/mutable_references.rs:108:51 | LL | const RAW_MUT_COERCE: SyncPtr = SyncPtr { x: &mut 0 }; | ^^^^^^ diff --git a/tests/ui/consts/no-ice-from-static-in-const-issue-52060.rs b/tests/ui/consts/no-ice-from-static-in-const-issue-52060.rs new file mode 100644 index 0000000000000..e0f9e462d32e8 --- /dev/null +++ b/tests/ui/consts/no-ice-from-static-in-const-issue-52060.rs @@ -0,0 +1,9 @@ +// Regression test for https://github.com/rust-lang/rust/issues/52060 +// The compiler shouldn't ICE in this case + +static mut A: &'static [u32] = &[1]; +static B: [u32; 1] = [0; unsafe { A.len() }]; +//~^ ERROR: evaluation of constant value failed +//~| mutable global memory + +fn main() {} diff --git a/tests/ui/consts/no-ice-from-static-in-const-issue-52060.stderr b/tests/ui/consts/no-ice-from-static-in-const-issue-52060.stderr new file mode 100644 index 0000000000000..ca4d3224ec790 --- /dev/null +++ b/tests/ui/consts/no-ice-from-static-in-const-issue-52060.stderr @@ -0,0 +1,9 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/no-ice-from-static-in-const-issue-52060.rs:5:35 + | +LL | static B: [u32; 1] = [0; unsafe { A.len() }]; + | ^ constant accesses mutable global memory + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/feature-gates/feature-gate-const-refs-to-static.rs b/tests/ui/feature-gates/feature-gate-const-refs-to-static.rs deleted file mode 100644 index 008b754dc6cf3..0000000000000 --- a/tests/ui/feature-gates/feature-gate-const-refs-to-static.rs +++ /dev/null @@ -1,11 +0,0 @@ -static S: i32 = 0; -static mut S_MUT: i32 = 0; - -const C1: &i32 = &S; //~ERROR: referencing statics in constants is unstable -const C1_READ: () = { - assert!(*C1 == 0); -}; -const C2: *const i32 = unsafe { std::ptr::addr_of!(S_MUT) }; //~ERROR: referencing statics in constants is unstable - -fn main() { -} diff --git a/tests/ui/feature-gates/feature-gate-const-refs-to-static.stderr b/tests/ui/feature-gates/feature-gate-const-refs-to-static.stderr deleted file mode 100644 index 5af484712501e..0000000000000 --- a/tests/ui/feature-gates/feature-gate-const-refs-to-static.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0658]: referencing statics in constants is unstable - --> $DIR/feature-gate-const-refs-to-static.rs:4:19 - | -LL | const C1: &i32 = &S; - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error[E0658]: referencing statics in constants is unstable - --> $DIR/feature-gate-const-refs-to-static.rs:8:52 - | -LL | const C2: *const i32 = unsafe { std::ptr::addr_of!(S_MUT) }; - | ^^^^^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/static/issue-18118-2.rs b/tests/ui/static/issue-18118-2.rs deleted file mode 100644 index 6c81eec7d7e4b..0000000000000 --- a/tests/ui/static/issue-18118-2.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub fn main() { - const z: &'static isize = { - static p: isize = 3; - &p //~ ERROR referencing statics - }; -} diff --git a/tests/ui/static/issue-18118-2.stderr b/tests/ui/static/issue-18118-2.stderr deleted file mode 100644 index f084f2b9fdfc4..0000000000000 --- a/tests/ui/static/issue-18118-2.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-18118-2.rs:4:10 - | -LL | &p - | ^ - | - = note: see issue #119618 for more information - = help: add `#![feature(const_refs_to_static)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. - = help: to fix this, the value can be extracted to a `const` and then used. - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/statics/const_generics.rs b/tests/ui/statics/const_generics.rs index 7f64f6995a453..6cc0a65f77d52 100644 --- a/tests/ui/statics/const_generics.rs +++ b/tests/ui/statics/const_generics.rs @@ -10,7 +10,6 @@ //@[noopt] compile-flags: -Copt-level=0 //@[opt] compile-flags: -O -#![feature(const_refs_to_static)] #![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] diff --git a/tests/ui/statics/mutable_memory_validation.rs b/tests/ui/statics/mutable_memory_validation.rs index d16b787fef84e..032b903f64e5b 100644 --- a/tests/ui/statics/mutable_memory_validation.rs +++ b/tests/ui/statics/mutable_memory_validation.rs @@ -4,8 +4,6 @@ //@ normalize-stderr-test: "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" //@ normalize-stderr-test: "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?()?─*╼ )+ *│.*" -> "HEX_DUMP" -#![feature(const_refs_to_static)] - use std::cell::UnsafeCell; struct Meh { diff --git a/tests/ui/statics/mutable_memory_validation.stderr b/tests/ui/statics/mutable_memory_validation.stderr index 60d1356467927..76e1827ea12a6 100644 --- a/tests/ui/statics/mutable_memory_validation.stderr +++ b/tests/ui/statics/mutable_memory_validation.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/mutable_memory_validation.rs:15:1 + --> $DIR/mutable_memory_validation.rs:13:1 | LL | const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } }; | ^^^^^^^^^^^^^^ constructing invalid value at .x.: encountered `UnsafeCell` in read-only memory