Auto merge of #54693 - RalfJung:ctfe-scalar-pair-undef, r=oli-obk
do not normalize all non-scalar constants to a ConstValue::ScalarPair We still need `ConstValue::ScalarPair` for match handling (matching slices and strings), but that will never see anything `Undef`. For non-fat-ptr `ScalarPair`, just point to the allocation like larger data structures do. Fixes https://github.com/rust-lang/rust/issues/54387 r? @eddyb
This commit is contained in:
commit
7cbcdae818
19 changed files with 166 additions and 150 deletions
|
|
@ -22,7 +22,7 @@ const UNION: DummyUnion = DummyUnion { field1: 1065353216 };
|
|||
|
||||
const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant cannot be used
|
||||
|
||||
const FIELD_PATH: Struct = Struct { //~ ERROR this constant cannot be used
|
||||
const FIELD_PATH: Struct = Struct { //~ ERROR this constant likely exhibits undefined behavior
|
||||
a: 42,
|
||||
b: unsafe { UNION.field3 },
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,14 +6,16 @@ LL | const FIELD3: Field3 = unsafe { UNION.field3 }; //~ ERROR this constant can
|
|||
|
|
||||
= note: #[deny(const_err)] on by default
|
||||
|
||||
error: this constant cannot be used
|
||||
error[E0080]: this constant likely exhibits undefined behavior
|
||||
--> $DIR/union-ice.rs:25:1
|
||||
|
|
||||
LL | / const FIELD_PATH: Struct = Struct { //~ ERROR this constant cannot be used
|
||||
LL | / const FIELD_PATH: Struct = Struct { //~ ERROR this constant likely exhibits undefined behavior
|
||||
LL | | a: 42,
|
||||
LL | | b: unsafe { UNION.field3 },
|
||||
LL | | };
|
||||
| |__^ attempted to read undefined bytes
|
||||
| |__^ type validation failed: encountered undefined bytes at .b
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||
|
||||
error[E0080]: this constant likely exhibits undefined behavior
|
||||
--> $DIR/union-ice.rs:35:1
|
||||
|
|
|
|||
12
src/test/ui/issues/issue-54387.rs
Normal file
12
src/test/ui/issues/issue-54387.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// compile-pass
|
||||
|
||||
pub struct GstRc {
|
||||
_obj: *const (),
|
||||
_borrowed: bool,
|
||||
}
|
||||
|
||||
const FOO: Option<GstRc> = None;
|
||||
|
||||
fn main() {
|
||||
let _meh = FOO;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue