Skip to content

Commit 686119a

Browse files
authored
Unrolled build for #150707
Rollup merge of #150707 - Delta17920:fix-transmute-valtree-ice, r=BoxyUwU Fix ICE when transmute Assume field is invalid This PR fixes an internal compiler error in `rustc_transmute` where initializing an `Assume` field (like `alignment`) with a non-scalar constant (like a struct) caused a panic. The fix updates `from_const` to use `try_to_scalar()` instead of assuming the value is always a leaf. It now gracefully returns `None` for invalid types, allowing the compiler to report standard "missing field initialiser" errors instead of crashing. Fixes #150506
2 parents 74fd751 + e603055 commit 686119a

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

‎compiler/rustc_transmute/src/lib.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ mod rustc {
155155
.enumerate()
156156
.find(|(_, field_def)| name == field_def.name)
157157
.unwrap_or_else(|| panic!("There were no fields named `{name}`."));
158-
fields[field_idx].to_leaf() == ScalarInt::TRUE
158+
fields[field_idx].try_to_leaf().map(|leaf| leaf == ScalarInt::TRUE)
159159
};
160160

161161
Some(Self {
162-
alignment: get_field(sym::alignment),
163-
lifetimes: get_field(sym::lifetimes),
164-
safety: get_field(sym::safety),
165-
validity: get_field(sym::validity),
162+
alignment: get_field(sym::alignment)?,
163+
lifetimes: get_field(sym::lifetimes)?,
164+
safety: get_field(sym::safety)?,
165+
validity: get_field(sym::validity)?,
166166
})
167167
}
168168
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(min_generic_const_args)]
2+
//~^ WARN the feature `min_generic_const_args` is incomplete
3+
4+
#![feature(transmutability)]
5+
6+
mod assert {
7+
use std::mem::{Assume, TransmuteFrom};
8+
struct Dst {}
9+
fn is_maybe_transmutable()
10+
where
11+
Dst: TransmuteFrom<
12+
(),
13+
{
14+
Assume {
15+
alignment: Assume {},
16+
//~^ ERROR struct expression with missing field initialiser for `alignment`
17+
//~| ERROR struct expression with missing field initialiser for `lifetimes`
18+
//~| ERROR struct expression with missing field initialiser for `safety`
19+
//~| ERROR struct expression with missing field initialiser for `validity`
20+
lifetimes: const { true },
21+
safety: const { true },
22+
validity: const { true },
23+
}
24+
},
25+
>,
26+
{
27+
}
28+
}
29+
30+
fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/non_scalar_alignment_value.rs:1:12
3+
|
4+
LL | #![feature(min_generic_const_args)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: struct expression with missing field initialiser for `alignment`
11+
--> $DIR/non_scalar_alignment_value.rs:15:32
12+
|
13+
LL | alignment: Assume {},
14+
| ^^^^^^
15+
16+
error: struct expression with missing field initialiser for `lifetimes`
17+
--> $DIR/non_scalar_alignment_value.rs:15:32
18+
|
19+
LL | alignment: Assume {},
20+
| ^^^^^^
21+
22+
error: struct expression with missing field initialiser for `safety`
23+
--> $DIR/non_scalar_alignment_value.rs:15:32
24+
|
25+
LL | alignment: Assume {},
26+
| ^^^^^^
27+
28+
error: struct expression with missing field initialiser for `validity`
29+
--> $DIR/non_scalar_alignment_value.rs:15:32
30+
|
31+
LL | alignment: Assume {},
32+
| ^^^^^^
33+
34+
error: aborting due to 4 previous errors; 1 warning emitted
35+

0 commit comments

Comments
 (0)