Rollup merge of #121104 - Urgau:bigger_layout-fix-fp, r=compiler-errors

Ignore unsized types when trying to determine the size of the original type

Fixes https://github.com/rust-lang/rust/issues/121074 a regression from https://github.com/rust-lang/rust/pull/118983
This commit is contained in:
Guillaume Gomez 2024-02-15 14:33:01 +01:00 committed by GitHub
commit 12d70af446
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -207,6 +207,13 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
}
let from_layout = cx.layout_of(*inner_start_ty).ok()?;
// if the type isn't sized, we bail out, instead of potentially giving
// the user a meaningless warning.
if from_layout.is_unsized() {
return None;
}
let alloc_layout = cx.layout_of(alloc_ty).ok()?;
let to_layout = cx.layout_of(*inner_end_ty).ok()?;

View file

@ -239,6 +239,11 @@ unsafe fn bigger_layout() {
//~^ ERROR casting references to a bigger memory layout
}
{
let x: Box<dyn Send> = Box::new(0i32);
let _z = unsafe { &*(&*x as *const dyn Send as *const i32) };
}
unsafe fn from_ref(this: &i32) -> &i64 {
&*(this as *const i32 as *const i64)
}