make never_type_fallback_flowing_into_unsafe a non-FCW lint

This commit is contained in:
Waffle Lapkin
2026-06-24 20:19:42 +02:00
parent e9d08de898
commit 39c6cacb34
3 changed files with 13 additions and 200 deletions

View File

@@ -4175,9 +4175,9 @@ declare_lint! {
///
/// ### Explanation
///
/// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
/// coerced to `()`. There are plans to change that, but they may make the code such as above
/// unsound. Instead of depending on the fallback, you should specify the type explicitly:
/// The never type fallback used to be `()`, meaning that `!` got spontaneously coerced to `()`.
/// Since then the never type fallback has been changed to `!`, making the above code undefined
/// behavior. Instead of depending on the fallback, you should specify the type explicitly:
/// ```
/// if true {
/// return
@@ -4194,11 +4194,6 @@ declare_lint! {
pub NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
Deny,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(EditionAndFutureReleaseSemanticsChange 2024 "never-type-fallback"),
report_in_deps: true,
};
@edition Edition2024 => Deny;
report_in_external_macro
}

View File

@@ -8,7 +8,6 @@ fn _zero() {
if false {
unsafe { mem::zeroed() }
//~^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
//~| warn: the type `!` does not permit zero-initialization
} else {
return;
@@ -24,7 +23,6 @@ fn _trans() {
struct Zst;
core::mem::transmute(Zst)
//~^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
}
} else {
return;
@@ -40,7 +38,6 @@ fn _union() {
unsafe { Union { a: () }.b }
//~^ error: never type fallback affects this union access
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
} else {
return;
};
@@ -50,7 +47,6 @@ fn _deref() {
if false {
unsafe { *ptr::from_ref(&()).cast() }
//~^ error: never type fallback affects this raw pointer dereference
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
} else {
return;
};
@@ -70,7 +66,6 @@ fn _only_generics() {
unsafe { internally_create(x) }
//~^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
x.unwrap()
} else {
@@ -82,11 +77,9 @@ fn _stored_function() {
if false {
let zeroed = mem::zeroed;
//~^ error: never type fallback affects this `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
unsafe { zeroed() }
//~^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
} else {
return;
};
@@ -103,7 +96,6 @@ fn _only_generics_stored_function() {
let x = None;
let f = internally_create;
//~^ error: never type fallback affects this `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
unsafe { f(x) }
@@ -127,7 +119,6 @@ fn _method() {
unsafe {
S(marker::PhantomData).create_out_of_thin_air()
//~^ error: never type fallback affects this call to an `unsafe` method
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
}
} else {
return;
@@ -144,7 +135,6 @@ fn _objc() {
() => {
match send_message::<_ /* ?0 */>() {
//~^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
Ok(x) => x,
Err(_) => loop {},
}

View File

@@ -5,120 +5,102 @@ LL | unsafe { mem::zeroed() }
| ^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` on by default
help: use `()` annotations to avoid fallback changes
|
LL | unsafe { mem::zeroed::<()>() }
| ++++++
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:25:13
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:24:13
|
LL | core::mem::transmute(Zst)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
help: use `()` annotations to avoid fallback changes
|
LL | core::mem::transmute::<_, ()>(Zst)
| +++++++++
error: never type fallback affects this union access
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:41:18
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:39:18
|
LL | unsafe { Union { a: () }.b }
| ^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
error: never type fallback affects this raw pointer dereference
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:51:18
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:48:18
|
LL | unsafe { *ptr::from_ref(&()).cast() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
help: use `()` annotations to avoid fallback changes
|
LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
| ++++++
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:71:18
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:67:18
|
LL | unsafe { internally_create(x) }
| ^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
help: use `()` annotations to avoid fallback changes
|
LL | unsafe { internally_create::<()>(x) }
| ++++++
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:87:18
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:81:18
|
LL | unsafe { zeroed() }
| ^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
help: use `()` annotations to avoid fallback changes
|
LL | let zeroed = mem::zeroed::<()>;
| ++++++
error: never type fallback affects this `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:83:22
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:78:22
|
LL | let zeroed = mem::zeroed;
| ^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
help: use `()` annotations to avoid fallback changes
|
LL | let zeroed = mem::zeroed::<()>;
| ++++++
error: never type fallback affects this `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:104:17
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:97:17
|
LL | let f = internally_create;
| ^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
help: use `()` annotations to avoid fallback changes
|
LL | let f = internally_create::<()>;
| ++++++
error: never type fallback affects this call to an `unsafe` method
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:128:13
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:120:13
|
LL | S(marker::PhantomData).create_out_of_thin_air()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:145:19
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:136:19
|
LL | match send_message::<_ /* ?0 */>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -127,8 +109,6 @@ LL | msg_send!();
| ----------- in this macro invocation
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: the type `!` does not permit zero-initialization
@@ -142,155 +122,3 @@ LL | unsafe { mem::zeroed() }
error: aborting due to 10 previous errors; 1 warning emitted
Future incompatibility report: Future breakage diagnostic:
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:9:18
|
LL | unsafe { mem::zeroed() }
| ^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | unsafe { mem::zeroed::<()>() }
| ++++++
Future breakage diagnostic:
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:25:13
|
LL | core::mem::transmute(Zst)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | core::mem::transmute::<_, ()>(Zst)
| +++++++++
Future breakage diagnostic:
error: never type fallback affects this union access
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:41:18
|
LL | unsafe { Union { a: () }.b }
| ^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
Future breakage diagnostic:
error: never type fallback affects this raw pointer dereference
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:51:18
|
LL | unsafe { *ptr::from_ref(&()).cast() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
| ++++++
Future breakage diagnostic:
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:71:18
|
LL | unsafe { internally_create(x) }
| ^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | unsafe { internally_create::<()>(x) }
| ++++++
Future breakage diagnostic:
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:87:18
|
LL | unsafe { zeroed() }
| ^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | let zeroed = mem::zeroed::<()>;
| ++++++
Future breakage diagnostic:
error: never type fallback affects this `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:83:22
|
LL | let zeroed = mem::zeroed;
| ^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | let zeroed = mem::zeroed::<()>;
| ++++++
Future breakage diagnostic:
error: never type fallback affects this `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:104:17
|
LL | let f = internally_create;
| ^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | let f = internally_create::<()>;
| ++++++
Future breakage diagnostic:
error: never type fallback affects this call to an `unsafe` method
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:128:13
|
LL | S(marker::PhantomData).create_out_of_thin_air()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
Future breakage diagnostic:
error: never type fallback affects this call to an `unsafe` function
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:145:19
|
LL | match send_message::<_ /* ?0 */>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | msg_send!();
| ----------- in this macro invocation
|
= help: specify the type explicitly
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)