Auto merge of #129759 - dingxiangfei2009:stabilize-const-refs-to-static, r=RalfJung

Stabilize `const_refs_to_static`

Meanwhile, I am cooking a sub-section in the language reference.
This commit is contained in:
bors 2024-09-26 13:36:03 +00:00
commit 4428a05167
45 changed files with 157 additions and 442 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
```

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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<T>(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

View File

@ -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 <https://github.com/rust-lang/rust/issues/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
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:21:44
|
LL | global_asm!("{}", const const_foo(S));
| ^
|
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/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
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:25:44
|
LL | global_asm!("{}", const const_bar(S));
| ^
|
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -2,8 +2,6 @@
//@ ignore-nvptx64
//@ ignore-spirv
#![feature(const_refs_to_static)]
use std::arch::{asm, global_asm};
use std::ptr::addr_of;

View File

@ -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)) };
| ^^^^^^-------------

View File

@ -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<T>(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

View File

@ -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 <https://github.com/rust-lang/rust/issues/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
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:21:44
|
LL | global_asm!("{}", const const_foo(S));
| ^
|
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/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
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:25:44
|
LL | global_asm!("{}", const const_bar(S));
| ^
|
= note: see issue #119618 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -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 {

View File

@ -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 <https://github.com/rust-lang/rust/issues/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
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 <https://github.com/rust-lang/rust/issues/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
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`.

View File

@ -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]+)?(<imm>)?─*╼ )+ *│.*" -> " HEX_DUMP"
//@ normalize-stderr-test: "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
#![feature(const_refs_to_static)]
use std::sync::Mutex;

View File

@ -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 .<enum-variant(Some)>.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 .<enum-variant(Some)>.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 .<enum-variant(Some)>.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 .<enum-variant(Some)>.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 .<enum-variant(Some)>.0: encountered a dangling reference (use-after-free)

View File

@ -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)]

View File

@ -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);

View File

@ -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

View File

@ -1,5 +1,4 @@
//@ run-pass
#![feature(const_refs_to_static)]
static S: i32 = 0;
static mut S_MUT: i32 = 0;

View File

@ -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]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
#![feature(const_refs_to_static, sync_unsafe_cell)]
#![feature(sync_unsafe_cell)]
use std::cell::SyncUnsafeCell;
static S: SyncUnsafeCell<i32> = SyncUnsafeCell::new(0);

View File

@ -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<i32> = &S;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
@ -10,13 +10,13 @@ LL | const C1: &SyncUnsafeCell<i32> = &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

View File

@ -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]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
#![feature(const_refs_to_static)]
#![allow(static_mut_refs)]
fn invalid() {

View File

@ -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 .<deref>: 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 => {}
| ^

View File

@ -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]+)?(<imm>)?─*╼ )+ *│.*" -> "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() {}

View File

@ -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 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -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 };

View File

@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -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() {}

View File

@ -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 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -74,8 +74,8 @@ const fn foo11_2<T: Send>(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 } }

View File

@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -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

View File

@ -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`.

View File

@ -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<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
//~^ ERROR mutable pointer in final value
fn main() {
unsafe {
*MEH.x.get() = 99;

View File

@ -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.<deref>: 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.<deref>: 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 .<deref>.<dyn-downcast>.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<i32> = 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<i32> = 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<AtomicI32> = 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<i32> = 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<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^

View File

@ -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() {}

View File

@ -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`.

View File

@ -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() {
}

View File

@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -1,6 +0,0 @@
pub fn main() {
const z: &'static isize = {
static p: isize = 3;
&p //~ ERROR referencing statics
};
}

View File

@ -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 <https://github.com/rust-lang/rust/issues/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`.

View File

@ -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)]

View File

@ -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]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
#![feature(const_refs_to_static)]
use std::cell::UnsafeCell;
struct Meh {

View File

@ -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.<deref>: encountered `UnsafeCell` in read-only memory