Validate before reporting interning errors.

validation produces much higher quality errors and already handles most of the cases
This commit is contained in:
Oli Scherer 2024-03-26 09:46:30 +00:00
parent 8b2a4f8b43
commit 77fe9f0a72
18 changed files with 253 additions and 513 deletions

View file

@ -10,20 +10,21 @@
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::lint;
use rustc_span::def_id::LocalDefId;
use rustc_span::Span;
use rustc_target::abi::{self, Abi};
use super::{CanAccessMutGlobal, CompileTimeEvalContext, CompileTimeInterpreter};
use crate::const_eval::CheckAlignment;
use crate::errors;
use crate::errors::ConstEvalError;
use crate::interpret::eval_nullary_intrinsic;
use crate::errors::{self, DanglingPtrInFinal};
use crate::interpret::{
create_static_alloc, intern_const_alloc_recursive, CtfeValidationMode, GlobalId, Immediate,
InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
StackPopCleanup,
};
use crate::interpret::{eval_nullary_intrinsic, InternResult};
use crate::CTRL_C_RECEIVED;
// Returns a pointer to where the result lives
@ -89,11 +90,33 @@ fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
}
// Intern the result
intern_const_alloc_recursive(ecx, intern_kind, &ret)?;
let intern_result = intern_const_alloc_recursive(ecx, intern_kind, &ret);
// Since evaluation had no errors, validate the resulting constant.
const_validate_mplace(&ecx, &ret, cid)?;
// Only report this after validation, as validaiton produces much better diagnostics.
// FIXME: ensure validation always reports this and stop making interning care about it.
if let Err(InternResult { found_bad_mutable_pointer, found_dangling_pointer }) = intern_result {
if found_dangling_pointer {
return Err(ecx
.tcx
.dcx()
.emit_err(DanglingPtrInFinal { span: ecx.tcx.span, kind: intern_kind })
.into());
} else if found_bad_mutable_pointer {
// only report mutable pointers if there were no dangling pointers
let err_diag = errors::MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind };
ecx.tcx.emit_node_span_lint(
lint::builtin::CONST_EVAL_MUTABLE_PTR_IN_FINAL_VALUE,
ecx.best_lint_scope(),
err_diag.span,
err_diag,
)
}
}
Ok(R::make_result(ret, ecx))
}

View file

@ -16,19 +16,17 @@
use hir::def::DefKind;
use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::mir::interpret::{ConstAllocation, CtfeProvenance, InterpResult};
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_session::lint;
use rustc_span::def_id::LocalDefId;
use rustc_span::sym;
use super::{AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceTy};
use crate::const_eval;
use crate::errors::{DanglingPtrInFinal, MutablePtrInFinal, NestedStaticInThreadLocal};
use crate::errors::NestedStaticInThreadLocal;
pub trait CompileTimeMachine<'mir, 'tcx: 'mir, T> = Machine<
'mir,
@ -134,6 +132,19 @@ pub enum InternKind {
Promoted,
}
#[derive(Default, Debug)]
pub struct InternResult {
pub found_bad_mutable_pointer: bool,
pub found_dangling_pointer: bool,
}
impl InternResult {
fn has_errors(&self) -> bool {
let Self { found_bad_mutable_pointer, found_dangling_pointer } = *self;
found_bad_mutable_pointer || found_dangling_pointer
}
}
/// Intern `ret` and everything it references.
///
/// This *cannot raise an interpreter error*. Doing so is left to validation, which
@ -149,7 +160,7 @@ pub fn intern_const_alloc_recursive<
ecx: &mut InterpCx<'mir, 'tcx, M>,
intern_kind: InternKind,
ret: &MPlaceTy<'tcx>,
) -> Result<(), ErrorGuaranteed> {
) -> Result<(), InternResult> {
// We are interning recursively, and for mutability we are distinguishing the "root" allocation
// that we are starting in, and all other allocations that we are encountering recursively.
let (base_mutability, inner_mutability, is_static) = match intern_kind {
@ -201,7 +212,7 @@ pub fn intern_const_alloc_recursive<
// Whether we encountered a bad mutable pointer.
// We want to first report "dangling" and then "mutable", so we need to delay reporting these
// errors.
let mut found_bad_mutable_pointer = false;
let mut result = InternResult::default();
// Keep interning as long as there are things to intern.
// We show errors if there are dangling pointers, or mutable pointers in immutable contexts
@ -251,7 +262,7 @@ pub fn intern_const_alloc_recursive<
// on the promotion analysis not screwing up to ensure that it is sound to intern
// promoteds as immutable.
trace!("found bad mutable pointer");
found_bad_mutable_pointer = true;
result.found_bad_mutable_pointer = true;
}
if ecx.tcx.try_get_global_alloc(alloc_id).is_some() {
// Already interned.
@ -269,21 +280,15 @@ pub fn intern_const_alloc_recursive<
// pointers before deciding which allocations can be made immutable; but for now we are
// okay with losing some potential for immutability here. This can anyway only affect
// `static mut`.
todo.extend(intern_shallow(ecx, alloc_id, inner_mutability).map_err(|()| {
ecx.tcx.dcx().emit_err(DanglingPtrInFinal { span: ecx.tcx.span, kind: intern_kind })
})?);
match intern_shallow(ecx, alloc_id, inner_mutability) {
Ok(nested) => todo.extend(nested),
Err(()) => {
ecx.tcx.dcx().delayed_bug("found dangling pointer during const interning");
result.found_dangling_pointer = true
}
}
}
if found_bad_mutable_pointer {
let err_diag = MutablePtrInFinal { span: ecx.tcx.span, kind: intern_kind };
ecx.tcx.emit_node_span_lint(
lint::builtin::CONST_EVAL_MUTABLE_PTR_IN_FINAL_VALUE,
ecx.best_lint_scope(),
err_diag.span,
err_diag,
)
}
Ok(())
if result.has_errors() { Err(result) } else { Ok(()) }
}
/// Intern `ret`. This function assumes that `ret` references no other allocation.

View file

@ -23,6 +23,7 @@
pub use self::eval_context::{format_interp_error, Frame, FrameInfo, InterpCx, StackPopCleanup};
pub use self::intern::{
intern_const_alloc_for_constprop, intern_const_alloc_recursive, HasStaticRootDefId, InternKind,
InternResult,
};
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, StackPopJump};
pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind};

View file

@ -2,10 +2,15 @@
#![feature(const_heap)]
#![feature(const_mut_refs)]
// Strip out raw byte dumps to make comparison platform-independent:
//@ 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"
//@ normalize-stderr-test "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
use std::intrinsics;
const _X: &'static u8 = unsafe {
//~^ error: dangling pointer in final value of constant
//~^ error: it is undefined behavior to use this value
let ptr = intrinsics::const_allocate(4, 4);
intrinsics::const_deallocate(ptr, 4, 4);
&*ptr

View file

@ -1,14 +1,19 @@
error: encountered dangling pointer in final value of constant
--> $DIR/dealloc_intrinsic_dangling.rs:7:1
error[E0080]: it is undefined behavior to use this value
--> $DIR/dealloc_intrinsic_dangling.rs:12:1
|
LL | const _X: &'static u8 = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
|
= 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: $SIZE, align: $ALIGN) {
HEX_DUMP
}
error[E0080]: evaluation of constant value failed
--> $DIR/dealloc_intrinsic_dangling.rs:18:5
--> $DIR/dealloc_intrinsic_dangling.rs:23:5
|
LL | *reference
| ^^^^^^^^^^ memory access failed: ALLOC0 has been freed, so this pointer is dangling
| ^^^^^^^^^^ memory access failed: ALLOC1 has been freed, so this pointer is dangling
error: aborting due to 2 previous errors

View file

@ -33,8 +33,8 @@ const fn helper_dangling() -> Option<&'static mut i32> { unsafe {
// Undefined behaviour (dangling pointer), who doesn't love tests like this.
Some(&mut *(&mut 42 as *mut i32))
} }
const DANGLING: Option<&mut i32> = helper_dangling(); //~ ERROR encountered dangling pointer
static DANGLING_STATIC: Option<&mut i32> = helper_dangling(); //~ ERROR encountered dangling pointer
const DANGLING: Option<&mut i32> = helper_dangling(); //~ ERROR it is undefined behavior to use this value
static DANGLING_STATIC: Option<&mut i32> = helper_dangling(); //~ ERROR it is undefined behavior to use this value
// These are fine! Just statics pointing to mutable statics, nothing fundamentally wrong with this.
static MUT_STATIC: Option<&mut i32> = helper();

View file

@ -31,17 +31,27 @@ LL | static INT2PTR_STATIC: Option<&mut i32> = helper_int2ptr();
HEX_DUMP
}
error: encountered dangling pointer in final value of constant
error[E0080]: it is undefined behavior to use this value
--> $DIR/mut_ref_in_final_dynamic_check.rs:36:1
|
LL | const DANGLING: Option<&mut i32> = helper_dangling();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0: encountered a dangling reference (use-after-free)
|
= 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: $SIZE, align: $ALIGN) {
HEX_DUMP
}
error: encountered dangling pointer in final value of static
error[E0080]: it is undefined behavior to use this value
--> $DIR/mut_ref_in_final_dynamic_check.rs:37: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)
|
= 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: $SIZE, align: $ALIGN) {
HEX_DUMP
}
error: aborting due to 5 previous errors

View file

@ -1,4 +1,8 @@
// https://github.com/rust-lang/rust/issues/55223
// Strip out raw byte dumps to make comparison platform-independent:
//@ 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"
//@ normalize-stderr-test "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
union Foo<'a> {
y: &'a (),
@ -6,7 +10,7 @@ union Foo<'a> {
}
const FOO: &() = {
//~^ ERROR encountered dangling pointer in final value of constant
//~^ ERROR it is undefined behavior to use this value
let y = ();
unsafe { Foo { y: &y }.long_live_the_unit }
};

View file

@ -1,8 +1,14 @@
error: encountered dangling pointer in final value of constant
--> $DIR/dangling-alloc-id-ice.rs:8:1
error[E0080]: it is undefined behavior to use this value
--> $DIR/dangling-alloc-id-ice.rs:12:1
|
LL | const FOO: &() = {
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
|
= 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: $SIZE, align: $ALIGN) {
HEX_DUMP
}
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,8 +1,29 @@
const FOO: *const u32 = { //~ ERROR encountered dangling pointer in final value of constant
const FOO: *const u32 = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42;
&x
};
fn main() {
let x = FOO;
union Union {
ptr: *const u32,
}
const BAR: Union = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42;
Union { ptr: &x }
};
const BAZ: Union = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42_u32;
Union { ptr: &(&x as *const u32) as *const *const u32 as _ }
};
const FOOMP: *const u32 = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42_u32;
&(&x as *const u32) as *const *const u32 as _
};
fn main() {}

View file

@ -4,5 +4,23 @@ error: encountered dangling pointer in final value of constant
LL | const FOO: *const u32 = {
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error
error: encountered dangling pointer in final value of constant
--> $DIR/dangling_raw_ptr.rs:11:1
|
LL | const BAR: Union = {
| ^^^^^^^^^^^^^^^^
error: encountered dangling pointer in final value of constant
--> $DIR/dangling_raw_ptr.rs:17:1
|
LL | const BAZ: Union = {
| ^^^^^^^^^^^^^^^^
error: encountered dangling pointer in final value of constant
--> $DIR/dangling_raw_ptr.rs:23:1
|
LL | const FOOMP: *const u32 = {
| ^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors

View file

@ -5,12 +5,9 @@
#![deny(const_eval_mutable_ptr_in_final_value)]
use std::cell::UnsafeCell;
// a test demonstrating what things we could allow with a smarter const qualification
// This requires walking nested statics.
static FOO: &&mut u32 = &&mut 42;
//~^ ERROR encountered mutable pointer in final value of static
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
static BAR: &mut () = &mut ();
//~^ ERROR encountered mutable pointer in final value of static
@ -27,14 +24,10 @@ struct Meh {
}
unsafe impl Sync for Meh {}
static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
//~^ ERROR encountered mutable pointer in final value of static
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
static OH_YES: &mut i32 = &mut 42;
//~^ ERROR encountered mutable pointer in final value of static
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
fn main() {
unsafe {

View file

@ -1,19 +1,5 @@
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:10:1
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references.rs:10:1
--> $DIR/mutable_references.rs:9:1
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered mutable reference or box pointing to read-only memory
@ -24,16 +10,21 @@ LL | static FOO: &&mut u32 = &&mut 42;
}
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:15:1
--> $DIR/mutable_references.rs:12:1
|
LL | static BAR: &mut () = &mut ();
| ^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:21:1
--> $DIR/mutable_references.rs:18:1
|
LL | static BOO: &mut Foo<()> = &mut Foo(());
| ^^^^^^^^^^^^^^^^^^^^^^^^
@ -41,17 +32,8 @@ LL | static BOO: &mut Foo<()> = &mut Foo(());
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:29:1
|
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references.rs:29:1
--> $DIR/mutable_references.rs:26:1
|
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in read-only memory
@ -61,17 +43,8 @@ LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
HEX_DUMP
}
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:34:1
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references.rs:34:1
--> $DIR/mutable_references.rs:29:1
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
@ -82,7 +55,7 @@ LL | static OH_YES: &mut i32 = &mut 42;
}
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
--> $DIR/mutable_references.rs:43:5
--> $DIR/mutable_references.rs:36:5
|
LL | *OH_YES = 99;
| ^^^^^^^^^^^^ cannot assign
@ -90,53 +63,38 @@ LL | *OH_YES = 99;
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references.rs:10:26
--> $DIR/mutable_references.rs:9:26
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references.rs:15:23
--> $DIR/mutable_references.rs:12:23
|
LL | static BAR: &mut () = &mut ();
| ^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references.rs:21:28
--> $DIR/mutable_references.rs:18:28
|
LL | static BOO: &mut Foo<()> = &mut Foo(());
| ^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references.rs:29:28
--> $DIR/mutable_references.rs:26: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:34:27
--> $DIR/mutable_references.rs:29:27
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^
error: aborting due to 9 previous errors; 1 warning emitted
error: aborting due to 6 previous errors; 1 warning emitted
Some errors have detailed explanations: E0080, E0594.
For more information about an error, try `rustc --explain E0080`.
Future incompatibility report: Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:10:1
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:15:1
--> $DIR/mutable_references.rs:12:1
|
LL | static BAR: &mut () = &mut ();
| ^^^^^^^^^^^^^^^^^^^
@ -151,7 +109,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:21:1
--> $DIR/mutable_references.rs:18:1
|
LL | static BOO: &mut Foo<()> = &mut Foo(());
| ^^^^^^^^^^^^^^^^^^^^^^^^
@ -164,33 +122,3 @@ note: the lint level is defined here
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:29:1
|
LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/mutable_references.rs:34:1
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -16,9 +16,7 @@ unsafe impl Sync for Meh {}
// the following will never be ok! no interior mut behind consts, because
// all allocs interned here will be marked immutable.
const MUH: Meh = Meh {
//~^ ERROR encountered mutable pointer in final value of constant
//~| WARNING this was previously accepted by the compiler
//~| ERROR: it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
x: &UnsafeCell::new(42),
};
@ -29,9 +27,7 @@ unsafe impl Sync for Synced {}
// Make sure we also catch this behind a type-erased `dyn Trait` reference.
const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
//~^ ERROR: mutable pointer in final value
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR: it is undefined behavior to use this value
// Make sure we also catch mutable references in values that shouldn't have them.
static mut FOO: i32 = 0;
@ -40,9 +36,7 @@ unsafe impl Sync for Synced {}
//~| static
const BLUNT: &mut i32 = &mut 42;
//~^ ERROR: mutable pointer in final value
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR: it is undefined behavior to use this value
// Check for mutable references to read-only memory.
static READONLY: i32 = 0;

View file

@ -1,17 +1,3 @@
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:18:1
|
LL | const MUH: Meh = Meh {
| ^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references_err.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references_err.rs:18:1
|
@ -23,17 +9,8 @@ LL | const MUH: Meh = Meh {
HEX_DUMP
}
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:31:1
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references_err.rs:31:1
--> $DIR/mutable_references_err.rs:29: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
@ -44,7 +21,7 @@ LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
}
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references_err.rs:38:1
--> $DIR/mutable_references_err.rs:34:1
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
@ -54,17 +31,8 @@ LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
HEX_DUMP
}
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:42:1
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references_err.rs:42:1
--> $DIR/mutable_references_err.rs:38:1
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
@ -75,7 +43,7 @@ LL | const BLUNT: &mut i32 = &mut 42;
}
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_references_err.rs:49:1
--> $DIR/mutable_references_err.rs:43: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
@ -86,7 +54,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_err.rs:56:1
--> $DIR/mutable_references_err.rs:50:1
|
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
@ -97,28 +65,33 @@ LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
}
note: erroneous constant encountered
--> $DIR/mutable_references_err.rs:58:34
--> $DIR/mutable_references_err.rs:52:34
|
LL | const READS_FROM_MUTABLE: i32 = *POINTS_TO_MUTABLE1;
| ^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of constant value failed
--> $DIR/mutable_references_err.rs:60:43
--> $DIR/mutable_references_err.rs:54: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_err.rs:64:1
--> $DIR/mutable_references_err.rs:58:1
|
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references_err.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:68:1
--> $DIR/mutable_references_err.rs:62:1
|
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -127,7 +100,7 @@ LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:72:1
--> $DIR/mutable_references_err.rs:66:1
|
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -136,7 +109,7 @@ LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *cons
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:85:1
--> $DIR/mutable_references_err.rs:79:1
|
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -145,7 +118,7 @@ LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:89:1
--> $DIR/mutable_references_err.rs:83:1
|
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -154,7 +127,7 @@ LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:93:1
--> $DIR/mutable_references_err.rs:87:1
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -165,132 +138,87 @@ LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references_err.rs:22:8
--> $DIR/mutable_references_err.rs:20:8
|
LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references_err.rs:31:27
--> $DIR/mutable_references_err.rs:29:27
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_refs_to_static` feature
--> $DIR/mutable_references_err.rs:38:40
--> $DIR/mutable_references_err.rs:34:40
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
| ^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references_err.rs:38:35
--> $DIR/mutable_references_err.rs:34:35
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
| ^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references_err.rs:42:25
--> $DIR/mutable_references_err.rs:38:25
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references_err.rs:49:49
--> $DIR/mutable_references_err.rs:43:49
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/mutable_references_err.rs:49:49
--> $DIR/mutable_references_err.rs:43:49
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check for `const_refs_to_static` feature
--> $DIR/mutable_references_err.rs:56:44
--> $DIR/mutable_references_err.rs:50:44
|
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
| ^^^^^^^
help: skipping check for `const_refs_to_static` feature
--> $DIR/mutable_references_err.rs:60:45
--> $DIR/mutable_references_err.rs:54:45
|
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
| ^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/mutable_references_err.rs:64:45
--> $DIR/mutable_references_err.rs:58: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_err.rs:68:46
--> $DIR/mutable_references_err.rs:62: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_err.rs:72:47
--> $DIR/mutable_references_err.rs:66: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_err.rs:85:51
--> $DIR/mutable_references_err.rs:79: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_err.rs:89:49
--> $DIR/mutable_references_err.rs:83: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_err.rs:93:51
--> $DIR/mutable_references_err.rs:87:51
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^
error: aborting due to 16 previous errors; 1 warning emitted
error: aborting due to 13 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.
Future incompatibility report: Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:18:1
|
LL | const MUH: Meh = Meh {
| ^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references_err.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:31:1
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references_err.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:42:1
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/mutable_references_err.rs:5:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:64:1
--> $DIR/mutable_references_err.rs:58:1
|
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -305,7 +233,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:68:1
--> $DIR/mutable_references_err.rs:62:1
|
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -320,7 +248,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:72:1
--> $DIR/mutable_references_err.rs:66:1
|
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -335,7 +263,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:85:1
--> $DIR/mutable_references_err.rs:79:1
|
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -350,7 +278,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:89:1
--> $DIR/mutable_references_err.rs:83:1
|
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -365,7 +293,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of constant
--> $DIR/mutable_references_err.rs:93:1
--> $DIR/mutable_references_err.rs:87:1
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,17 +1,3 @@
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:9:1
|
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:9:1
|
@ -23,17 +9,8 @@ LL | static REF: &AtomicI32 = &AtomicI32::new(42);
╾ALLOC0╼ │ ╾──╼
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:14:1
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:14:1
--> $DIR/static-no-inner-mut.rs:12:1
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
@ -43,17 +20,8 @@ LL | static REFMUT: &mut i32 = &mut 0;
╾ALLOC1╼ │ ╾──╼
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:20:1
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:20:1
--> $DIR/static-no-inner-mut.rs:16:1
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.v: encountered `UnsafeCell` in read-only memory
@ -63,17 +31,8 @@ LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
╾ALLOC2╼ │ ╾──╼
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:25:1
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:25:1
--> $DIR/static-no-inner-mut.rs:18:1
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
@ -84,16 +43,21 @@ LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:43:1
--> $DIR/static-no-inner-mut.rs:34:1
|
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:47:1
--> $DIR/static-no-inner-mut.rs:38:1
|
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -102,7 +66,7 @@ LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *con
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:51:1
--> $DIR/static-no-inner-mut.rs:42:1
|
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -118,102 +82,42 @@ help: skipping check that does not even have a feature gate
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
| ^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:14:27
--> $DIR/static-no-inner-mut.rs:12:27
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:20:56
--> $DIR/static-no-inner-mut.rs:16:56
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:25:44
--> $DIR/static-no-inner-mut.rs:18:44
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:43:52
--> $DIR/static-no-inner-mut.rs:34:52
|
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:47:51
--> $DIR/static-no-inner-mut.rs:38:51
|
LL | static 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/static-no-inner-mut.rs:51:52
--> $DIR/static-no-inner-mut.rs:42:52
|
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^
error: aborting due to 11 previous errors; 1 warning emitted
error: aborting due to 7 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.
Future incompatibility report: Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:9:1
|
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:14:1
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:20:1
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:25:1
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:43:1
--> $DIR/static-no-inner-mut.rs:34:1
|
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -228,7 +132,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:47:1
--> $DIR/static-no-inner-mut.rs:38:1
|
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -243,7 +147,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:51:1
--> $DIR/static-no-inner-mut.rs:42:1
|
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,17 +1,3 @@
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:9:1
|
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:9:1
|
@ -23,17 +9,8 @@ LL | static REF: &AtomicI32 = &AtomicI32::new(42);
╾ALLOC0╼ │ ╾──────╼
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:14:1
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:14:1
--> $DIR/static-no-inner-mut.rs:12:1
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
@ -43,17 +20,8 @@ LL | static REFMUT: &mut i32 = &mut 0;
╾ALLOC1╼ │ ╾──────╼
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:20:1
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:20:1
--> $DIR/static-no-inner-mut.rs:16:1
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.v: encountered `UnsafeCell` in read-only memory
@ -63,17 +31,8 @@ LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
╾ALLOC2╼ │ ╾──────╼
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:25:1
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error[E0080]: it is undefined behavior to use this value
--> $DIR/static-no-inner-mut.rs:25:1
--> $DIR/static-no-inner-mut.rs:18:1
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
@ -84,16 +43,21 @@ LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
}
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:43:1
--> $DIR/static-no-inner-mut.rs:34:1
|
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:47:1
--> $DIR/static-no-inner-mut.rs:38:1
|
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -102,7 +66,7 @@ LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *con
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:51:1
--> $DIR/static-no-inner-mut.rs:42:1
|
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -118,102 +82,42 @@ help: skipping check that does not even have a feature gate
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
| ^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:14:27
--> $DIR/static-no-inner-mut.rs:12:27
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:20:56
--> $DIR/static-no-inner-mut.rs:16:56
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:25:44
--> $DIR/static-no-inner-mut.rs:18:44
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:43:52
--> $DIR/static-no-inner-mut.rs:34:52
|
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/static-no-inner-mut.rs:47:51
--> $DIR/static-no-inner-mut.rs:38:51
|
LL | static 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/static-no-inner-mut.rs:51:52
--> $DIR/static-no-inner-mut.rs:42:52
|
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^
error: aborting due to 11 previous errors; 1 warning emitted
error: aborting due to 7 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.
Future incompatibility report: Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:9:1
|
LL | static REF: &AtomicI32 = &AtomicI32::new(42);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:14:1
|
LL | static REFMUT: &mut i32 = &mut 0;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:20:1
|
LL | static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:25:1
|
LL | static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #122153 <https://github.com/rust-lang/rust/issues/122153>
note: the lint level is defined here
--> $DIR/static-no-inner-mut.rs:6:9
|
LL | #![deny(const_eval_mutable_ptr_in_final_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:43:1
--> $DIR/static-no-inner-mut.rs:34:1
|
LL | static RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -228,7 +132,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:47:1
--> $DIR/static-no-inner-mut.rs:38:1
|
LL | static RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -243,7 +147,7 @@ LL | #![deny(const_eval_mutable_ptr_in_final_value)]
Future breakage diagnostic:
error: encountered mutable pointer in final value of static
--> $DIR/static-no-inner-mut.rs:51:1
--> $DIR/static-no-inner-mut.rs:42:1
|
LL | static RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -7,25 +7,16 @@
use std::sync::atomic::*;
static REF: &AtomicI32 = &AtomicI32::new(42);
//~^ ERROR mutable pointer in final value
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
static REFMUT: &mut i32 = &mut 0;
//~^ ERROR mutable pointer in final value
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
// Different way of writing this that avoids promotion.
static REF2: &AtomicI32 = {let x = AtomicI32::new(42); &{x}};
//~^ ERROR mutable pointer in final value
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
static REFMUT2: &mut i32 = {let mut x = 0; &mut {x}};
//~^ ERROR mutable pointer in final value
//~| WARNING this was previously accepted by the compiler
//~| ERROR it is undefined behavior to use this value
//~^ ERROR it is undefined behavior to use this value
// This one is obvious, since it is non-Sync. (It also suppresses the other errors, so it is
// commented out.)