Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstrieb
Rename and allow `cast_ref_to_mut` lint This PR is a small subset of https://github.com/rust-lang/rust/pull/112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`). BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until https://github.com/rust-lang/rust/pull/112431 is merged. r? `@Nilstrieb`
This commit is contained in:
commit
04411507be
14 changed files with 42 additions and 45 deletions
|
@ -155,8 +155,6 @@ lint_builtin_unused_doc_comment = unused doc comment
|
||||||
lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
|
lint_builtin_while_true = denote infinite loops with `loop {"{"} ... {"}"}`
|
||||||
.suggestion = use `loop`
|
.suggestion = use `loop`
|
||||||
|
|
||||||
lint_cast_ref_to_mut = casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
|
||||||
|
|
||||||
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
|
lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not have an effect anymore. Use: {$new_name}
|
||||||
|
|
||||||
lint_check_name_unknown = unknown lint: `{$lint_name}`
|
lint_check_name_unknown = unknown lint: `{$lint_name}`
|
||||||
|
@ -320,6 +318,8 @@ lint_invalid_nan_comparisons_eq_ne = incorrect NaN comparison, NaN cannot be dir
|
||||||
|
|
||||||
lint_invalid_nan_comparisons_lt_le_gt_ge = incorrect NaN comparison, NaN is not orderable
|
lint_invalid_nan_comparisons_lt_le_gt_ge = incorrect NaN comparison, NaN is not orderable
|
||||||
|
|
||||||
|
lint_invalid_reference_casting = casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||||
|
|
||||||
lint_lintpass_by_hand = implementing `LintPass` by hand
|
lint_lintpass_by_hand = implementing `LintPass` by hand
|
||||||
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
|
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ extern crate tracing;
|
||||||
|
|
||||||
mod array_into_iter;
|
mod array_into_iter;
|
||||||
pub mod builtin;
|
pub mod builtin;
|
||||||
mod cast_ref_to_mut;
|
|
||||||
mod context;
|
mod context;
|
||||||
mod deref_into_dyn_supertrait;
|
mod deref_into_dyn_supertrait;
|
||||||
mod drop_forget_useless;
|
mod drop_forget_useless;
|
||||||
|
@ -78,6 +77,7 @@ mod opaque_hidden_inferred_bound;
|
||||||
mod pass_by_value;
|
mod pass_by_value;
|
||||||
mod passes;
|
mod passes;
|
||||||
mod redundant_semicolon;
|
mod redundant_semicolon;
|
||||||
|
mod reference_casting;
|
||||||
mod traits;
|
mod traits;
|
||||||
mod types;
|
mod types;
|
||||||
mod unused;
|
mod unused;
|
||||||
|
@ -99,7 +99,6 @@ use rustc_span::Span;
|
||||||
|
|
||||||
use array_into_iter::ArrayIntoIter;
|
use array_into_iter::ArrayIntoIter;
|
||||||
use builtin::*;
|
use builtin::*;
|
||||||
use cast_ref_to_mut::*;
|
|
||||||
use deref_into_dyn_supertrait::*;
|
use deref_into_dyn_supertrait::*;
|
||||||
use drop_forget_useless::*;
|
use drop_forget_useless::*;
|
||||||
use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums;
|
use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums;
|
||||||
|
@ -119,6 +118,7 @@ use noop_method_call::*;
|
||||||
use opaque_hidden_inferred_bound::*;
|
use opaque_hidden_inferred_bound::*;
|
||||||
use pass_by_value::*;
|
use pass_by_value::*;
|
||||||
use redundant_semicolon::*;
|
use redundant_semicolon::*;
|
||||||
|
use reference_casting::*;
|
||||||
use traits::*;
|
use traits::*;
|
||||||
use types::*;
|
use types::*;
|
||||||
use unused::*;
|
use unused::*;
|
||||||
|
@ -218,7 +218,7 @@ late_lint_methods!(
|
||||||
BoxPointers: BoxPointers,
|
BoxPointers: BoxPointers,
|
||||||
PathStatements: PathStatements,
|
PathStatements: PathStatements,
|
||||||
LetUnderscore: LetUnderscore,
|
LetUnderscore: LetUnderscore,
|
||||||
CastRefToMut: CastRefToMut,
|
InvalidReferenceCasting: InvalidReferenceCasting,
|
||||||
// Depends on referenced function signatures in expressions
|
// Depends on referenced function signatures in expressions
|
||||||
UnusedResults: UnusedResults,
|
UnusedResults: UnusedResults,
|
||||||
NonUpperCaseGlobals: NonUpperCaseGlobals,
|
NonUpperCaseGlobals: NonUpperCaseGlobals,
|
||||||
|
|
|
@ -743,10 +743,10 @@ pub enum InvalidFromUtf8Diag {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// cast_ref_to_mut.rs
|
// reference_casting.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(lint_cast_ref_to_mut)]
|
#[diag(lint_invalid_reference_casting)]
|
||||||
pub struct CastRefToMutDiag;
|
pub struct InvalidReferenceCastingDiag;
|
||||||
|
|
||||||
// hidden_unicode_codepoints.rs
|
// hidden_unicode_codepoints.rs
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
|
|
|
@ -3,15 +3,16 @@ use rustc_hir::{Expr, ExprKind, MutTy, TyKind, UnOp};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
use crate::{lints::CastRefToMutDiag, LateContext, LateLintPass, LintContext};
|
use crate::{lints::InvalidReferenceCastingDiag, LateContext, LateLintPass, LintContext};
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
/// The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T`
|
/// The `invalid_reference_casting` lint checks for casts of `&T` to `&mut T`
|
||||||
/// without using interior mutability.
|
/// without using interior mutability.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
///
|
///
|
||||||
/// ```rust,compile_fail
|
/// ```rust,compile_fail
|
||||||
|
/// # #![deny(invalid_reference_casting)]
|
||||||
/// fn x(r: &i32) {
|
/// fn x(r: &i32) {
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// *(r as *const i32 as *mut i32) += 1;
|
/// *(r as *const i32 as *mut i32) += 1;
|
||||||
|
@ -28,14 +29,14 @@ declare_lint! {
|
||||||
///
|
///
|
||||||
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
|
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
|
||||||
/// mutable.
|
/// mutable.
|
||||||
CAST_REF_TO_MUT,
|
INVALID_REFERENCE_CASTING,
|
||||||
Deny,
|
Allow,
|
||||||
"casts of `&T` to `&mut T` without interior mutability"
|
"casts of `&T` to `&mut T` without interior mutability"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint_pass!(CastRefToMut => [CAST_REF_TO_MUT]);
|
declare_lint_pass!(InvalidReferenceCasting => [INVALID_REFERENCE_CASTING]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for CastRefToMut {
|
impl<'tcx> LateLintPass<'tcx> for InvalidReferenceCasting {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||||
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else {
|
let ExprKind::Unary(UnOp::Deref, e) = &expr.kind else {
|
||||||
return;
|
return;
|
||||||
|
@ -68,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for CastRefToMut {
|
||||||
|
|
||||||
let e = e.peel_blocks();
|
let e = e.peel_blocks();
|
||||||
if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind() {
|
if let ty::Ref(..) = cx.typeck_results().node_type(e.hir_id).kind() {
|
||||||
cx.emit_spanned_lint(CAST_REF_TO_MUT, expr.span, CastRefToMutDiag);
|
cx.emit_spanned_lint(INVALID_REFERENCE_CASTING, expr.span, InvalidReferenceCastingDiag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
|
||||||
("clippy::stutter", "clippy::module_name_repetitions"),
|
("clippy::stutter", "clippy::module_name_repetitions"),
|
||||||
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
|
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
|
||||||
("clippy::zero_width_space", "clippy::invisible_characters"),
|
("clippy::zero_width_space", "clippy::invisible_characters"),
|
||||||
("clippy::cast_ref_to_mut", "cast_ref_to_mut"),
|
("clippy::cast_ref_to_mut", "invalid_reference_casting"),
|
||||||
("clippy::clone_double_ref", "suspicious_double_ref_op"),
|
("clippy::clone_double_ref", "suspicious_double_ref_op"),
|
||||||
("clippy::cmp_nan", "invalid_nan_comparisons"),
|
("clippy::cmp_nan", "invalid_nan_comparisons"),
|
||||||
("clippy::drop_bounds", "drop_bounds"),
|
("clippy::drop_bounds", "drop_bounds"),
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
#![allow(clippy::module_name_repetitions)]
|
#![allow(clippy::module_name_repetitions)]
|
||||||
#![allow(clippy::recursive_format_impl)]
|
#![allow(clippy::recursive_format_impl)]
|
||||||
#![allow(clippy::invisible_characters)]
|
#![allow(clippy::invisible_characters)]
|
||||||
#![allow(cast_ref_to_mut)]
|
|
||||||
#![allow(suspicious_double_ref_op)]
|
#![allow(suspicious_double_ref_op)]
|
||||||
#![allow(invalid_nan_comparisons)]
|
#![allow(invalid_nan_comparisons)]
|
||||||
|
#![allow(invalid_reference_casting)]
|
||||||
#![allow(drop_bounds)]
|
#![allow(drop_bounds)]
|
||||||
#![allow(dropping_copy_types)]
|
#![allow(dropping_copy_types)]
|
||||||
#![allow(dropping_references)]
|
#![allow(dropping_references)]
|
||||||
|
@ -79,7 +79,7 @@
|
||||||
#![warn(clippy::module_name_repetitions)]
|
#![warn(clippy::module_name_repetitions)]
|
||||||
#![warn(clippy::recursive_format_impl)]
|
#![warn(clippy::recursive_format_impl)]
|
||||||
#![warn(clippy::invisible_characters)]
|
#![warn(clippy::invisible_characters)]
|
||||||
#![warn(cast_ref_to_mut)]
|
#![warn(invalid_reference_casting)]
|
||||||
#![warn(suspicious_double_ref_op)]
|
#![warn(suspicious_double_ref_op)]
|
||||||
#![warn(invalid_nan_comparisons)]
|
#![warn(invalid_nan_comparisons)]
|
||||||
#![warn(drop_bounds)]
|
#![warn(drop_bounds)]
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
#![allow(clippy::module_name_repetitions)]
|
#![allow(clippy::module_name_repetitions)]
|
||||||
#![allow(clippy::recursive_format_impl)]
|
#![allow(clippy::recursive_format_impl)]
|
||||||
#![allow(clippy::invisible_characters)]
|
#![allow(clippy::invisible_characters)]
|
||||||
#![allow(cast_ref_to_mut)]
|
|
||||||
#![allow(suspicious_double_ref_op)]
|
#![allow(suspicious_double_ref_op)]
|
||||||
#![allow(invalid_nan_comparisons)]
|
#![allow(invalid_nan_comparisons)]
|
||||||
|
#![allow(invalid_reference_casting)]
|
||||||
#![allow(drop_bounds)]
|
#![allow(drop_bounds)]
|
||||||
#![allow(dropping_copy_types)]
|
#![allow(dropping_copy_types)]
|
||||||
#![allow(dropping_references)]
|
#![allow(dropping_references)]
|
||||||
|
|
|
@ -174,11 +174,11 @@ error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_ch
|
||||||
LL | #![warn(clippy::zero_width_space)]
|
LL | #![warn(clippy::zero_width_space)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
|
||||||
|
|
||||||
error: lint `clippy::cast_ref_to_mut` has been renamed to `cast_ref_to_mut`
|
error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting`
|
||||||
--> $DIR/rename.rs:82:9
|
--> $DIR/rename.rs:82:9
|
||||||
|
|
|
|
||||||
LL | #![warn(clippy::cast_ref_to_mut)]
|
LL | #![warn(clippy::cast_ref_to_mut)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `cast_ref_to_mut`
|
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting`
|
||||||
|
|
||||||
error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op`
|
error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op`
|
||||||
--> $DIR/rename.rs:83:9
|
--> $DIR/rename.rs:83:9
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@revisions: stack tree
|
//@revisions: stack tree
|
||||||
//@[tree]compile-flags: -Zmiri-tree-borrows
|
//@[tree]compile-flags: -Zmiri-tree-borrows
|
||||||
|
|
||||||
#![allow(cast_ref_to_mut)]
|
#![allow(invalid_reference_casting)]
|
||||||
|
|
||||||
fn foo(x: &mut i32) -> i32 {
|
fn foo(x: &mut i32) -> i32 {
|
||||||
*x = 5;
|
*x = 5;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// This should fail even without validation/SB
|
// This should fail even without validation/SB
|
||||||
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
|
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
|
||||||
|
|
||||||
#![allow(cast_ref_to_mut)]
|
#![allow(invalid_reference_casting)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee
|
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee
|
||||||
|
|
|
@ -9,7 +9,6 @@ impl <const B: &'static bool> T<B> {
|
||||||
unsafe {
|
unsafe {
|
||||||
*(B as *const bool as *mut bool) = false;
|
*(B as *const bool as *mut bool) = false;
|
||||||
//~^ ERROR evaluation of constant value failed [E0080]
|
//~^ ERROR evaluation of constant value failed [E0080]
|
||||||
//~| ERROR casting `&T` to `&mut T` is undefined behavior
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
|
||||||
--> $DIR/issue-100313.rs:10:13
|
|
||||||
|
|
|
||||||
LL | *(B as *const bool as *mut bool) = false;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: `#[deny(cast_ref_to_mut)]` on by default
|
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/issue-100313.rs:10:13
|
--> $DIR/issue-100313.rs:10:13
|
||||||
|
|
|
|
||||||
|
@ -18,11 +10,11 @@ note: inside `T::<&true>::set_false`
|
||||||
LL | *(B as *const bool as *mut bool) = false;
|
LL | *(B as *const bool as *mut bool) = false;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
note: inside `_`
|
note: inside `_`
|
||||||
--> $DIR/issue-100313.rs:19:5
|
--> $DIR/issue-100313.rs:18:5
|
||||||
|
|
|
|
||||||
LL | x.set_false();
|
LL | x.set_false();
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0080`.
|
For more information about this error, try `rustc --explain E0080`.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// check-fail
|
// check-fail
|
||||||
|
|
||||||
#![feature(ptr_from_ref)]
|
#![feature(ptr_from_ref)]
|
||||||
|
#![deny(invalid_reference_casting)]
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// N.B., mutability can be easily incorrect in FFI calls -- as
|
// N.B., mutability can be easily incorrect in FFI calls -- as
|
|
@ -1,61 +1,65 @@
|
||||||
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/cast_ref_to_mut.rs:19:9
|
--> $DIR/reference_casting.rs:20:9
|
||||||
|
|
|
|
||||||
LL | (*(a as *const _ as *mut String)).push_str(" world");
|
LL | (*(a as *const _ as *mut String)).push_str(" world");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `#[deny(cast_ref_to_mut)]` on by default
|
note: the lint level is defined here
|
||||||
|
--> $DIR/reference_casting.rs:4:9
|
||||||
|
|
|
||||||
|
LL | #![deny(invalid_reference_casting)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
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/cast_ref_to_mut.rs:21:9
|
--> $DIR/reference_casting.rs:22:9
|
||||||
|
|
|
|
||||||
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
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/cast_ref_to_mut.rs:23:9
|
--> $DIR/reference_casting.rs:24:9
|
||||||
|
|
|
|
||||||
LL | *(a as *const _ as *mut String) += " world";
|
LL | *(a as *const _ as *mut String) += " world";
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
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/cast_ref_to_mut.rs:25:25
|
--> $DIR/reference_casting.rs:26:25
|
||||||
|
|
|
|
||||||
LL | let _num = &mut *(num as *const i32 as *mut i32);
|
LL | let _num = &mut *(num as *const i32 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/cast_ref_to_mut.rs:27:25
|
--> $DIR/reference_casting.rs:28:25
|
||||||
|
|
|
|
||||||
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/cast_ref_to_mut.rs:29:20
|
--> $DIR/reference_casting.rs:30:20
|
||||||
|
|
|
|
||||||
LL | let _num = *{ num as *const i32 }.cast_mut();
|
LL | let _num = *{ 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/cast_ref_to_mut.rs:31:9
|
--> $DIR/reference_casting.rs:32:9
|
||||||
|
|
|
|
||||||
LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
LL | *std::ptr::from_ref(num).cast_mut() += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
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/cast_ref_to_mut.rs:33:9
|
--> $DIR/reference_casting.rs:34:9
|
||||||
|
|
|
|
||||||
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
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/cast_ref_to_mut.rs:35:9
|
--> $DIR/reference_casting.rs:36:9
|
||||||
|
|
|
|
||||||
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
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/cast_ref_to_mut.rs:37:9
|
--> $DIR/reference_casting.rs:38:9
|
||||||
|
|
|
|
||||||
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
Loading…
Add table
Add a link
Reference in a new issue