Skip to content

Commit 8aca71f

Browse files
committed
Ignore unsized types when trying to determine the size of a type
1 parent 502ce82 commit 8aca71f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

compiler/rustc_lint/src/reference_casting.rs

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
194194
return None;
195195
};
196196

197+
// if the type is not Sized we cannot know by definition it's size
198+
// so we bail out
199+
if !inner_start_ty.is_sized(cx.tcx, cx.param_env) {
200+
return None;
201+
}
202+
197203
// try to find the underlying allocation
198204
let e_alloc = cx.expr_or_init(e);
199205
let e_alloc =

tests/ui/lint/reference_casting.rs

+5
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ unsafe fn bigger_layout() {
239239
//~^ ERROR casting references to a bigger memory layout
240240
}
241241

242+
{
243+
let x: Box<dyn Send> = Box::new(0i32);
244+
let _z = unsafe { &*(&*x as *const dyn Send as *const i32) };
245+
}
246+
242247
unsafe fn from_ref(this: &i32) -> &i64 {
243248
&*(this as *const i32 as *const i64)
244249
}

0 commit comments

Comments
 (0)