mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Revert "Temporarily switch invalid_reference_casting lint to allow-by-default"
This reverts commit f25ad54a4d
.
This commit is contained in:
parent
04411507be
commit
345d6b816b
@ -12,7 +12,6 @@ declare_lint! {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,compile_fail
|
||||
/// # #![deny(invalid_reference_casting)]
|
||||
/// fn x(r: &i32) {
|
||||
/// unsafe {
|
||||
/// *(r as *const i32 as *mut i32) += 1;
|
||||
@ -30,7 +29,7 @@ declare_lint! {
|
||||
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
|
||||
/// mutable.
|
||||
INVALID_REFERENCE_CASTING,
|
||||
Allow,
|
||||
Deny,
|
||||
"casts of `&T` to `&mut T` without interior mutability"
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ impl <const B: &'static bool> T<B> {
|
||||
unsafe {
|
||||
*(B as *const bool as *mut bool) = false;
|
||||
//~^ ERROR evaluation of constant value failed [E0080]
|
||||
//~| ERROR casting `&T` to `&mut T` is undefined behavior
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,11 @@
|
||||
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(invalid_reference_casting)]` on by default
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-100313.rs:10:13
|
||||
|
|
||||
@ -10,11 +18,11 @@ note: inside `T::<&true>::set_false`
|
||||
LL | *(B as *const bool as *mut bool) = false;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: inside `_`
|
||||
--> $DIR/issue-100313.rs:18:5
|
||||
--> $DIR/issue-100313.rs:19:5
|
||||
|
|
||||
LL | x.set_false();
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -1,7 +1,6 @@
|
||||
// check-fail
|
||||
|
||||
#![feature(ptr_from_ref)]
|
||||
#![deny(invalid_reference_casting)]
|
||||
|
||||
extern "C" {
|
||||
// N.B., mutability can be easily incorrect in FFI calls -- as
|
||||
|
@ -1,65 +1,61 @@
|
||||
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
|
||||
--> $DIR/reference_casting.rs:20:9
|
||||
--> $DIR/reference_casting.rs:19:9
|
||||
|
|
||||
LL | (*(a as *const _ as *mut String)).push_str(" world");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/reference_casting.rs:4:9
|
||||
|
|
||||
LL | #![deny(invalid_reference_casting)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= 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`
|
||||
--> $DIR/reference_casting.rs:22:9
|
||||
--> $DIR/reference_casting.rs:21:9
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:24:9
|
||||
--> $DIR/reference_casting.rs:23:9
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:26:25
|
||||
--> $DIR/reference_casting.rs:25:25
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:28:25
|
||||
--> $DIR/reference_casting.rs:27:25
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:30:20
|
||||
--> $DIR/reference_casting.rs:29:20
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:32:9
|
||||
--> $DIR/reference_casting.rs:31:9
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:34:9
|
||||
--> $DIR/reference_casting.rs:33:9
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:36:9
|
||||
--> $DIR/reference_casting.rs:35:9
|
||||
|
|
||||
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`
|
||||
--> $DIR/reference_casting.rs:38:9
|
||||
--> $DIR/reference_casting.rs:37:9
|
||||
|
|
||||
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user