Skip to content

Commit 345d6b8

Browse files
committed
Revert "Temporarily switch invalid_reference_casting lint to allow-by-default"
This reverts commit f25ad54.
1 parent 0441150 commit 345d6b8

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

compiler/rustc_lint/src/reference_casting.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ declare_lint! {
1212
/// ### Example
1313
///
1414
/// ```rust,compile_fail
15-
/// # #![deny(invalid_reference_casting)]
1615
/// fn x(r: &i32) {
1716
/// unsafe {
1817
/// *(r as *const i32 as *mut i32) += 1;
@@ -30,7 +29,7 @@ declare_lint! {
3029
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
3130
/// mutable.
3231
INVALID_REFERENCE_CASTING,
33-
Allow,
32+
Deny,
3433
"casts of `&T` to `&mut T` without interior mutability"
3534
}
3635

tests/ui/const-generics/issues/issue-100313.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ impl <const B: &'static bool> T<B> {
99
unsafe {
1010
*(B as *const bool as *mut bool) = false;
1111
//~^ ERROR evaluation of constant value failed [E0080]
12+
//~| ERROR casting `&T` to `&mut T` is undefined behavior
1213
}
1314
}
1415
}

tests/ui/const-generics/issues/issue-100313.stderr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
2+
--> $DIR/issue-100313.rs:10:13
3+
|
4+
LL | *(B as *const bool as *mut bool) = false;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[deny(invalid_reference_casting)]` on by default
8+
19
error[E0080]: evaluation of constant value failed
210
--> $DIR/issue-100313.rs:10:13
311
|
@@ -10,11 +18,11 @@ note: inside `T::<&true>::set_false`
1018
LL | *(B as *const bool as *mut bool) = false;
1119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1220
note: inside `_`
13-
--> $DIR/issue-100313.rs:18:5
21+
--> $DIR/issue-100313.rs:19:5
1422
|
1523
LL | x.set_false();
1624
| ^^^^^^^^^^^^^
1725

18-
error: aborting due to previous error
26+
error: aborting due to 2 previous errors
1927

2028
For more information about this error, try `rustc --explain E0080`.

tests/ui/lint/reference_casting.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// check-fail
22

33
#![feature(ptr_from_ref)]
4-
#![deny(invalid_reference_casting)]
54

65
extern "C" {
76
// N.B., mutability can be easily incorrect in FFI calls -- as

tests/ui/lint/reference_casting.stderr

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,61 @@
11
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
2-
--> $DIR/reference_casting.rs:20:9
2+
--> $DIR/reference_casting.rs:19:9
33
|
44
LL | (*(a as *const _ as *mut String)).push_str(" world");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: the lint level is defined here
8-
--> $DIR/reference_casting.rs:4:9
9-
|
10-
LL | #![deny(invalid_reference_casting)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: `#[deny(invalid_reference_casting)]` on by default
128

139
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
14-
--> $DIR/reference_casting.rs:22:9
10+
--> $DIR/reference_casting.rs:21:9
1511
|
1612
LL | *(a as *const _ as *mut _) = String::from("Replaced");
1713
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1814

1915
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
20-
--> $DIR/reference_casting.rs:24:9
16+
--> $DIR/reference_casting.rs:23:9
2117
|
2218
LL | *(a as *const _ as *mut String) += " world";
2319
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2420

2521
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
26-
--> $DIR/reference_casting.rs:26:25
22+
--> $DIR/reference_casting.rs:25:25
2723
|
2824
LL | let _num = &mut *(num as *const i32 as *mut i32);
2925
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3026

3127
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
32-
--> $DIR/reference_casting.rs:28:25
28+
--> $DIR/reference_casting.rs:27:25
3329
|
3430
LL | let _num = &mut *(num as *const i32).cast_mut();
3531
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3632

3733
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
38-
--> $DIR/reference_casting.rs:30:20
34+
--> $DIR/reference_casting.rs:29:20
3935
|
4036
LL | let _num = *{ num as *const i32 }.cast_mut();
4137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4238

4339
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
44-
--> $DIR/reference_casting.rs:32:9
40+
--> $DIR/reference_casting.rs:31:9
4541
|
4642
LL | *std::ptr::from_ref(num).cast_mut() += 1;
4743
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4844

4945
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
50-
--> $DIR/reference_casting.rs:34:9
46+
--> $DIR/reference_casting.rs:33:9
5147
|
5248
LL | *std::ptr::from_ref({ num }).cast_mut() += 1;
5349
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5450

5551
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
56-
--> $DIR/reference_casting.rs:36:9
52+
--> $DIR/reference_casting.rs:35:9
5753
|
5854
LL | *{ std::ptr::from_ref(num) }.cast_mut() += 1;
5955
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6056

6157
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
62-
--> $DIR/reference_casting.rs:38:9
58+
--> $DIR/reference_casting.rs:37:9
6359
|
6460
LL | *(std::ptr::from_ref({ num }) as *mut i32) += 1;
6561
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)