Skip to content

Commit f25ad54

Browse files
committed
Temporarily switch invalid_reference_casting lint to allow-by-default
1 parent fa15df6 commit f25ad54

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

Diff for: compiler/rustc_lint/src/reference_casting.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare_lint! {
1212
/// ### Example
1313
///
1414
/// ```rust,compile_fail
15+
/// # #![deny(invalid_reference_casting)]
1516
/// fn x(r: &i32) {
1617
/// unsafe {
1718
/// *(r as *const i32 as *mut i32) += 1;
@@ -29,7 +30,7 @@ declare_lint! {
2930
/// `UnsafeCell` is the only way to obtain aliasable data that is considered
3031
/// mutable.
3132
INVALID_REFERENCE_CASTING,
32-
Deny,
33+
Allow,
3334
"casts of `&T` to `&mut T` without interior mutability"
3435
}
3536

Diff for: tests/ui/const-generics/issues/issue-100313.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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
1312
}
1413
}
1514
}

Diff for: tests/ui/const-generics/issues/issue-100313.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
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-
91
error[E0080]: evaluation of constant value failed
102
--> $DIR/issue-100313.rs:10:13
113
|
@@ -18,11 +10,11 @@ note: inside `T::<&true>::set_false`
1810
LL | *(B as *const bool as *mut bool) = false;
1911
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2012
note: inside `_`
21-
--> $DIR/issue-100313.rs:19:5
13+
--> $DIR/issue-100313.rs:18:5
2214
|
2315
LL | x.set_false();
2416
| ^^^^^^^^^^^^^
2517

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

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

Diff for: tests/ui/lint/reference_casting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-fail
22

33
#![feature(ptr_from_ref)]
4+
#![deny(invalid_reference_casting)]
45

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

Diff for: tests/ui/lint/reference_casting.stderr

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,65 @@
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:19:9
2+
--> $DIR/reference_casting.rs:20:9
33
|
44
LL | (*(a as *const _ as *mut String)).push_str(" world");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[deny(invalid_reference_casting)]` on by default
7+
note: the lint level is defined here
8+
--> $DIR/reference_casting.rs:4:9
9+
|
10+
LL | #![deny(invalid_reference_casting)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
812

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)