Skip to content

Commit b4c377e

Browse files
committed
bless some tests
1 parent adf6d37 commit b4c377e

File tree

3 files changed

+39
-52
lines changed

3 files changed

+39
-52
lines changed

src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((
217217
}
218218

219219
error[E0080]: it is undefined behavior to use this value
220-
--> $DIR/ub-wide-ptr.rs:120:1
220+
--> $DIR/ub-wide-ptr.rs:121:1
221221
|
222222
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
223223
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -228,7 +228,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((
228228
}
229229

230230
error[E0080]: it is undefined behavior to use this value
231-
--> $DIR/ub-wide-ptr.rs:123:1
231+
--> $DIR/ub-wide-ptr.rs:125:1
232232
|
233233
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
234234
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
@@ -239,25 +239,25 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u
239239
}
240240

241241
error[E0080]: evaluation of constant value failed
242-
--> $DIR/ub-wide-ptr.rs:125:57
242+
--> $DIR/ub-wide-ptr.rs:128:57
243243
|
244244
LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
245245
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
246246

247247
error[E0080]: evaluation of constant value failed
248-
--> $DIR/ub-wide-ptr.rs:128:57
248+
--> $DIR/ub-wide-ptr.rs:131:57
249249
|
250250
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
251251
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
252252

253253
error[E0080]: evaluation of constant value failed
254-
--> $DIR/ub-wide-ptr.rs:131:56
254+
--> $DIR/ub-wide-ptr.rs:134:56
255255
|
256256
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
257257
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
258258

259259
error[E0080]: it is undefined behavior to use this value
260-
--> $DIR/ub-wide-ptr.rs:134:1
260+
--> $DIR/ub-wide-ptr.rs:137:1
261261
|
262262
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
263263
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -268,7 +268,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans
268268
}
269269

270270
error[E0080]: it is undefined behavior to use this value
271-
--> $DIR/ub-wide-ptr.rs:138:1
271+
--> $DIR/ub-wide-ptr.rs:142:1
272272
|
273273
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
274274
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
@@ -278,36 +278,26 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_,
278278
╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼
279279
}
280280

281-
error[E0080]: it is undefined behavior to use this value
282-
--> $DIR/ub-wide-ptr.rs:142:1
281+
error[E0080]: evaluation of constant value failed
282+
--> $DIR/ub-wide-ptr.rs:147:62
283283
|
284284
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
285-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
286-
|
287-
= 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.
288-
= note: the raw bytes of the constant (size: 8, align: 4) {
289-
╾allocN─╼ 00 00 00 00 │ ╾──╼....
290-
}
285+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
291286

292-
error[E0080]: it is undefined behavior to use this value
293-
--> $DIR/ub-wide-ptr.rs:144:1
287+
error[E0080]: evaluation of constant value failed
288+
--> $DIR/ub-wide-ptr.rs:150:65
294289
|
295290
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
296-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer
297-
|
298-
= 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.
299-
= note: the raw bytes of the constant (size: 8, align: 4) {
300-
╾allocN─╼ ╾allocN─╼ │ ╾──╼╾──╼
301-
}
291+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
302292

303293
error[E0080]: could not evaluate static initializer
304-
--> $DIR/ub-wide-ptr.rs:150:5
294+
--> $DIR/ub-wide-ptr.rs:157:5
305295
|
306296
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
307297
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
308298

309299
error[E0080]: could not evaluate static initializer
310-
--> $DIR/ub-wide-ptr.rs:154:5
300+
--> $DIR/ub-wide-ptr.rs:161:5
311301
|
312302
LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
313303
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable

src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((
217217
}
218218

219219
error[E0080]: it is undefined behavior to use this value
220-
--> $DIR/ub-wide-ptr.rs:120:1
220+
--> $DIR/ub-wide-ptr.rs:121:1
221221
|
222222
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
223223
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -228,7 +228,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((
228228
}
229229

230230
error[E0080]: it is undefined behavior to use this value
231-
--> $DIR/ub-wide-ptr.rs:123:1
231+
--> $DIR/ub-wide-ptr.rs:125:1
232232
|
233233
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
234234
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
@@ -239,25 +239,25 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u
239239
}
240240

241241
error[E0080]: evaluation of constant value failed
242-
--> $DIR/ub-wide-ptr.rs:125:57
242+
--> $DIR/ub-wide-ptr.rs:128:57
243243
|
244244
LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
245245
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
246246

247247
error[E0080]: evaluation of constant value failed
248-
--> $DIR/ub-wide-ptr.rs:128:57
248+
--> $DIR/ub-wide-ptr.rs:131:57
249249
|
250250
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
251251
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
252252

253253
error[E0080]: evaluation of constant value failed
254-
--> $DIR/ub-wide-ptr.rs:131:56
254+
--> $DIR/ub-wide-ptr.rs:134:56
255255
|
256256
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
257257
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
258258

259259
error[E0080]: it is undefined behavior to use this value
260-
--> $DIR/ub-wide-ptr.rs:134:1
260+
--> $DIR/ub-wide-ptr.rs:137:1
261261
|
262262
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
263263
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -268,7 +268,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans
268268
}
269269

270270
error[E0080]: it is undefined behavior to use this value
271-
--> $DIR/ub-wide-ptr.rs:138:1
271+
--> $DIR/ub-wide-ptr.rs:142:1
272272
|
273273
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
274274
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
@@ -278,36 +278,26 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_,
278278
╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
279279
}
280280

281-
error[E0080]: it is undefined behavior to use this value
282-
--> $DIR/ub-wide-ptr.rs:142:1
281+
error[E0080]: evaluation of constant value failed
282+
--> $DIR/ub-wide-ptr.rs:147:62
283283
|
284284
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
285-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
286-
|
287-
= 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.
288-
= note: the raw bytes of the constant (size: 16, align: 8) {
289-
╾──────allocN───────╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........
290-
}
285+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
291286

292-
error[E0080]: it is undefined behavior to use this value
293-
--> $DIR/ub-wide-ptr.rs:144:1
287+
error[E0080]: evaluation of constant value failed
288+
--> $DIR/ub-wide-ptr.rs:150:65
294289
|
295290
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
296-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer
297-
|
298-
= 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.
299-
= note: the raw bytes of the constant (size: 16, align: 8) {
300-
╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
301-
}
291+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
302292

303293
error[E0080]: could not evaluate static initializer
304-
--> $DIR/ub-wide-ptr.rs:150:5
294+
--> $DIR/ub-wide-ptr.rs:157:5
305295
|
306296
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
307297
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
308298

309299
error[E0080]: could not evaluate static initializer
310-
--> $DIR/ub-wide-ptr.rs:154:5
300+
--> $DIR/ub-wide-ptr.rs:161:5
311301
|
312302
LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
313303
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
116116
// bad trait object
117117
const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
118118
//~^ ERROR it is undefined behavior to use this value
119+
//~| expected a vtable
119120
// bad trait object
120121
const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
121122
//~^ ERROR it is undefined behavior to use this value
123+
//~| expected a vtable
122124
// bad trait object
123125
const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
124126
//~^ ERROR it is undefined behavior to use this value
127+
//~| expected a vtable
125128
const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
126129
//~^ ERROR evaluation of constant value failed
127130
//~| does not point to a vtable
@@ -133,16 +136,20 @@ const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[
133136
//~| does not point to a vtable
134137
const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
135138
//~^ ERROR it is undefined behavior to use this value
139+
//~| expected a vtable
136140

137141
// bad data *inside* the trait object
138142
const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
139143
//~^ ERROR it is undefined behavior to use this value
144+
//~| expected a boolean
140145

141146
// # raw trait object
142147
const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
143-
//~^ ERROR it is undefined behavior to use this value
148+
//~^ ERROR evaluation of constant value failed
149+
//~| null pointer
144150
const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
145-
//~^ ERROR it is undefined behavior to use this value
151+
//~^ ERROR evaluation of constant value failed
152+
//~| does not point to a vtable
146153
const RAW_TRAIT_OBJ_CONTENT_INVALID: *const dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) } as *const dyn Trait; // ok because raw
147154

148155
// Const eval fails for these, so they need to be statics to error.

0 commit comments

Comments
 (0)