mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Stabilize const_raw_ptr_deref
for *const T
This stabilizes dereferencing immutable raw pointers in const contexts. It does not stabilize `*mut T` dereferencing. This is placed behind the `const_raw_mut_ptr_deref` feature gate.
This commit is contained in:
parent
5ec7d1dad6
commit
0cdbeaa2a3
@ -725,7 +725,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
|
||||
match elem {
|
||||
ProjectionElem::Deref => {
|
||||
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
|
||||
if let ty::RawPtr(_) = base_ty.kind() {
|
||||
if base_ty.is_unsafe_ptr() {
|
||||
if proj_base.is_empty() {
|
||||
let decl = &self.body.local_decls[place_local];
|
||||
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
|
||||
@ -734,7 +734,13 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.check_op(ops::RawPtrDeref);
|
||||
|
||||
// `*const T` is stable, `*mut T` is not
|
||||
if !base_ty.is_mutable_ptr() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.check_op(ops::RawMutPtrDeref);
|
||||
}
|
||||
|
||||
if context.is_mutating_use() {
|
||||
|
@ -400,18 +400,18 @@ impl NonConstOp for RawPtrComparison {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RawPtrDeref;
|
||||
impl NonConstOp for RawPtrDeref {
|
||||
pub struct RawMutPtrDeref;
|
||||
impl NonConstOp for RawMutPtrDeref {
|
||||
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
|
||||
Status::Unstable(sym::const_raw_ptr_deref)
|
||||
Status::Unstable(sym::const_mut_refs)
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
feature_err(
|
||||
&ccx.tcx.sess.parse_sess,
|
||||
sym::const_raw_ptr_deref,
|
||||
sym::const_mut_refs,
|
||||
span,
|
||||
&format!("dereferencing raw pointers in {}s is unstable", ccx.const_kind(),),
|
||||
&format!("dereferencing raw mutable pointers in {}s is unstable", ccx.const_kind(),),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -299,6 +299,8 @@ declare_features! (
|
||||
(accepted, const_panic, "1.57.0", Some(51999), None),
|
||||
/// Lessens the requirements for structs to implement `Unsize`.
|
||||
(accepted, relaxed_struct_unsize, "1.58.0", Some(81793), None),
|
||||
/// Allows dereferencing raw pointers during const eval.
|
||||
(accepted, const_raw_ptr_deref, "1.58.0", Some(51911), None),
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// feature-group-end: accepted features
|
||||
|
@ -408,9 +408,6 @@ declare_features! (
|
||||
/// Allows inferring `'static` outlives requirements (RFC 2093).
|
||||
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
|
||||
|
||||
/// Allows dereferencing raw pointers during const eval.
|
||||
(active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
|
||||
|
||||
/// Allows inconsistent bounds in where clauses.
|
||||
(active, trivial_bounds, "1.28.0", Some(48214), None),
|
||||
|
||||
|
@ -156,7 +156,7 @@
|
||||
#![feature(const_impl_trait)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_precise_live_drops)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![cfg_attr(bootstrap, feature(const_raw_ptr_deref))]
|
||||
#![feature(const_refs_to_cell)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(doc_cfg)]
|
||||
|
@ -56,7 +56,7 @@
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_pin)]
|
||||
#![feature(const_slice_from_raw_parts)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![cfg_attr(bootstrap, feature(const_raw_ptr_deref))]
|
||||
#![feature(never_type)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(result_into_ok_or_err)]
|
||||
|
@ -264,7 +264,8 @@
|
||||
#![feature(const_ipv4)]
|
||||
#![feature(const_ipv6)]
|
||||
#![feature(const_option)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![cfg_attr(bootstrap, feature(const_raw_ptr_deref))]
|
||||
#![cfg_attr(not(bootstrap), feature(const_mut_refs))]
|
||||
#![feature(const_socketaddr)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(container_error_extra)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Check that you can't dereference raw pointers in constants.
|
||||
// Check that you can't dereference invalid raw pointers in constants.
|
||||
|
||||
fn main() {
|
||||
static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
|
||||
//~^ ERROR dereferencing raw pointers in statics is unstable
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
println!("{}", C);
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
error[E0658]: dereferencing raw pointers in statics is unstable
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/const-deref-ptr.rs:4:29
|
||||
|
|
||||
LL | static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xdeadbeef is not a valid pointer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -1,19 +0,0 @@
|
||||
// New test for #53818: modifying static memory at compile-time is not allowed.
|
||||
// The test should never compile successfully
|
||||
|
||||
#![feature(const_raw_ptr_deref, const_mut_refs)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
struct Foo(UnsafeCell<u32>);
|
||||
|
||||
unsafe impl Send for Foo {}
|
||||
unsafe impl Sync for Foo {}
|
||||
|
||||
static FOO: Foo = Foo(UnsafeCell::new(42));
|
||||
|
||||
static BAR: () = unsafe {
|
||||
*FOO.0.get() = 5; //~ ERROR
|
||||
};
|
||||
|
||||
fn main() {}
|
@ -1,9 +0,0 @@
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/assign-to-static-within-other-static-2.rs:16:5
|
||||
|
|
||||
LL | *FOO.0.get() = 5;
|
||||
| ^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
@ -1,8 +1,6 @@
|
||||
// New test for #53818: modifying static memory at compile-time is not allowed.
|
||||
// The test should never compile successfully
|
||||
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
static mut FOO: u32 = 42;
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/assign-to-static-within-other-static.rs:10:5
|
||||
--> $DIR/assign-to-static-within-other-static.rs:8:5
|
||||
|
|
||||
LL | FOO = 5;
|
||||
| ^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
// fine
|
||||
|
@ -1,11 +1,11 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const_raw_ptr_ops2.rs:9:26
|
||||
--> $DIR/const_raw_ptr_ops2.rs:7:26
|
||||
|
|
||||
LL | const Z2: i32 = unsafe { *(42 as *const i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^ 0x2a is not a valid pointer
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const_raw_ptr_ops2.rs:11:26
|
||||
--> $DIR/const_raw_ptr_ops2.rs:9:26
|
||||
|
|
||||
LL | const Z3: i32 = unsafe { *(44 as *const i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^ 0x2c is not a valid pointer
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
// Make sure we error with the right kind of error on a too large slice.
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/dangling.rs:8:16
|
||||
--> $DIR/dangling.rs:6:16
|
||||
|
|
||||
LL | let _val = &*slice;
|
||||
| ^^^^^^^ invalid metadata in wide pointer: slice is bigger than largest supported object
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
use std::intrinsics;
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/alloc_intrinsic_errors.rs:10:17
|
||||
--> $DIR/alloc_intrinsic_errors.rs:9:17
|
||||
|
|
||||
LL | const FOO: i32 = foo();
|
||||
| ----- inside `FOO` at $DIR/alloc_intrinsic_errors.rs:7:18
|
||||
| ----- inside `FOO` at $DIR/alloc_intrinsic_errors.rs:6:18
|
||||
...
|
||||
LL | let _ = intrinsics::const_allocate(4, 3) as * mut i32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| align has to be a power of 2, `3` is not a power of 2
|
||||
| inside `foo` at $DIR/alloc_intrinsic_errors.rs:10:17
|
||||
| inside `foo` at $DIR/alloc_intrinsic_errors.rs:9:17
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// run-pass
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
use std::intrinsics;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
use std::intrinsics;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: untyped pointers are not allowed in constant
|
||||
--> $DIR/alloc_intrinsic_nontransient_fail.rs:7:1
|
||||
--> $DIR/alloc_intrinsic_nontransient_fail.rs:6:1
|
||||
|
|
||||
LL | const FOO: *const i32 = foo();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,7 +1,6 @@
|
||||
// run-pass
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
use std::intrinsics;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/alloc_intrinsic_uninit.rs:9:1
|
||||
--> $DIR/alloc_intrinsic_uninit.rs:8:1
|
||||
|
|
||||
LL | const BAR: &i32 = unsafe { &*(intrinsics::const_allocate(4, 4) as *mut i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/alloc_intrinsic_uninit.rs:9:1
|
||||
--> $DIR/alloc_intrinsic_uninit.rs:8:1
|
||||
|
|
||||
LL | const BAR: &i32 = unsafe { &*(intrinsics::const_allocate(4, 4) as *mut i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
|
||||
|
@ -2,7 +2,6 @@
|
||||
// compile-test
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
use std::intrinsics;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_heap)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
use std::intrinsics;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: untyped pointers are not allowed in constant
|
||||
--> $DIR/alloc_intrinsic_untyped.rs:7:1
|
||||
--> $DIR/alloc_intrinsic_untyped.rs:6:1
|
||||
|
|
||||
LL | const BAR: *mut i32 = unsafe { intrinsics::const_allocate(4, 4) as *mut i32};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,7 +1,7 @@
|
||||
// New test for #53818: modifying static memory at compile-time is not allowed.
|
||||
// The test should never compile successfully
|
||||
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
@ -14,7 +14,7 @@ static FOO: Foo = Foo(UnsafeCell::new(42));
|
||||
|
||||
static BAR: () = unsafe {
|
||||
*FOO.0.get() = 5;
|
||||
//~^ mutation through a reference
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
};
|
||||
|
||||
fn main() {
|
||||
|
@ -1,12 +1,9 @@
|
||||
error[E0658]: mutation through a reference is not allowed in statics
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/mod-static-with-const-fn.rs:16:5
|
||||
|
|
||||
LL | *FOO.0.get() = 5;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
| ^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Test for the behavior described in <https://github.com/rust-lang/rust/issues/87184>.
|
||||
#![feature(const_mut_refs, const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
|
||||
const PARTIAL_OVERWRITE: () = {
|
||||
let mut p = &42;
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
fn main() {
|
||||
let x: &'static bool = &(42 as *const i32 == 43 as *const i32);
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:4:29
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:2:29
|
||||
|
|
||||
LL | let x: &'static bool = &(42 as *const i32 == 43 as *const i32);
|
||||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
@ -10,7 +10,7 @@ LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:6:30
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:4:30
|
||||
|
|
||||
LL | let y: &'static usize = &(&1 as *const i32 as usize + 1);
|
||||
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
@ -21,7 +21,7 @@ LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:8:28
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:6:28
|
||||
|
|
||||
LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) });
|
||||
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
@ -32,7 +32,7 @@ LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:10:29
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:8:29
|
||||
|
|
||||
LL | let a: &'static bool = &(main as fn() == main as fn());
|
||||
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(raw_ref_op)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
const NULL: *mut i32 = std::ptr::null_mut();
|
||||
const A: *const i32 = &4;
|
||||
|
@ -1,11 +1,11 @@
|
||||
error[E0764]: mutable references are not allowed in the final value of constants
|
||||
--> $DIR/mut_ref_in_final.rs:11:21
|
||||
--> $DIR/mut_ref_in_final.rs:10:21
|
||||
|
|
||||
LL | const B: *mut i32 = &mut 4;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/mut_ref_in_final.rs:17:40
|
||||
--> $DIR/mut_ref_in_final.rs:16:40
|
||||
|
|
||||
LL | const B3: Option<&mut i32> = Some(&mut 42);
|
||||
| ----------^^-
|
||||
@ -15,7 +15,7 @@ LL | const B3: Option<&mut i32> = Some(&mut 42);
|
||||
| using this value as a constant requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/mut_ref_in_final.rs:20:42
|
||||
--> $DIR/mut_ref_in_final.rs:19:42
|
||||
|
|
||||
LL | const B4: Option<&mut i32> = helper(&mut 42);
|
||||
| ------------^^-
|
||||
@ -25,7 +25,7 @@ LL | const B4: Option<&mut i32> = helper(&mut 42);
|
||||
| using this value as a constant requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/mut_ref_in_final.rs:35:65
|
||||
--> $DIR/mut_ref_in_final.rs:34:65
|
||||
|
|
||||
LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
| -------------------------------^^--
|
||||
@ -35,7 +35,7 @@ LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
| using this value as a constant requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/mut_ref_in_final.rs:38:67
|
||||
--> $DIR/mut_ref_in_final.rs:37:67
|
||||
|
|
||||
LL | static FOO2: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
| -------------------------------^^--
|
||||
@ -45,7 +45,7 @@ LL | static FOO2: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
| using this value as a static requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/mut_ref_in_final.rs:41:71
|
||||
--> $DIR/mut_ref_in_final.rs:40:71
|
||||
|
|
||||
LL | static mut FOO3: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
| -------------------------------^^--
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(raw_ref_op)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
// This file checks that our dynamic checks catch things that the static checks miss.
|
||||
// We do not have static checks for these, because we do not look into function bodies.
|
||||
|
@ -1,17 +1,17 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/mut_ref_in_final_dynamic_check.rs:14:10
|
||||
--> $DIR/mut_ref_in_final_dynamic_check.rs:13:10
|
||||
|
|
||||
LL | Some(&mut *(42 as *mut i32))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| 0x2a is not a valid pointer
|
||||
| inside `helper` at $DIR/mut_ref_in_final_dynamic_check.rs:14:10
|
||||
| inside `helper` at $DIR/mut_ref_in_final_dynamic_check.rs:13:10
|
||||
...
|
||||
LL | const A: Option<&mut i32> = helper();
|
||||
| -------- inside `A` at $DIR/mut_ref_in_final_dynamic_check.rs:19:29
|
||||
| -------- inside `A` at $DIR/mut_ref_in_final_dynamic_check.rs:18:29
|
||||
|
||||
error: encountered dangling pointer in final constant
|
||||
--> $DIR/mut_ref_in_final_dynamic_check.rs:26:1
|
||||
--> $DIR/mut_ref_in_final_dynamic_check.rs:25:1
|
||||
|
|
||||
LL | const B: Option<&mut i32> = helper2();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,7 +1,7 @@
|
||||
const WRITE: () = unsafe {
|
||||
*std::ptr::null_mut() = 0;
|
||||
//~^ ERROR dereferencing raw pointers in constants is unstable
|
||||
//~| HELP add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
//~^ ERROR dereferencing raw mutable pointers in constants is unstable
|
||||
//~| HELP add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,11 +1,11 @@
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
error[E0658]: dereferencing raw mutable pointers in constants is unstable
|
||||
--> $DIR/const-suggest-feature.rs:2:5
|
||||
|
|
||||
LL | *std::ptr::null_mut() = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
// build-pass (FIXME(62277): could be check-pass?)
|
||||
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
// check-pass
|
||||
|
||||
const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const str) };
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
// check-pass
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
use std::ptr;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } }
|
||||
//~^ dereferencing raw pointers in constant functions
|
||||
//~^ dereferencing raw mutable pointers in constant functions
|
||||
|
||||
const unsafe fn bad_const_unsafe_deref_raw(x: *mut usize) -> usize { *x }
|
||||
//~^ dereferencing raw pointers in constant functions
|
||||
//~^ dereferencing raw mutable pointers in constant functions
|
||||
|
||||
const unsafe fn bad_const_unsafe_deref_raw_ref(x: *mut usize) -> &'static usize { &*x }
|
||||
//~^ dereferencing raw pointers in constant functions
|
||||
//~^ dereferencing raw mutable pointers in constant functions
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,29 +1,29 @@
|
||||
error[E0658]: dereferencing raw pointers in constant functions is unstable
|
||||
error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
|
||||
--> $DIR/min_const_fn_unsafe_bad.rs:1:77
|
||||
|
|
||||
LL | const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } }
|
||||
| ^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constant functions is unstable
|
||||
error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
|
||||
--> $DIR/min_const_fn_unsafe_bad.rs:4:70
|
||||
|
|
||||
LL | const unsafe fn bad_const_unsafe_deref_raw(x: *mut usize) -> usize { *x }
|
||||
| ^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constant functions is unstable
|
||||
error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
|
||||
--> $DIR/min_const_fn_unsafe_bad.rs:7:83
|
||||
|
|
||||
LL | const unsafe fn bad_const_unsafe_deref_raw_ref(x: *mut usize) -> &'static usize { &*x }
|
||||
| ^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -33,11 +33,6 @@ help: skipping check that does not even have a feature gate
|
||||
|
|
||||
LL | unsafe { *(&FOO as *const _ as *const usize) }
|
||||
| ^^^
|
||||
help: skipping check for `const_raw_ptr_deref` feature
|
||||
--> $DIR/const_refers_to_static.rs:18:14
|
||||
|
|
||||
LL | unsafe { *(&FOO as *const _ as *const usize) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: skipping check that does not even have a feature gate
|
||||
--> $DIR/const_refers_to_static.rs:22:32
|
||||
|
|
||||
|
@ -35,11 +35,6 @@ help: skipping check that does not even have a feature gate
|
||||
|
|
||||
LL | unsafe { &*(&FOO as *const _ as *const usize) }
|
||||
| ^^^
|
||||
help: skipping check for `const_raw_ptr_deref` feature
|
||||
--> $DIR/const_refers_to_static2.rs:14:14
|
||||
|
|
||||
LL | unsafe { &*(&FOO as *const _ as *const usize) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: skipping check that does not even have a feature gate
|
||||
--> $DIR/const_refers_to_static2.rs:21:6
|
||||
|
|
||||
|
@ -35,11 +35,6 @@ help: skipping check that does not even have a feature gate
|
||||
|
|
||||
LL | unsafe { &*(&FOO as *const _ as *const usize) }
|
||||
| ^^^
|
||||
help: skipping check for `const_raw_ptr_deref` feature
|
||||
--> $DIR/const_refers_to_static2.rs:14:14
|
||||
|
|
||||
LL | unsafe { &*(&FOO as *const _ as *const usize) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: skipping check that does not even have a feature gate
|
||||
--> $DIR/const_refers_to_static2.rs:21:6
|
||||
|
|
||||
|
@ -1,6 +1,5 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_ptr_offset_from)]
|
||||
|
||||
struct Struct {
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_ptr_offset_from)]
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/offset_from_ub.rs:18:27
|
||||
--> $DIR/offset_from_ub.rs:17:27
|
||||
|
|
||||
LL | let offset = unsafe { ptr_offset_from(field_ptr, base_ptr) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ptr_offset_from cannot compute offset of pointers into different allocations.
|
||||
@ -13,25 +13,25 @@ LL | unsafe { intrinsics::ptr_offset_from(self, origin) }
|
||||
| 0x2a is not a valid pointer
|
||||
| inside `ptr::const_ptr::<impl *const u8>::offset_from` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
|
||||
::: $DIR/offset_from_ub.rs:24:14
|
||||
::: $DIR/offset_from_ub.rs:23:14
|
||||
|
|
||||
LL | unsafe { (42 as *const u8).offset_from(&5u8) as usize }
|
||||
| ----------------------------------- inside `NOT_PTR` at $DIR/offset_from_ub.rs:24:14
|
||||
| ----------------------------------- inside `NOT_PTR` at $DIR/offset_from_ub.rs:23:14
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/offset_from_ub.rs:31:14
|
||||
--> $DIR/offset_from_ub.rs:30:14
|
||||
|
|
||||
LL | unsafe { ptr_offset_from(field_ptr, base_ptr as *const u16) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exact_div: 1_isize cannot be divided by 2_isize without remainder
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/offset_from_ub.rs:37:14
|
||||
--> $DIR/offset_from_ub.rs:36:14
|
||||
|
|
||||
LL | unsafe { ptr_offset_from(ptr, ptr) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ null pointer is not a valid pointer for this operation
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/offset_from_ub.rs:44:14
|
||||
--> $DIR/offset_from_ub.rs:43:14
|
||||
|
|
||||
LL | unsafe { ptr_offset_from(ptr2, ptr1) }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0x10 is not a valid pointer
|
||||
|
@ -8,7 +8,6 @@
|
||||
core_intrinsics,
|
||||
const_raw_ptr_comparison,
|
||||
const_ptr_offset,
|
||||
const_raw_ptr_deref
|
||||
)]
|
||||
|
||||
const FOO: &usize = &42;
|
||||
|
@ -7,19 +7,19 @@ LL | unsafe { intrinsics::offset(self, count) }
|
||||
| pointer arithmetic failed: alloc3 has size $WORD, so pointer to $TWO_WORDS bytes starting at offset 0 is out-of-bounds
|
||||
| inside `ptr::const_ptr::<impl *const usize>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
||||
|
|
||||
::: $DIR/ptr_comparisons.rs:60:34
|
||||
::: $DIR/ptr_comparisons.rs:59:34
|
||||
|
|
||||
LL | const _: *const usize = unsafe { (FOO as *const usize).offset(2) };
|
||||
| ------------------------------- inside `_` at $DIR/ptr_comparisons.rs:60:34
|
||||
| ------------------------------- inside `_` at $DIR/ptr_comparisons.rs:59:34
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/ptr_comparisons.rs:63:33
|
||||
--> $DIR/ptr_comparisons.rs:62:33
|
||||
|
|
||||
LL | unsafe { std::ptr::addr_of!((*(FOO as *const usize as *const [u8; 1000]))[999]) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: alloc3 has size $WORD, so pointer to 1000 bytes starting at offset 0 is out-of-bounds
|
||||
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/ptr_comparisons.rs:67:27
|
||||
--> $DIR/ptr_comparisons.rs:66:27
|
||||
|
|
||||
LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 };
|
||||
| --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
@ -31,7 +31,7 @@ LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) +
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/ptr_comparisons.rs:72:27
|
||||
--> $DIR/ptr_comparisons.rs:71:27
|
||||
|
|
||||
LL | const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 };
|
||||
| --------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
|
||||
|
@ -1,5 +1,5 @@
|
||||
// stderr-per-bitwidth
|
||||
#![feature(const_raw_ptr_deref, never_type)]
|
||||
#![feature(never_type)]
|
||||
|
||||
const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR undefined behavior
|
||||
const _: &[!; 0] = unsafe { &*(1_usize as *const [!; 0]) }; // ok
|
||||
|
@ -1,12 +0,0 @@
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/write_to_mut_ref_dest.rs:11:18
|
||||
|
|
||||
LL | unsafe { *b = 5; }
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
@ -1,4 +1,5 @@
|
||||
// revisions: stock mut_refs
|
||||
//[mut_refs] check-pass
|
||||
|
||||
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
||||
|
||||
@ -8,7 +9,7 @@ const FOO: &u32 = {
|
||||
let mut a = 42;
|
||||
{
|
||||
let b: *mut u32 = &mut a; //[stock]~ ERROR mutable references are not allowed in constants
|
||||
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
|
||||
unsafe { *b = 5; } //[stock]~ ERROR dereferencing raw mutable pointers in constants
|
||||
}
|
||||
&{a}
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/write_to_mut_ref_dest.rs:10:27
|
||||
--> $DIR/write_to_mut_ref_dest.rs:11:27
|
||||
|
|
||||
LL | let b: *mut u32 = &mut a;
|
||||
| ^^^^^^
|
||||
@ -7,14 +7,14 @@ LL | let b: *mut u32 = &mut a;
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/write_to_mut_ref_dest.rs:11:18
|
||||
error[E0658]: dereferencing raw mutable pointers in constants is unstable
|
||||
--> $DIR/write_to_mut_ref_dest.rs:12:18
|
||||
|
|
||||
LL | unsafe { *b = 5; }
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// run-pass
|
||||
#![feature(arbitrary_enum_discriminant, const_raw_ptr_deref, test)]
|
||||
#![feature(arbitrary_enum_discriminant, test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(const_mut_refs)]
|
||||
|
||||
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
|
||||
const REG_ADDR: *mut u8 = 0x5f3759df as *mut u8;
|
||||
|
||||
const VALUE: u8 = unsafe { *REG_ADDR };
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
|
@ -1,19 +1,17 @@
|
||||
// gate-test-const_raw_ptr_deref
|
||||
|
||||
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
|
||||
const REG_ADDR: *mut u8 = 0x5f3759df as *mut u8;
|
||||
|
||||
const VALUE: u8 = unsafe { *REG_ADDR };
|
||||
//~^ ERROR dereferencing raw pointers in constants is unstable
|
||||
//~^ ERROR dereferencing raw mutable pointers in constants is unstable
|
||||
|
||||
const unsafe fn unreachable() -> ! {
|
||||
use std::convert::Infallible;
|
||||
|
||||
const INFALLIBLE: *const Infallible = [].as_ptr();
|
||||
const INFALLIBLE: *mut Infallible = &[] as *const [Infallible] as *const _ as _;
|
||||
match *INFALLIBLE {}
|
||||
//~^ ERROR dereferencing raw pointers in constant functions is unstable
|
||||
//~^ ERROR dereferencing raw mutable pointers in constant functions is unstable
|
||||
|
||||
const BAD: () = unsafe { match *INFALLIBLE {} };
|
||||
//~^ ERROR dereferencing raw pointers in constants is unstable
|
||||
//~^ ERROR dereferencing raw mutable pointers in constants is unstable
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,29 +1,29 @@
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/E0396.rs:5:28
|
||||
error[E0658]: dereferencing raw mutable pointers in constants is unstable
|
||||
--> $DIR/E0396.rs:3:28
|
||||
|
|
||||
LL | const VALUE: u8 = unsafe { *REG_ADDR };
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constant functions is unstable
|
||||
--> $DIR/E0396.rs:12:11
|
||||
error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
|
||||
--> $DIR/E0396.rs:10:11
|
||||
|
|
||||
LL | match *INFALLIBLE {}
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/E0396.rs:15:36
|
||||
error[E0658]: dereferencing raw mutable pointers in constants is unstable
|
||||
--> $DIR/E0396.rs:13:36
|
||||
|
|
||||
LL | const BAD: () = unsafe { match *INFALLIBLE {} };
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:11:5
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:10:5
|
||||
|
|
||||
LL | *a == b
|
||||
| ^^ dereference of raw pointer
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#![stable(feature = "foo", since = "1.33.0")]
|
||||
#![feature(staged_api)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
||||
#[stable(feature = "foo", since = "1.33.0")]
|
||||
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:11:5
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:10:5
|
||||
|
|
||||
LL | *a == b
|
||||
| ^^ dereference of raw pointer
|
||||
|
Loading…
Reference in New Issue
Block a user