Skip to content

Commit

Permalink
Unrolled build for rust-lang#121104
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#121104 - Urgau:bigger_layout-fix-fp, r=compiler-errors

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

Fixes rust-lang#121074 a regression from rust-lang#118983
  • Loading branch information
rust-timer authored Feb 15, 2024
2 parents 62fb0db + ddec8c5 commit 4d3276c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_lint/src/reference_casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/lint/reference_casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4d3276c

Please sign in to comment.