Stabilize const_ptr_read

This commit is contained in:
bors 2023-05-05 12:50:59 +00:00 committed by Albin Hedman
parent 4a18324a4d
commit 81c2459af6
17 changed files with 35 additions and 42 deletions

View File

@ -113,7 +113,6 @@
#![feature(const_maybe_uninit_write)] #![feature(const_maybe_uninit_write)]
#![feature(const_maybe_uninit_zeroed)] #![feature(const_maybe_uninit_zeroed)]
#![feature(const_pin)] #![feature(const_pin)]
#![feature(const_ptr_read)]
#![feature(const_refs_to_cell)] #![feature(const_refs_to_cell)]
#![feature(const_size_of_val)] #![feature(const_size_of_val)]
#![feature(const_waker)] #![feature(const_waker)]

View File

@ -2260,7 +2260,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
/// This intrinsic can *only* be called where the pointer is a local without /// This intrinsic can *only* be called where the pointer is a local without
/// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it /// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it
/// trivially obeys runtime-MIR rules about derefs in operands. /// trivially obeys runtime-MIR rules about derefs in operands.
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[rustc_nounwind] #[rustc_nounwind]
pub fn read_via_copy<T>(ptr: *const T) -> T; pub fn read_via_copy<T>(ptr: *const T) -> T;

View File

@ -140,7 +140,6 @@
#![feature(const_pointer_is_aligned)] #![feature(const_pointer_is_aligned)]
#![feature(const_ptr_as_ref)] #![feature(const_ptr_as_ref)]
#![feature(const_ptr_is_null)] #![feature(const_ptr_is_null)]
#![feature(const_ptr_read)]
#![feature(const_ptr_sub_ptr)] #![feature(const_ptr_sub_ptr)]
#![feature(const_ptr_write)] #![feature(const_ptr_write)]
#![feature(const_raw_ptr_comparison)] #![feature(const_raw_ptr_comparison)]

View File

@ -1195,7 +1195,7 @@ pub const fn wrapping_byte_sub(self, count: usize) -> Self {
/// ///
/// [`ptr::read`]: crate::ptr::read() /// [`ptr::read`]: crate::ptr::read()
#[stable(feature = "pointer_methods", since = "1.26.0")] #[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[inline] #[inline]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn read(self) -> T pub const unsafe fn read(self) -> T
@ -1236,7 +1236,7 @@ pub unsafe fn read_volatile(self) -> T
/// ///
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
#[stable(feature = "pointer_methods", since = "1.26.0")] #[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[inline] #[inline]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn read_unaligned(self) -> T pub const unsafe fn read_unaligned(self) -> T

View File

@ -1133,7 +1133,8 @@ macro_rules! attempt_swap_as_chunks {
/// [valid]: self#safety /// [valid]: self#safety
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_mut_refs, const_maybe_uninit_as_mut_ptr)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn read<T>(src: *const T) -> T { pub const unsafe fn read<T>(src: *const T) -> T {
// It would be semantically correct to implement this via `copy_nonoverlapping` // It would be semantically correct to implement this via `copy_nonoverlapping`
@ -1249,7 +1250,8 @@ macro_rules! attempt_swap_as_chunks {
/// ``` /// ```
#[inline] #[inline]
#[stable(feature = "ptr_unaligned", since = "1.17.0")] #[stable(feature = "ptr_unaligned", since = "1.17.0")]
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[rustc_allow_const_fn_unstable(const_mut_refs, const_maybe_uninit_as_mut_ptr)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn read_unaligned<T>(src: *const T) -> T { pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
let mut tmp = MaybeUninit::<T>::uninit(); let mut tmp = MaybeUninit::<T>::uninit();

View File

@ -1305,7 +1305,7 @@ pub const fn wrapping_byte_sub(self, count: usize) -> Self {
/// ///
/// [`ptr::read`]: crate::ptr::read() /// [`ptr::read`]: crate::ptr::read()
#[stable(feature = "pointer_methods", since = "1.26.0")] #[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[inline(always)] #[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn read(self) -> T pub const unsafe fn read(self) -> T
@ -1346,7 +1346,7 @@ pub unsafe fn read_volatile(self) -> T
/// ///
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
#[stable(feature = "pointer_methods", since = "1.26.0")] #[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[inline(always)] #[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn read_unaligned(self) -> T pub const unsafe fn read_unaligned(self) -> T

View File

@ -18,7 +18,6 @@
#![feature(const_pointer_byte_offsets)] #![feature(const_pointer_byte_offsets)]
#![feature(const_pointer_is_aligned)] #![feature(const_pointer_is_aligned)]
#![feature(const_ptr_as_ref)] #![feature(const_ptr_as_ref)]
#![feature(const_ptr_read)]
#![feature(const_ptr_write)] #![feature(const_ptr_write)]
#![feature(const_trait_impl)] #![feature(const_trait_impl)]
#![feature(const_likely)] #![feature(const_likely)]

View File

@ -1,4 +1,3 @@
#![feature(const_ptr_read)]
const UNALIGNED_READ: () = unsafe { const UNALIGNED_READ: () = unsafe {
let x = &[0u8; 4]; let x = &[0u8; 4];

View File

@ -1,7 +1,7 @@
// check-pass // check-pass
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![feature(adt_const_params, const_ptr_read, generic_const_exprs)] #![feature(adt_const_params, generic_const_exprs)]
#![allow(dead_code)] #![allow(dead_code)]
const fn catone<const M: usize>(_a: &[u8; M]) -> [u8; M + 1] const fn catone<const M: usize>(_a: &[u8; M]) -> [u8; M + 1]

View File

@ -1,7 +1,5 @@
// error-pattern: evaluation of constant value failed // error-pattern: evaluation of constant value failed
#![feature(const_ptr_read)]
fn main() { fn main() {
use std::ptr; use std::ptr;

View File

@ -6,7 +6,7 @@ error[E0080]: evaluation of constant value failed
note: inside `std::ptr::read::<u32>` note: inside `std::ptr::read::<u32>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
note: inside `_READ` note: inside `_READ`
--> $DIR/out_of_bounds_read.rs:12:33 --> $DIR/out_of_bounds_read.rs:10:33
| |
LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) }; LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
@ -21,7 +21,7 @@ note: inside `std::ptr::read::<u32>`
note: inside `ptr::const_ptr::<impl *const u32>::read` note: inside `ptr::const_ptr::<impl *const u32>::read`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
note: inside `_CONST_READ` note: inside `_CONST_READ`
--> $DIR/out_of_bounds_read.rs:13:39 --> $DIR/out_of_bounds_read.rs:11:39
| |
LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() }; LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
@ -36,7 +36,7 @@ note: inside `std::ptr::read::<u32>`
note: inside `ptr::mut_ptr::<impl *mut u32>::read` note: inside `ptr::mut_ptr::<impl *mut u32>::read`
--> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL --> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
note: inside `_MUT_READ` note: inside `_MUT_READ`
--> $DIR/out_of_bounds_read.rs:14:37 --> $DIR/out_of_bounds_read.rs:12:37
| |
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() }; LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -3,7 +3,6 @@
// normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" // normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
// normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP" // normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP"
#![allow(invalid_value)] #![allow(invalid_value)]
#![feature(const_ptr_read)]
use std::mem; use std::mem;

View File

@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:16:1 --> $DIR/ub-ref-ptr.rs:15:1
| |
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
@ -10,7 +10,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:20:1 --> $DIR/ub-ref-ptr.rs:19:1
| |
LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) }; LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1)
@ -21,7 +21,7 @@ LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:24:1 --> $DIR/ub-ref-ptr.rs:23:1
| |
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
@ -32,7 +32,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:27:1 --> $DIR/ub-ref-ptr.rs:26:1
| |
LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) }; LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box
@ -43,7 +43,7 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
} }
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:34:1 --> $DIR/ub-ref-ptr.rs:33:1
| |
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
@ -52,7 +52,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:37:39 --> $DIR/ub-ref-ptr.rs:36:39
| |
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
@ -61,13 +61,13 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
note: erroneous constant used note: erroneous constant used
--> $DIR/ub-ref-ptr.rs:37:38 --> $DIR/ub-ref-ptr.rs:36:38
| |
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:40:86 --> $DIR/ub-ref-ptr.rs:39:86
| |
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
| ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes | ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
@ -76,13 +76,13 @@ LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[us
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
note: erroneous constant used note: erroneous constant used
--> $DIR/ub-ref-ptr.rs:40:85 --> $DIR/ub-ref-ptr.rs:39:85
| |
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:43:1 --> $DIR/ub-ref-ptr.rs:42:1
| |
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance)
@ -93,7 +93,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:46:1 --> $DIR/ub-ref-ptr.rs:45:1
| |
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) }; LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance)
@ -104,13 +104,13 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
} }
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:49:41 --> $DIR/ub-ref-ptr.rs:48:41
| |
LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:53:1 --> $DIR/ub-ref-ptr.rs:52:1
| |
LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) }; LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
@ -121,13 +121,13 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
} }
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:55:38 --> $DIR/ub-ref-ptr.rs:54:38
| |
LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:58:1 --> $DIR/ub-ref-ptr.rs:57:1
| |
LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) }; LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
@ -138,7 +138,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
} }
error[E0080]: it is undefined behavior to use this value error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-ref-ptr.rs:60:1 --> $DIR/ub-ref-ptr.rs:59:1
| |
LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer
@ -158,7 +158,7 @@ note: inside `std::ptr::read::<u32>`
note: inside `ptr::const_ptr::<impl *const u32>::read` note: inside `ptr::const_ptr::<impl *const u32>::read`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
note: inside `UNALIGNED_READ` note: inside `UNALIGNED_READ`
--> $DIR/ub-ref-ptr.rs:67:5 --> $DIR/ub-ref-ptr.rs:66:5
| |
LL | ptr.read(); LL | ptr.read();
| ^^^^^^^^^^ | ^^^^^^^^^^

View File

@ -1,7 +1,6 @@
// revisions: no_flag with_flag // revisions: no_flag with_flag
// [no_flag] check-pass // [no_flag] check-pass
// [with_flag] compile-flags: -Zextra-const-ub-checks // [with_flag] compile-flags: -Zextra-const-ub-checks
#![feature(const_ptr_read)]
use std::mem::transmute; use std::mem::transmute;

View File

@ -1,11 +1,11 @@
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/detect-extra-ub.rs:9:20 --> $DIR/detect-extra-ub.rs:8:20
| |
LL | let _x: bool = transmute(3u8); LL | let _x: bool = transmute(3u8);
| ^^^^^^^^^^^^^^ constructing invalid value: encountered 0x03, but expected a boolean | ^^^^^^^^^^^^^^ constructing invalid value: encountered 0x03, but expected a boolean
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/detect-extra-ub.rs:15:21 --> $DIR/detect-extra-ub.rs:14:21
| |
LL | let _x: usize = transmute(&3u8); LL | let _x: usize = transmute(&3u8);
| ^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes | ^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
@ -14,7 +14,7 @@ LL | let _x: usize = transmute(&3u8);
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/detect-extra-ub.rs:21:30 --> $DIR/detect-extra-ub.rs:20:30
| |
LL | let _x: (usize, usize) = transmute(x); LL | let _x: (usize, usize) = transmute(x);
| ^^^^^^^^^^^^ unable to turn pointer into raw bytes | ^^^^^^^^^^^^ unable to turn pointer into raw bytes
@ -23,7 +23,7 @@ LL | let _x: (usize, usize) = transmute(x);
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed error[E0080]: evaluation of constant value failed
--> $DIR/detect-extra-ub.rs:26:20 --> $DIR/detect-extra-ub.rs:25:20
| |
LL | let _x: &u32 = transmute(&[0u8; 4]); LL | let _x: &u32 = transmute(&[0u8; 4]);
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 4 byte alignment but found 1) | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 4 byte alignment but found 1)

View File

@ -1,6 +1,5 @@
// error-pattern unable to turn pointer into raw bytes // error-pattern unable to turn pointer into raw bytes
// normalize-stderr-test: "alloc[0-9]+\+0x[a-z0-9]+" -> "ALLOC" // normalize-stderr-test: "alloc[0-9]+\+0x[a-z0-9]+" -> "ALLOC"
#![feature(const_ptr_read)]
const C: () = unsafe { const C: () = unsafe {
let foo = Some(&42 as *const i32); let foo = Some(&42 as *const i32);

View File

@ -10,7 +10,7 @@ note: inside `std::ptr::read::<u8>`
note: inside `ptr::const_ptr::<impl *const u8>::read` note: inside `ptr::const_ptr::<impl *const u8>::read`
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
note: inside `C` note: inside `C`
--> $DIR/issue-miri-1910.rs:8:5 --> $DIR/issue-miri-1910.rs:7:5
| |
LL | (&foo as *const _ as *const u8).add(one_and_a_half_pointers).read(); LL | (&foo as *const _ as *const u8).add(one_and_a_half_pointers).read();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^