Fix ICE when transmute Assume field is invalid

This commit is contained in:
delta17920 2026-01-05 16:20:36 +00:00
parent 9e8a0c5164
commit e603055d89
3 changed files with 70 additions and 5 deletions

View file

@ -155,14 +155,14 @@ mod rustc {
.enumerate()
.find(|(_, field_def)| name == field_def.name)
.unwrap_or_else(|| panic!("There were no fields named `{name}`."));
fields[field_idx].to_leaf() == ScalarInt::TRUE
fields[field_idx].try_to_leaf().map(|leaf| leaf == ScalarInt::TRUE)
};
Some(Self {
alignment: get_field(sym::alignment),
lifetimes: get_field(sym::lifetimes),
safety: get_field(sym::safety),
validity: get_field(sym::validity),
alignment: get_field(sym::alignment)?,
lifetimes: get_field(sym::lifetimes)?,
safety: get_field(sym::safety)?,
validity: get_field(sym::validity)?,
})
}
}

View file

@ -0,0 +1,30 @@
#![feature(min_generic_const_args)]
//~^ WARN the feature `min_generic_const_args` is incomplete
#![feature(transmutability)]
mod assert {
use std::mem::{Assume, TransmuteFrom};
struct Dst {}
fn is_maybe_transmutable()
where
Dst: TransmuteFrom<
(),
{
Assume {
alignment: Assume {},
//~^ ERROR struct expression with missing field initialiser for `alignment`
//~| ERROR struct expression with missing field initialiser for `lifetimes`
//~| ERROR struct expression with missing field initialiser for `safety`
//~| ERROR struct expression with missing field initialiser for `validity`
lifetimes: const { true },
safety: const { true },
validity: const { true },
}
},
>,
{
}
}
fn main() {}

View file

@ -0,0 +1,35 @@
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/non_scalar_alignment_value.rs:1:12
|
LL | #![feature(min_generic_const_args)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
= note: `#[warn(incomplete_features)]` on by default
error: struct expression with missing field initialiser for `alignment`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^
error: struct expression with missing field initialiser for `lifetimes`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^
error: struct expression with missing field initialiser for `safety`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^
error: struct expression with missing field initialiser for `validity`
--> $DIR/non_scalar_alignment_value.rs:15:32
|
LL | alignment: Assume {},
| ^^^^^^
error: aborting due to 4 previous errors; 1 warning emitted