Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4100,7 +4100,7 @@ declare_lint! {
/// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
/// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
pub NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
Warn,
Deny,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
Expand Down Expand Up @@ -4155,7 +4155,7 @@ declare_lint! {
///
/// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
pub DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
Warn,
Deny,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
Expand Down
22 changes: 10 additions & 12 deletions tests/ui/editions/never-type-fallback-breaking.e2021.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
//@[e2021] edition: 2021
//@[e2024] edition: 2024
//
//@[e2021] run-pass
//@[e2021] run-rustfix
//@[e2024] check-fail

fn main() {
m();
Expand All @@ -16,8 +14,8 @@ fn main() {
}

fn m() {
//[e2021]~^ WARN this function depends on never type fallback being `()`
//[e2021]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
//[e2021]~^ error: this function depends on never type fallback being `()`
//[e2021]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
let x: () = match true {
true => Default::default(),
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
Expand All @@ -28,8 +26,8 @@ fn m() {
}

fn q() -> Option<()> {
//[e2021]~^ WARN this function depends on never type fallback being `()`
//[e2021]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
//[e2021]~^ error: this function depends on never type fallback being `()`
//[e2021]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
fn deserialize<T: Default>() -> Option<T> {
Some(T::default())
}
Expand All @@ -45,8 +43,8 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
Err(())
}
fn meow() -> Result<(), ()> {
//[e2021]~^ WARN this function depends on never type fallback being `()`
//[e2021]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
//[e2021]~^ error: this function depends on never type fallback being `()`
//[e2021]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
help::<(), _>(1)?;
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
Ok(())
Expand All @@ -57,8 +55,8 @@ pub fn takes_apit<T>(_y: impl Fn() -> T) -> Result<T, ()> {
}

pub fn fallback_return() -> Result<(), ()> {
//[e2021]~^ WARN this function depends on never type fallback being `()`
//[e2021]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
//[e2021]~^ error: this function depends on never type fallback being `()`
//[e2021]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
takes_apit::<()>(|| Default::default())?;
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
Ok(())
Expand All @@ -71,8 +69,8 @@ fn mk<T>() -> Result<T, ()> {
fn takes_apit2(_x: impl Default) {}

fn fully_apit() -> Result<(), ()> {
//[e2021]~^ WARN this function depends on never type fallback being `()`
//[e2021]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
//[e2021]~^ error: this function depends on never type fallback being `()`
//[e2021]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
takes_apit2(mk::<()>()?);
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
Ok(())
Expand Down
74 changes: 37 additions & 37 deletions tests/ui/editions/never-type-fallback-breaking.e2021.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:18:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:16:1
|
LL | fn m() {
| ^^^^^^
Expand All @@ -8,18 +8,18 @@ LL | fn m() {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:22:17
--> $DIR/never-type-fallback-breaking.rs:20:17
|
LL | true => Default::default(),
| ^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` (part of `#[warn(rust_2024_compatibility)]`) on by default
= note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | let x: () = match true {
| ++++

warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:30:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:28:1
|
LL | fn q() -> Option<()> {
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -28,7 +28,7 @@ LL | fn q() -> Option<()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:37:5
--> $DIR/never-type-fallback-breaking.rs:35:5
|
LL | deserialize()?;
| ^^^^^^^^^^^^^
Expand All @@ -37,8 +37,8 @@ help: use `()` annotations to avoid fallback changes
LL | deserialize::<()>()?;
| ++++++

warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:47:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:45:1
|
LL | fn meow() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -47,7 +47,7 @@ LL | fn meow() -> Result<(), ()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `(): From<!>` will fail
--> $DIR/never-type-fallback-breaking.rs:50:5
--> $DIR/never-type-fallback-breaking.rs:48:5
|
LL | help(1)?;
| ^^^^^^^
Expand All @@ -56,8 +56,8 @@ help: use `()` annotations to avoid fallback changes
LL | help::<(), _>(1)?;
| +++++++++

warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:59:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:57:1
|
LL | pub fn fallback_return() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -66,7 +66,7 @@ LL | pub fn fallback_return() -> Result<(), ()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:62:19
--> $DIR/never-type-fallback-breaking.rs:60:19
|
LL | takes_apit(|| Default::default())?;
| ^^^^^^^^^^^^^^^^^^
Expand All @@ -75,8 +75,8 @@ help: use `()` annotations to avoid fallback changes
LL | takes_apit::<()>(|| Default::default())?;
| ++++++

warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:73:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:71:1
|
LL | fn fully_apit() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -85,7 +85,7 @@ LL | fn fully_apit() -> Result<(), ()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:76:17
--> $DIR/never-type-fallback-breaking.rs:74:17
|
LL | takes_apit2(mk()?);
| ^^^^^
Expand All @@ -94,11 +94,11 @@ help: use `()` annotations to avoid fallback changes
LL | takes_apit2(mk::<()>()?);
| ++++++

warning: 5 warnings emitted
error: aborting due to 5 previous errors

Future incompatibility report: Future breakage diagnostic:
warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:18:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:16:1
|
LL | fn m() {
| ^^^^^^
Expand All @@ -107,19 +107,19 @@ LL | fn m() {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:22:17
--> $DIR/never-type-fallback-breaking.rs:20:17
|
LL | true => Default::default(),
| ^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` (part of `#[warn(rust_2024_compatibility)]`) on by default
= note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | let x: () = match true {
| ++++

Future breakage diagnostic:
warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:30:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:28:1
|
LL | fn q() -> Option<()> {
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -128,19 +128,19 @@ LL | fn q() -> Option<()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:37:5
--> $DIR/never-type-fallback-breaking.rs:35:5
|
LL | deserialize()?;
| ^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` (part of `#[warn(rust_2024_compatibility)]`) on by default
= note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | deserialize::<()>()?;
| ++++++

Future breakage diagnostic:
warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:47:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:45:1
|
LL | fn meow() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -149,19 +149,19 @@ LL | fn meow() -> Result<(), ()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `(): From<!>` will fail
--> $DIR/never-type-fallback-breaking.rs:50:5
--> $DIR/never-type-fallback-breaking.rs:48:5
|
LL | help(1)?;
| ^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` (part of `#[warn(rust_2024_compatibility)]`) on by default
= note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | help::<(), _>(1)?;
| +++++++++

Future breakage diagnostic:
warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:59:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:57:1
|
LL | pub fn fallback_return() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -170,19 +170,19 @@ LL | pub fn fallback_return() -> Result<(), ()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:62:19
--> $DIR/never-type-fallback-breaking.rs:60:19
|
LL | takes_apit(|| Default::default())?;
| ^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` (part of `#[warn(rust_2024_compatibility)]`) on by default
= note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | takes_apit::<()>(|| Default::default())?;
| ++++++

Future breakage diagnostic:
warning: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:73:1
error: this function depends on never type fallback being `()`
--> $DIR/never-type-fallback-breaking.rs:71:1
|
LL | fn fully_apit() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -191,11 +191,11 @@ LL | fn fully_apit() -> Result<(), ()> {
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:76:17
--> $DIR/never-type-fallback-breaking.rs:74:17
|
LL | takes_apit2(mk()?);
| ^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` (part of `#[warn(rust_2024_compatibility)]`) on by default
= note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
help: use `()` annotations to avoid fallback changes
|
LL | takes_apit2(mk::<()>()?);
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/editions/never-type-fallback-breaking.e2024.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `!: Default` is not satisfied
--> $DIR/never-type-fallback-breaking.rs:22:17
--> $DIR/never-type-fallback-breaking.rs:20:17
|
LL | true => Default::default(),
| ^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `!`
Expand All @@ -8,21 +8,21 @@ LL | true => Default::default(),
= help: you might have intended to use the type `()` here instead

error[E0277]: the trait bound `!: Default` is not satisfied
--> $DIR/never-type-fallback-breaking.rs:37:5
--> $DIR/never-type-fallback-breaking.rs:35:5
|
LL | deserialize()?;
| ^^^^^^^^^^^^^ the trait `Default` is not implemented for `!`
|
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information)
= help: you might have intended to use the type `()` here instead
note: required by a bound in `deserialize`
--> $DIR/never-type-fallback-breaking.rs:33:23
--> $DIR/never-type-fallback-breaking.rs:31:23
|
LL | fn deserialize<T: Default>() -> Option<T> {
| ^^^^^^^ required by this bound in `deserialize`

error[E0277]: the trait bound `(): From<!>` is not satisfied
--> $DIR/never-type-fallback-breaking.rs:50:5
--> $DIR/never-type-fallback-breaking.rs:48:5
|
LL | help(1)?;
| ^^^^^^^ the trait `From<!>` is not implemented for `()`
Expand All @@ -39,13 +39,13 @@ LL | help(1)?;
and 4 others
= note: required for `!` to implement `Into<()>`
note: required by a bound in `help`
--> $DIR/never-type-fallback-breaking.rs:44:20
--> $DIR/never-type-fallback-breaking.rs:42:20
|
LL | fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
| ^^^^^^^^ required by this bound in `help`

error[E0277]: the trait bound `!: Default` is not satisfied
--> $DIR/never-type-fallback-breaking.rs:62:19
--> $DIR/never-type-fallback-breaking.rs:60:19
|
LL | takes_apit(|| Default::default())?;
| ^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `!`
Expand All @@ -54,7 +54,7 @@ LL | takes_apit(|| Default::default())?;
= help: you might have intended to use the type `()` here instead

error[E0277]: the trait bound `!: Default` is not satisfied
--> $DIR/never-type-fallback-breaking.rs:76:17
--> $DIR/never-type-fallback-breaking.rs:74:17
|
LL | takes_apit2(mk()?);
| ----------- ^^^^^ the trait `Default` is not implemented for `!`
Expand All @@ -64,7 +64,7 @@ LL | takes_apit2(mk()?);
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information)
= help: you might have intended to use the type `()` here instead
note: required by a bound in `takes_apit2`
--> $DIR/never-type-fallback-breaking.rs:71:25
--> $DIR/never-type-fallback-breaking.rs:69:25
|
LL | fn takes_apit2(_x: impl Default) {}
| ^^^^^^^ required by this bound in `takes_apit2`
Expand Down
Loading
Loading