Fix #69191
This commit is contained in:
parent
c79f5f0647
commit
9712fa4059
@ -410,6 +410,12 @@ where
|
||||
stride * field
|
||||
}
|
||||
layout::FieldPlacement::Union(count) => {
|
||||
// This is a narrow bug-fix for rust-lang/rust#69191: if we are
|
||||
// trying to access absent field of uninhabited variant, then
|
||||
// signal UB (but don't ICE the compiler).
|
||||
if field >= count as u64 && base.layout.abi == layout::Abi::Uninhabited {
|
||||
throw_ub!(Unreachable);
|
||||
}
|
||||
assert!(
|
||||
field < count as u64,
|
||||
"Tried to access field {} of union {:#?} with {} fields",
|
||||
|
@ -0,0 +1,31 @@
|
||||
// build-pass
|
||||
//
|
||||
// (this is deliberately *not* check-pass; I have confirmed that the bug in
|
||||
// question does not replicate when one uses `cargo check` alone.)
|
||||
|
||||
pub enum Void {}
|
||||
|
||||
enum UninhabitedUnivariant { _Variant(Void), }
|
||||
|
||||
#[repr(C)]
|
||||
enum UninhabitedUnivariantC { _Variant(Void), }
|
||||
|
||||
#[repr(i32)]
|
||||
enum UninhabitedUnivariant32 { _Variant(Void), }
|
||||
|
||||
fn main() {
|
||||
let _seed: UninhabitedUnivariant = None.unwrap();
|
||||
match _seed {
|
||||
UninhabitedUnivariant::_Variant(_x) => {}
|
||||
}
|
||||
|
||||
let _seed: UninhabitedUnivariantC = None.unwrap();
|
||||
match _seed {
|
||||
UninhabitedUnivariantC::_Variant(_x) => {}
|
||||
}
|
||||
|
||||
let _seed: UninhabitedUnivariant32 = None.unwrap();
|
||||
match _seed {
|
||||
UninhabitedUnivariant32::_Variant(_x) => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user