Skip to content

Commit 545fcca

Browse files
committed
Add a test for scalar pair layout validation
1 parent ccaa28b commit 545fcca

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
6565
14 00 00 00 │ ....
6666
}
6767

68-
error: aborting due to 7 previous errors
68+
error[E0080]: it is undefined behavior to use this value
69+
--> $DIR/ub-nonnull.rs:50:1
70+
|
71+
LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
73+
|
74+
= 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.
75+
= note: the raw bytes of the constant (size: 8, align: 4) {
76+
00 00 00 00 ╾─alloc26─╼ │ ....╾──╼
77+
}
78+
79+
error: aborting due to 8 previous errors
6980

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

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
6565
14 00 00 00 │ ....
6666
}
6767

68-
error: aborting due to 7 previous errors
68+
error[E0080]: it is undefined behavior to use this value
69+
--> $DIR/ub-nonnull.rs:50:1
70+
|
71+
LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
73+
|
74+
= 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.
75+
= note: the raw bytes of the constant (size: 16, align: 8) {
76+
00 00 00 00 00 00 00 00 ╾───────alloc26───────╼ │ ........╾──────╼
77+
}
78+
79+
error: aborting due to 8 previous errors
6980

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

src/test/ui/consts/const-eval/ub-nonnull.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// stderr-per-bitwidth
2-
#![feature(rustc_attrs)]
2+
#![feature(rustc_attrs, ptr_metadata)]
33
#![allow(invalid_value)] // make sure we cannot allow away the errors tested here
44

55
use std::mem;
@@ -47,4 +47,11 @@ struct RestrictedRange2(u32);
4747
const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
4848
//~^ ERROR it is undefined behavior to use this value
4949

50+
const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
51+
//~^ ERROR it is undefined behavior to use this value
52+
let x: &dyn Send = &42;
53+
let meta = std::ptr::metadata(x);
54+
mem::transmute((0_usize, meta))
55+
};
56+
5057
fn main() {}

0 commit comments

Comments
 (0)