Skip to content

Commit 18c248b

Browse files
committed
Make NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE deny-by-default in e2024
1 parent 33422e7 commit 18c248b

4 files changed

+160
-23
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4197,6 +4197,7 @@ declare_lint! {
41974197
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
41984198
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
41994199
};
4200+
@edition Edition2024 => Deny;
42004201
report_in_external_macro
42014202
}
42024203

tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.stderr renamed to tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: never type fallback affects this call to an `unsafe` function
2-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:8:18
2+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:13:18
33
|
44
LL | unsafe { mem::zeroed() }
55
| ^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | unsafe { mem::zeroed() }
1010
= note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default
1111

1212
warning: never type fallback affects this call to an `unsafe` function
13-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:23:13
13+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:30:13
1414
|
1515
LL | core::mem::transmute(Zst)
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,7 +20,7 @@ LL | core::mem::transmute(Zst)
2020
= help: specify the type explicitly
2121

2222
warning: never type fallback affects this union access
23-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:39:18
23+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:47:18
2424
|
2525
LL | unsafe { Union { a: () }.b }
2626
| ^^^^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | unsafe { Union { a: () }.b }
3030
= help: specify the type explicitly
3131

3232
warning: never type fallback affects this raw pointer dereference
33-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:49:18
33+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:58:18
3434
|
3535
LL | unsafe { *ptr::from_ref(&()).cast() }
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL | unsafe { *ptr::from_ref(&()).cast() }
4040
= help: specify the type explicitly
4141

4242
warning: never type fallback affects this call to an `unsafe` function
43-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:67:18
43+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:79:18
4444
|
4545
LL | unsafe { internally_create(x) }
4646
| ^^^^^^^^^^^^^^^^^^^^
@@ -50,7 +50,7 @@ LL | unsafe { internally_create(x) }
5050
= help: specify the type explicitly
5151

5252
warning: never type fallback affects this call to an `unsafe` function
53-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:83:18
53+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:97:18
5454
|
5555
LL | unsafe { zeroed() }
5656
| ^^^^^^^^
@@ -60,7 +60,7 @@ LL | unsafe { zeroed() }
6060
= help: specify the type explicitly
6161

6262
warning: never type fallback affects this `unsafe` function
63-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:79:22
63+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:92:22
6464
|
6565
LL | let zeroed = mem::zeroed;
6666
| ^^^^^^^^^^^
@@ -70,7 +70,7 @@ LL | let zeroed = mem::zeroed;
7070
= help: specify the type explicitly
7171

7272
warning: never type fallback affects this `unsafe` function
73-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:98:17
73+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:115:17
7474
|
7575
LL | let f = internally_create;
7676
| ^^^^^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL | let f = internally_create;
8080
= help: specify the type explicitly
8181

8282
warning: never type fallback affects this call to an `unsafe` method
83-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:122:13
83+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:140:13
8484
|
8585
LL | S(marker::PhantomData).create_out_of_thin_air()
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -90,7 +90,7 @@ LL | S(marker::PhantomData).create_out_of_thin_air()
9090
= help: specify the type explicitly
9191

9292
warning: never type fallback affects this call to an `unsafe` function
93-
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:139:19
93+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:158:19
9494
|
9595
LL | match send_message::<_ /* ?0 */>() {
9696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
error: never type fallback affects this call to an `unsafe` function
2+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:13:18
3+
|
4+
LL | unsafe { mem::zeroed() }
5+
| ^^^^^^^^^^^^^
6+
|
7+
= warning: this will change its meaning in a future release!
8+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
9+
= help: specify the type explicitly
10+
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` on by default
11+
12+
error: never type fallback affects this call to an `unsafe` function
13+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:30:13
14+
|
15+
LL | core::mem::transmute(Zst)
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
17+
|
18+
= warning: this will change its meaning in a future release!
19+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
20+
= help: specify the type explicitly
21+
22+
error: never type fallback affects this union access
23+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:47:18
24+
|
25+
LL | unsafe { Union { a: () }.b }
26+
| ^^^^^^^^^^^^^^^^^
27+
|
28+
= warning: this will change its meaning in a future release!
29+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
30+
= help: specify the type explicitly
31+
32+
error: never type fallback affects this raw pointer dereference
33+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:58:18
34+
|
35+
LL | unsafe { *ptr::from_ref(&()).cast() }
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
|
38+
= warning: this will change its meaning in a future release!
39+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
40+
= help: specify the type explicitly
41+
42+
error: never type fallback affects this call to an `unsafe` function
43+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:79:18
44+
|
45+
LL | unsafe { internally_create(x) }
46+
| ^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= warning: this will change its meaning in a future release!
49+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
50+
= help: specify the type explicitly
51+
52+
error: never type fallback affects this call to an `unsafe` function
53+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:97:18
54+
|
55+
LL | unsafe { zeroed() }
56+
| ^^^^^^^^
57+
|
58+
= warning: this will change its meaning in a future release!
59+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
60+
= help: specify the type explicitly
61+
62+
error: never type fallback affects this `unsafe` function
63+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:92:22
64+
|
65+
LL | let zeroed = mem::zeroed;
66+
| ^^^^^^^^^^^
67+
|
68+
= warning: this will change its meaning in a future release!
69+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
70+
= help: specify the type explicitly
71+
72+
error: never type fallback affects this `unsafe` function
73+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:115:17
74+
|
75+
LL | let f = internally_create;
76+
| ^^^^^^^^^^^^^^^^^
77+
|
78+
= warning: this will change its meaning in a future release!
79+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
80+
= help: specify the type explicitly
81+
82+
error: never type fallback affects this call to an `unsafe` method
83+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:140:13
84+
|
85+
LL | S(marker::PhantomData).create_out_of_thin_air()
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= warning: this will change its meaning in a future release!
89+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
90+
= help: specify the type explicitly
91+
92+
error: never type fallback affects this call to an `unsafe` function
93+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:158:19
94+
|
95+
LL | match send_message::<_ /* ?0 */>() {
96+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
...
98+
LL | msg_send!();
99+
| ----------- in this macro invocation
100+
|
101+
= warning: this will change its meaning in a future release!
102+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
103+
= help: specify the type explicitly
104+
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
105+
106+
warning: the type `!` does not permit zero-initialization
107+
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:13:18
108+
|
109+
LL | unsafe { mem::zeroed() }
110+
| ^^^^^^^^^^^^^ this code causes undefined behavior when executed
111+
|
112+
= note: the `!` type has no valid value
113+
= note: `#[warn(invalid_value)]` on by default
114+
115+
error: aborting due to 10 previous errors; 1 warning emitted
116+

tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs

+33-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
//@ check-pass
1+
//@ revisions: e2015 e2024
2+
//@[e2015] check-pass
3+
//@[e2024] check-fail
4+
//@[e2024] edition:2024
5+
//@[e2024] compile-flags: -Zunstable-options
6+
27
use std::{marker, mem, ptr};
38

49
fn main() {}
510

611
fn _zero() {
712
if false {
813
unsafe { mem::zeroed() }
9-
//~^ warn: never type fallback affects this call to an `unsafe` function
14+
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
15+
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
1016
//~| warn: this will change its meaning in a future release!
17+
//[e2024]~| warning: the type `!` does not permit zero-initialization
1118
} else {
1219
return;
1320
};
@@ -21,7 +28,8 @@ fn _trans() {
2128
unsafe {
2229
struct Zst;
2330
core::mem::transmute(Zst)
24-
//~^ warn: never type fallback affects this call to an `unsafe` function
31+
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
32+
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
2533
//~| warn: this will change its meaning in a future release!
2634
}
2735
} else {
@@ -37,7 +45,8 @@ fn _union() {
3745
}
3846

3947
unsafe { Union { a: () }.b }
40-
//~^ warn: never type fallback affects this union access
48+
//[e2015]~^ warn: never type fallback affects this union access
49+
//[e2024]~^^ error: never type fallback affects this union access
4150
//~| warn: this will change its meaning in a future release!
4251
} else {
4352
return;
@@ -47,7 +56,8 @@ fn _union() {
4756
fn _deref() {
4857
if false {
4958
unsafe { *ptr::from_ref(&()).cast() }
50-
//~^ warn: never type fallback affects this raw pointer dereference
59+
//[e2015]~^ warn: never type fallback affects this raw pointer dereference
60+
//[e2024]~^^ error: never type fallback affects this raw pointer dereference
5161
//~| warn: this will change its meaning in a future release!
5262
} else {
5363
return;
@@ -57,15 +67,18 @@ fn _deref() {
5767
fn _only_generics() {
5868
if false {
5969
unsafe fn internally_create<T>(_: Option<T>) {
60-
let _ = mem::zeroed::<T>();
70+
unsafe {
71+
let _ = mem::zeroed::<T>();
72+
}
6173
}
6274

6375
// We need the option (and unwrap later) to call a function in a way,
6476
// which makes it affected by the fallback, but without having it return anything
6577
let x = None;
6678

6779
unsafe { internally_create(x) }
68-
//~^ warn: never type fallback affects this call to an `unsafe` function
80+
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
81+
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
6982
//~| warn: this will change its meaning in a future release!
7083

7184
x.unwrap()
@@ -77,11 +90,13 @@ fn _only_generics() {
7790
fn _stored_function() {
7891
if false {
7992
let zeroed = mem::zeroed;
80-
//~^ warn: never type fallback affects this `unsafe` function
93+
//[e2015]~^ warn: never type fallback affects this `unsafe` function
94+
//[e2024]~^^ error: never type fallback affects this `unsafe` function
8195
//~| warn: this will change its meaning in a future release!
8296

8397
unsafe { zeroed() }
84-
//~^ warn: never type fallback affects this call to an `unsafe` function
98+
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
99+
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
85100
//~| warn: this will change its meaning in a future release!
86101
} else {
87102
return;
@@ -91,12 +106,15 @@ fn _stored_function() {
91106
fn _only_generics_stored_function() {
92107
if false {
93108
unsafe fn internally_create<T>(_: Option<T>) {
94-
let _ = mem::zeroed::<T>();
109+
unsafe {
110+
let _ = mem::zeroed::<T>();
111+
}
95112
}
96113

97114
let x = None;
98115
let f = internally_create;
99-
//~^ warn: never type fallback affects this `unsafe` function
116+
//[e2015]~^ warn: never type fallback affects this `unsafe` function
117+
//[e2024]~^^ error: never type fallback affects this `unsafe` function
100118
//~| warn: this will change its meaning in a future release!
101119

102120
unsafe { f(x) }
@@ -120,7 +138,8 @@ fn _method() {
120138
if false {
121139
unsafe {
122140
S(marker::PhantomData).create_out_of_thin_air()
123-
//~^ warn: never type fallback affects this call to an `unsafe` method
141+
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` method
142+
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` method
124143
//~| warn: this will change its meaning in a future release!
125144
}
126145
} else {
@@ -137,7 +156,8 @@ fn _objc() {
137156
macro_rules! msg_send {
138157
() => {
139158
match send_message::<_ /* ?0 */>() {
140-
//~^ warn: never type fallback affects this call to an `unsafe` function
159+
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
160+
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
141161
//~| warn: this will change its meaning in a future release!
142162
Ok(x) => x,
143163
Err(_) => loop {},

0 commit comments

Comments
 (0)