Improve invalid_reference_casting
lint
This commit is contained in:
parent
6933848fbf
commit
91b05f8e09
3 changed files with 133 additions and 35 deletions
|
@ -100,7 +100,7 @@ fn is_cast_from_const_to_mut<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>)
|
||||||
|
|
||||||
fn from_casts<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
fn from_casts<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||||
// <expr> as *mut ...
|
// <expr> as *mut ...
|
||||||
let e = if let ExprKind::Cast(e, t) = e.kind
|
let mut e = if let ExprKind::Cast(e, t) = e.kind
|
||||||
&& let ty::RawPtr(TypeAndMut { mutbl: Mutability::Mut, .. }) = cx.typeck_results().node_type(t.hir_id).kind() {
|
&& let ty::RawPtr(TypeAndMut { mutbl: Mutability::Mut, .. }) = cx.typeck_results().node_type(t.hir_id).kind() {
|
||||||
e
|
e
|
||||||
// <expr>.cast_mut()
|
// <expr>.cast_mut()
|
||||||
|
@ -112,23 +112,36 @@ fn is_cast_from_const_to_mut<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>)
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
let e = e.peel_blocks();
|
let mut had_at_least_one_cast = false;
|
||||||
|
loop {
|
||||||
// <expr> as *const ...
|
e = e.peel_blocks();
|
||||||
let e = if let ExprKind::Cast(e, t) = e.kind
|
// <expr> as *mut/const ... or <expr> as <uint>
|
||||||
&& let ty::RawPtr(TypeAndMut { mutbl: Mutability::Not, .. }) = cx.typeck_results().node_type(t.hir_id).kind() {
|
e = if let ExprKind::Cast(expr, t) = e.kind
|
||||||
e
|
&& matches!(cx.typeck_results().node_type(t.hir_id).kind(), ty::RawPtr(_) | ty::Uint(_)) {
|
||||||
// ptr::from_ref(<expr>)
|
had_at_least_one_cast = true;
|
||||||
} else if let ExprKind::Call(path, [arg]) = e.kind
|
expr
|
||||||
&& let ExprKind::Path(ref qpath) = path.kind
|
// <expr>.cast(), <expr>.cast_mut() or <expr>.cast_const()
|
||||||
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
|
} else if let ExprKind::MethodCall(_, expr, [], _) = e.kind
|
||||||
&& cx.tcx.is_diagnostic_item(sym::ptr_from_ref, def_id) {
|
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id)
|
||||||
arg
|
&& matches!(
|
||||||
} else {
|
cx.tcx.get_diagnostic_name(def_id),
|
||||||
return None;
|
Some(sym::ptr_cast | sym::const_ptr_cast | sym::ptr_cast_mut | sym::ptr_cast_const)
|
||||||
};
|
)
|
||||||
|
{
|
||||||
Some(e)
|
had_at_least_one_cast = true;
|
||||||
|
expr
|
||||||
|
// ptr::from_ref(<expr>)
|
||||||
|
} else if let ExprKind::Call(path, [arg]) = e.kind
|
||||||
|
&& let ExprKind::Path(ref qpath) = path.kind
|
||||||
|
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
|
||||||
|
&& cx.tcx.is_diagnostic_item(sym::ptr_from_ref, def_id) {
|
||||||
|
return Some(arg);
|
||||||
|
} else if had_at_least_one_cast {
|
||||||
|
return Some(e);
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_transmute<'tcx>(
|
fn from_transmute<'tcx>(
|
||||||
|
|
|
@ -9,6 +9,10 @@ extern "C" {
|
||||||
fn int_ffi(c: *mut i32);
|
fn int_ffi(c: *mut i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn static_u8() -> &'static u8 {
|
||||||
|
&8
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn ref_to_mut() {
|
unsafe fn ref_to_mut() {
|
||||||
let num = &3i32;
|
let num = &3i32;
|
||||||
|
|
||||||
|
@ -24,12 +28,28 @@ unsafe fn ref_to_mut() {
|
||||||
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
|
let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
|
||||||
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
|
||||||
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
|
||||||
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
|
||||||
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
|
let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
|
||||||
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
|
||||||
let deferred = num as *const i32 as *mut i32;
|
let deferred = num as *const i32 as *mut i32;
|
||||||
let _num = &mut *deferred;
|
let _num = &mut *deferred;
|
||||||
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
|
||||||
|
let _num = &mut *deferred;
|
||||||
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
let _num = &mut *(num as *const _ as usize as *mut i32);
|
||||||
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
|
||||||
|
unsafe fn generic_ref_cast_mut<T>(this: &T) -> &mut T {
|
||||||
|
&mut *((this as *const _) as *mut _)
|
||||||
|
//~^ ERROR casting `&T` to `&mut T` is undefined behavior
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn assign_to_ref() {
|
unsafe fn assign_to_ref() {
|
||||||
|
@ -55,6 +75,15 @@ unsafe fn assign_to_ref() {
|
||||||
let value = num as *const i32 as *mut i32;
|
let value = num as *const i32 as *mut i32;
|
||||||
*value = 1;
|
*value = 1;
|
||||||
//~^ ERROR assigning to `&T` is undefined behavior
|
//~^ ERROR assigning to `&T` is undefined behavior
|
||||||
|
*(num as *const i32).cast::<i32>().cast_mut() = 2;
|
||||||
|
//~^ ERROR assigning to `&T` is undefined behavior
|
||||||
|
*(num as *const _ as usize as *mut i32) = 2;
|
||||||
|
//~^ ERROR assigning to `&T` is undefined behavior
|
||||||
|
|
||||||
|
unsafe fn generic_assign_to_ref<T>(this: &T, a: T) {
|
||||||
|
*(this as *const _ as *mut _) = a;
|
||||||
|
//~^ ERROR assigning to `&T` is undefined behavior
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn no_warn() {
|
unsafe fn no_warn() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:15:16
|
--> $DIR/reference_casting.rs:19:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *(num as *const i32 as *mut i32);
|
LL | let _num = &mut *(num as *const i32 as *mut i32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -7,98 +7,154 @@ LL | let _num = &mut *(num as *const i32 as *mut i32);
|
||||||
= note: `#[deny(invalid_reference_casting)]` on by default
|
= note: `#[deny(invalid_reference_casting)]` on by default
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:17:16
|
--> $DIR/reference_casting.rs:21:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *(num as *const i32).cast_mut();
|
LL | let _num = &mut *(num as *const i32).cast_mut();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:19:16
|
--> $DIR/reference_casting.rs:23:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
|
LL | let _num = &mut *std::ptr::from_ref(num).cast_mut();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:21:16
|
--> $DIR/reference_casting.rs:25:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
|
LL | let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:23:16
|
--> $DIR/reference_casting.rs:27:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
|
LL | let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:25:16
|
--> $DIR/reference_casting.rs:29:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
|
LL | let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:27:16
|
--> $DIR/reference_casting.rs:31:16
|
||||||
|
|
|
||||||
|
LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:33:16
|
||||||
|
|
|
||||||
|
LL | let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:35:16
|
||||||
|
|
|
||||||
|
LL | let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:37:16
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
|
LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:31:16
|
--> $DIR/reference_casting.rs:41:16
|
||||||
|
|
|
|
||||||
LL | let deferred = num as *const i32 as *mut i32;
|
LL | let deferred = num as *const i32 as *mut i32;
|
||||||
| ----------------------------- casting happend here
|
| ----------------------------- casting happend here
|
||||||
LL | let _num = &mut *deferred;
|
LL | let _num = &mut *deferred;
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:44:16
|
||||||
|
|
|
||||||
|
LL | let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
|
||||||
|
| ---------------------------------------------------------------------------- casting happend here
|
||||||
|
LL | let _num = &mut *deferred;
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:46:16
|
||||||
|
|
|
||||||
|
LL | let _num = &mut *(num as *const _ as usize as *mut i32);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:50:9
|
||||||
|
|
|
||||||
|
LL | &mut *((this as *const _) as *mut _)
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:40:5
|
--> $DIR/reference_casting.rs:60:5
|
||||||
|
|
|
|
||||||
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:42:5
|
--> $DIR/reference_casting.rs:62:5
|
||||||
|
|
|
|
||||||
LL | *(a as *const _ as *mut String) += " world";
|
LL | *(a as *const _ as *mut String) += " world";
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:44:5
|
--> $DIR/reference_casting.rs:64:5
|
||||||
|
|
|
|
||||||
LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:46:5
|
--> $DIR/reference_casting.rs:66:5
|
||||||
|
|
|
|
||||||
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:48:5
|
--> $DIR/reference_casting.rs:68:5
|
||||||
|
|
|
|
||||||
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:50:5
|
--> $DIR/reference_casting.rs:70:5
|
||||||
|
|
|
|
||||||
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:52:5
|
--> $DIR/reference_casting.rs:72:5
|
||||||
|
|
|
|
||||||
LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
|
LL | *std::mem::transmute::<_, *mut i32>(num) += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
--> $DIR/reference_casting.rs:56:5
|
--> $DIR/reference_casting.rs:76:5
|
||||||
|
|
|
|
||||||
LL | let value = num as *const i32 as *mut i32;
|
LL | let value = num as *const i32 as *mut i32;
|
||||||
| ----------------------------- casting happend here
|
| ----------------------------- casting happend here
|
||||||
LL | *value = 1;
|
LL | *value = 1;
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 16 previous errors
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:78:5
|
||||||
|
|
|
||||||
|
LL | *(num as *const i32).cast::<i32>().cast_mut() = 2;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:80:5
|
||||||
|
|
|
||||||
|
LL | *(num as *const _ as usize as *mut i32) = 2;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
|
||||||
|
--> $DIR/reference_casting.rs:84:9
|
||||||
|
|
|
||||||
|
LL | *(this as *const _ as *mut _) = a;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 25 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue