mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Handle field projections like slice indexing in invalid_reference_casting
This commit is contained in:
parent
c3202afa28
commit
0ca1a94b2b
@ -202,7 +202,8 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
|
|||||||
|
|
||||||
// if the current expr looks like this `&mut expr[index]` then just looking
|
// if the current expr looks like this `&mut expr[index]` then just looking
|
||||||
// at `expr[index]` won't give us the underlying allocation, so we just skip it
|
// at `expr[index]` won't give us the underlying allocation, so we just skip it
|
||||||
if let ExprKind::Index(..) = e_alloc.kind {
|
// the same logic applies field access like `&mut expr.field`
|
||||||
|
if let ExprKind::Index(..) | ExprKind::Field(..) = e_alloc.kind {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +255,12 @@ unsafe fn bigger_layout() {
|
|||||||
let a3 = a2 as *mut u64;
|
let a3 = a2 as *mut u64;
|
||||||
unsafe { *a3 = 3 };
|
unsafe { *a3 = 3 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe fn field_access(v: &mut Vec3<i32>) {
|
||||||
|
let r = &mut v.0;
|
||||||
|
let ptr = r as *mut i32 as *mut Vec3<i32>;
|
||||||
|
unsafe { *ptr = Vec3(0, 0, 0) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const RAW_PTR: *mut u8 = 1 as *mut u8;
|
const RAW_PTR: *mut u8 = 1 as *mut u8;
|
||||||
|
Loading…
Reference in New Issue
Block a user