Skip to content

Commit 0ea0c90

Browse files
committed
fix UB in ancient test
1 parent adb4bfd commit 0ea0c90

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tests/ui/regions/regions-mock-codegen.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ struct Ccx {
2222
x: isize,
2323
}
2424

25-
fn allocate(_bcx: &arena) -> &Bcx<'_> {
25+
fn allocate(_bcx: &arena) -> &mut Bcx<'_> {
2626
unsafe {
2727
let layout = Layout::new::<Bcx>();
2828
let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout));
29-
&*(ptr.as_ptr() as *const _)
29+
&mut *ptr.as_ptr().cast()
3030
}
3131
}
3232

33-
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
33+
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a mut Bcx<'a> {
3434
return allocate(bcx.fcx.arena);
3535
}
3636

3737
fn g(fcx: &Fcx) {
3838
let bcx = Bcx { fcx };
3939
let bcx2 = h(&bcx);
4040
unsafe {
41-
Global.deallocate(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
41+
Global.deallocate(NonNull::new_unchecked(bcx2 as *mut _ as *mut _), Layout::new::<Bcx>());
4242
}
4343
}
4444

0 commit comments

Comments
 (0)