Skip to content

Commit 8f1716c

Browse files
authored
Rollup merge of #81128 - RalfJung:validation-testing, r=oli-obk
validation test: turn some const_err back into validation failures This resolves the problem I raised at #78407 (comment). r? `@oli-obk`
2 parents f82100e + 514543a commit 8f1716c

File tree

2 files changed

+59
-81
lines changed

2 files changed

+59
-81
lines changed

src/test/ui/consts/const-eval/ub-wide-ptr.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ use std::mem;
88
// normalize-stderr-test "alloc\d+" -> "allocN"
99
// normalize-stderr-test "size \d+" -> "size N"
1010

11+
/// A newtype wrapper to prevent MIR generation from inserting reborrows that would affect the error
12+
/// message. Use this whenever the message is "any use of this value will cause an error" instead of
13+
/// "it is undefined behavior to use this value".
14+
#[repr(transparent)]
15+
struct W<T>(T);
16+
1117
#[repr(C)]
1218
union MaybeUninit<T: Copy> {
1319
uninit: (),
@@ -95,26 +101,22 @@ const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
95101

96102
// # trait object
97103
// bad trait object
98-
#[warn(const_err)]
99-
const TRAIT_OBJ_SHORT_VTABLE_1: &dyn Trait = unsafe { mem::transmute((&92u8, &3u8)) };
100-
//~^ WARN any use of this value will cause an error [const_err]
104+
const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
105+
//~^ ERROR it is undefined behavior to use this value
101106
// bad trait object
102-
#[warn(const_err)]
103-
const TRAIT_OBJ_SHORT_VTABLE_2: &dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
104-
//~^ WARN any use of this value will cause an error [const_err]
107+
const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
108+
//~^ ERROR it is undefined behavior to use this value
105109
// bad trait object
106-
#[warn(const_err)]
107-
const TRAIT_OBJ_INT_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, 4usize)) };
108-
//~^ WARN any use of this value will cause an error [const_err]
110+
const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
111+
//~^ ERROR it is undefined behavior to use this value
109112
const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
110113
//~^ ERROR it is undefined behavior to use this value
111114
const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
112115
//~^ ERROR it is undefined behavior to use this value
113116
const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
114117
//~^ ERROR it is undefined behavior to use this value
115-
#[warn(const_err)]
116-
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: &dyn Trait = unsafe { mem::transmute((&92u8, &[&42u8; 8])) };
117-
//~^ WARN any use of this value will cause an error [const_err]
118+
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
119+
//~^ ERROR it is undefined behavior to use this value
118120

119121
// bad data *inside* the trait object
120122
const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };

0 commit comments

Comments
 (0)