Skip to content

Commit 8f1716c

Browse files
authoredJan 18, 2021
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`
·
1.88.01.51.0
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

Lines changed: 14 additions & 12 deletions
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) };
Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-wide-ptr.rs:31:1
2+
--> $DIR/ub-wide-ptr.rs:37:1
33
|
44
LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (going beyond the bounds of its allocation)
66
|
77
= 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.
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/ub-wide-ptr.rs:33:1
10+
--> $DIR/ub-wide-ptr.rs:39:1
1111
|
1212
LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid reference metadata: slice is bigger than largest supported object at .0
1414
|
1515
= 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.
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/ub-wide-ptr.rs:36:1
18+
--> $DIR/ub-wide-ptr.rs:42:1
1919
|
2020
LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
2222
|
2323
= 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.
2424

2525
error[E0080]: it is undefined behavior to use this value
26-
--> $DIR/ub-wide-ptr.rs:39:1
26+
--> $DIR/ub-wide-ptr.rs:45:1
2727
|
2828
LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
3030
|
3131
= 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.
3232

3333
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/ub-wide-ptr.rs:41:1
34+
--> $DIR/ub-wide-ptr.rs:47:1
3535
|
3636
LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid reference metadata: slice is bigger than largest supported object
3838
|
3939
= 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.
4040

4141
error[E0080]: it is undefined behavior to use this value
42-
--> $DIR/ub-wide-ptr.rs:45:1
42+
--> $DIR/ub-wide-ptr.rs:51:1
4343
|
4444
LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized data in `str` at .<deref>
4646
|
4747
= 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.
4848

4949
error[E0080]: it is undefined behavior to use this value
50-
--> $DIR/ub-wide-ptr.rs:48:1
50+
--> $DIR/ub-wide-ptr.rs:54:1
5151
|
5252
LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized data in `str` at .<deref>.0
5454
|
5555
= 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.
5656

5757
error[E0080]: it is undefined behavior to use this value
58-
--> $DIR/ub-wide-ptr.rs:55:1
58+
--> $DIR/ub-wide-ptr.rs:61:1
5959
|
6060
LL | / const SLICE_LENGTH_UNINIT: &[u8] = unsafe {
6161
LL | |
@@ -67,63 +67,63 @@ LL | | };
6767
= 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.
6868

6969
error[E0080]: it is undefined behavior to use this value
70-
--> $DIR/ub-wide-ptr.rs:61:1
70+
--> $DIR/ub-wide-ptr.rs:67:1
7171
|
7272
LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (going beyond the bounds of its allocation)
7474
|
7575
= 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.
7676

7777
error[E0080]: it is undefined behavior to use this value
78-
--> $DIR/ub-wide-ptr.rs:64:1
78+
--> $DIR/ub-wide-ptr.rs:70:1
7979
|
8080
LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
8181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
8282
|
8383
= 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.
8484

8585
error[E0080]: it is undefined behavior to use this value
86-
--> $DIR/ub-wide-ptr.rs:67:1
86+
--> $DIR/ub-wide-ptr.rs:73:1
8787
|
8888
LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (going beyond the bounds of its allocation)
9090
|
9191
= 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.
9292

9393
error[E0080]: it is undefined behavior to use this value
94-
--> $DIR/ub-wide-ptr.rs:70:1
94+
--> $DIR/ub-wide-ptr.rs:76:1
9595
|
9696
LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
9898
|
9999
= 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.
100100

101101
error[E0080]: it is undefined behavior to use this value
102-
--> $DIR/ub-wide-ptr.rs:74:1
102+
--> $DIR/ub-wide-ptr.rs:80:1
103103
|
104104
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
105105
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>[0], but expected a boolean
106106
|
107107
= 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.
108108

109109
error[E0080]: it is undefined behavior to use this value
110-
--> $DIR/ub-wide-ptr.rs:80:1
110+
--> $DIR/ub-wide-ptr.rs:86:1
111111
|
112112
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
113113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>.0, but expected a boolean
114114
|
115115
= 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.
116116

117117
error[E0080]: it is undefined behavior to use this value
118-
--> $DIR/ub-wide-ptr.rs:83:1
118+
--> $DIR/ub-wide-ptr.rs:89:1
119119
|
120120
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>.1[0], but expected a boolean
122122
|
123123
= 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.
124124

125125
error[E0080]: it is undefined behavior to use this value
126-
--> $DIR/ub-wide-ptr.rs:90:1
126+
--> $DIR/ub-wide-ptr.rs:96:1
127127
|
128128
LL | / const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
129129
LL | |
@@ -134,122 +134,98 @@ LL | | };
134134
|
135135
= 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.
136136

137-
warning: any use of this value will cause an error
138-
--> $DIR/ub-wide-ptr.rs:99:55
139-
|
140-
LL | const TRAIT_OBJ_SHORT_VTABLE_1: &dyn Trait = unsafe { mem::transmute((&92u8, &3u8)) };
141-
| ------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
142-
| |
143-
| memory access failed: pointer must be in-bounds at offset N, but is outside bounds of allocN which has size N
137+
error[E0080]: it is undefined behavior to use this value
138+
--> $DIR/ub-wide-ptr.rs:104:1
144139
|
145-
note: the lint level is defined here
146-
--> $DIR/ub-wide-ptr.rs:98:8
140+
LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
141+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered too small vtable at .0
147142
|
148-
LL | #[warn(const_err)]
149-
| ^^^^^^^^^
143+
= 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.
150144

151-
warning: any use of this value will cause an error
152-
--> $DIR/ub-wide-ptr.rs:103:55
153-
|
154-
LL | const TRAIT_OBJ_SHORT_VTABLE_2: &dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
155-
| ------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
156-
| |
157-
| memory access failed: pointer must be in-bounds at offset N, but is outside bounds of allocN which has size N
145+
error[E0080]: it is undefined behavior to use this value
146+
--> $DIR/ub-wide-ptr.rs:107:1
158147
|
159-
note: the lint level is defined here
160-
--> $DIR/ub-wide-ptr.rs:102:8
148+
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
149+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered too small vtable at .0
161150
|
162-
LL | #[warn(const_err)]
163-
| ^^^^^^^^^
151+
= 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.
164152

165-
warning: any use of this value will cause an error
166-
--> $DIR/ub-wide-ptr.rs:107:51
167-
|
168-
LL | const TRAIT_OBJ_INT_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, 4usize)) };
169-
| --------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
170-
| |
171-
| unable to turn bytes into a pointer
153+
error[E0080]: it is undefined behavior to use this value
154+
--> $DIR/ub-wide-ptr.rs:110:1
172155
|
173-
note: the lint level is defined here
174-
--> $DIR/ub-wide-ptr.rs:106:8
156+
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
157+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling vtable pointer in wide pointer at .0
175158
|
176-
LL | #[warn(const_err)]
177-
| ^^^^^^^^^
159+
= 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.
178160

179161
error[E0080]: it is undefined behavior to use this value
180-
--> $DIR/ub-wide-ptr.rs:109:1
162+
--> $DIR/ub-wide-ptr.rs:112:1
181163
|
182164
LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
183165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered unaligned vtable pointer in wide pointer
184166
|
185167
= 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.
186168

187169
error[E0080]: it is undefined behavior to use this value
188-
--> $DIR/ub-wide-ptr.rs:111:1
170+
--> $DIR/ub-wide-ptr.rs:114:1
189171
|
190172
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
191173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
192174
|
193175
= 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.
194176

195177
error[E0080]: it is undefined behavior to use this value
196-
--> $DIR/ub-wide-ptr.rs:113:1
178+
--> $DIR/ub-wide-ptr.rs:116:1
197179
|
198180
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
199181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
200182
|
201183
= 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.
202184

203-
warning: any use of this value will cause an error
204-
--> $DIR/ub-wide-ptr.rs:116:63
205-
|
206-
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: &dyn Trait = unsafe { mem::transmute((&92u8, &[&42u8; 8])) };
207-
| --------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
208-
| |
209-
| "pointer-to-integer cast" needs an rfc before being allowed inside constants
185+
error[E0080]: it is undefined behavior to use this value
186+
--> $DIR/ub-wide-ptr.rs:118:1
210187
|
211-
note: the lint level is defined here
212-
--> $DIR/ub-wide-ptr.rs:115:8
188+
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
189+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function) at .0
213190
|
214-
LL | #[warn(const_err)]
215-
| ^^^^^^^^^
191+
= 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.
216192

217193
error[E0080]: it is undefined behavior to use this value
218-
--> $DIR/ub-wide-ptr.rs:120:1
194+
--> $DIR/ub-wide-ptr.rs:122:1
219195
|
220196
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
221197
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>.<dyn-downcast>, but expected a boolean
222198
|
223199
= 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.
224200

225201
error[E0080]: it is undefined behavior to use this value
226-
--> $DIR/ub-wide-ptr.rs:124:1
202+
--> $DIR/ub-wide-ptr.rs:126:1
227203
|
228204
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
229205
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling vtable pointer in wide pointer
230206
|
231207
= 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.
232208

233209
error[E0080]: it is undefined behavior to use this value
234-
--> $DIR/ub-wide-ptr.rs:126:1
210+
--> $DIR/ub-wide-ptr.rs:128:1
235211
|
236212
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
237213
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered too small vtable
238214
|
239215
= 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.
240216

241217
error[E0080]: could not evaluate static initializer
242-
--> $DIR/ub-wide-ptr.rs:132:5
218+
--> $DIR/ub-wide-ptr.rs:134:5
243219
|
244220
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
245221
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inbounds test failed: 0x0 is not a valid pointer
246222

247223
error[E0080]: could not evaluate static initializer
248-
--> $DIR/ub-wide-ptr.rs:136:5
224+
--> $DIR/ub-wide-ptr.rs:138:5
249225
|
250226
LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
251227
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset N, but is outside bounds of allocN which has size N
252228

253-
error: aborting due to 24 previous errors; 4 warnings emitted
229+
error: aborting due to 28 previous errors
254230

255231
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)
Please sign in to comment.