Skip to content

Commit 8768a6a

Browse files
committed
Auto merge of rust-lang#125508 - scottmcm:fix-125506, r=Nilstrieb
Stop SRoA'ing `DynMetadata` in MIR Fixes rust-lang#125506
2 parents 5fe5543 + d7248d7 commit 8768a6a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

compiler/rustc_mir_transform/src/sroa.rs

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ fn escaping_locals<'tcx>(
7070
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
7171
return true;
7272
}
73+
if Some(def.did()) == tcx.lang_items().dyn_metadata() {
74+
// codegen wants to see the `DynMetadata<T>`,
75+
// not the inner reference-to-opaque-type.
76+
return true;
77+
}
7378
// We already excluded unions and enums, so this ADT must have one variant
7479
let variant = def.variant(FIRST_VARIANT);
7580
if variant.fields.len() > 1 {

tests/ui/mir/dyn_metadata_sroa.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ run-pass
2+
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir
3+
4+
#![feature(ptr_metadata)]
5+
6+
// Regression for <https://github.com/rust-lang/rust/issues/125506>,
7+
// which failed because of SRoA would project into `DynMetadata`.
8+
9+
trait Foo {}
10+
11+
struct Bar;
12+
13+
impl Foo for Bar {}
14+
15+
fn main() {
16+
let a: *mut dyn Foo = &mut Bar;
17+
18+
let _d = a.to_raw_parts().0 as usize;
19+
}

0 commit comments

Comments
 (0)