Skip to content

Commit

Permalink
Mention both release *and* edition breakage for never type lints
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Nov 14, 2024
1 parent db07404 commit 46967bd
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 62 deletions.
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 @@ -4185,7 +4185,7 @@ declare_lint! {
Warn,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
};
@edition Edition2024 => Deny;
Expand Down Expand Up @@ -4239,7 +4239,7 @@ declare_lint! {
Warn,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
};
report_in_external_macro
Expand Down
24 changes: 21 additions & 3 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ pub enum FutureIncompatibilityReason {
/// hard errors (and the lint removed). Preferably when there is some
/// confidence that the number of impacted projects is very small (few
/// should have a broken dependency in their dependency tree).
///
/// [`EditionAndFutureReleaseError`]: FutureIncompatibilityReason::EditionAndFutureReleaseError
FutureReleaseErrorReportInDeps,
/// Code that changes meaning in some way in a
/// future release.
Expand Down Expand Up @@ -419,6 +421,17 @@ pub enum FutureIncompatibilityReason {
/// slightly changes the text of the diagnostic, but is otherwise the
/// same.
EditionSemanticsChange(Edition),
/// This will be an error in the provided edition *and* in a future
/// release.
///
/// This variant a combination of [`FutureReleaseErrorDontReportInDeps`]
/// and [`EditionError`]. This is useful in rare cases when we
/// want to have "preview" of a breaking change in an edition, but do a
/// breaking change later on all editions anyway.
///
/// [`EditionError`]: FutureIncompatibilityReason::EditionError
/// [`FutureReleaseErrorDontReportInDeps`]: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
EditionAndFutureReleaseError(Edition),
/// A custom reason.
///
/// Choose this variant if the built-in text of the diagnostic of the
Expand All @@ -431,9 +444,14 @@ pub enum FutureIncompatibilityReason {
impl FutureIncompatibilityReason {
pub fn edition(self) -> Option<Edition> {
match self {
Self::EditionError(e) => Some(e),
Self::EditionSemanticsChange(e) => Some(e),
_ => None,
Self::EditionError(e)
| Self::EditionSemanticsChange(e)
| Self::EditionAndFutureReleaseError(e) => Some(e),

FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
| FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
| FutureIncompatibilityReason::FutureReleaseSemanticsChange
| FutureIncompatibilityReason::Custom(_) => None,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ pub fn lint_level(
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
format!("this changes meaning in Rust {edition}")
}
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
format!(
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error in Rust {edition} and in a future release in all editions!"
)
}
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
};

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/editions/never-type-fallback-breaking.e2021.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {

fn m() {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| 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,7 +28,7 @@ fn m() {

fn q() -> Option<()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| 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,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
}
fn meow() -> Result<(), ()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| 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 Down
6 changes: 3 additions & 3 deletions tests/ui/editions/never-type-fallback-breaking.e2021.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn m() {
| ^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
Expand All @@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
LL | fn q() -> Option<()> {
| ^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
Expand All @@ -43,7 +43,7 @@ warning: this function depends on never type fallback being `()`
LL | fn meow() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `(): From<!>` will fail
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/editions/never-type-fallback-breaking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {

fn m() {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| 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,7 +28,7 @@ fn m() {

fn q() -> Option<()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| 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,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
}
fn meow() -> Result<(), ()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| 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 Down
2 changes: 1 addition & 1 deletion tests/ui/never_type/defaulted-never-note.nofallback.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn smeg() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: ImplementedForUnitButNotNever` will fail
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/never_type/defaulted-never-note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
//[fallback]~| NOTE required by a bound in `foo`
fn smeg() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| 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 = return;
foo(_x);
//[fallback]~^ ERROR the trait bound
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/never_type/dependency-on-fallback-to-unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {

fn def() {
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| 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!
match true {
false => <_>::default(),
true => return,
Expand All @@ -18,7 +18,7 @@ fn def() {
// <https://github.com/rust-lang/rust/issues/39216>
fn question_mark() -> Result<(), ()> {
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| 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!
deserialize()?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/never_type/dependency-on-fallback-to-unit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn def() {
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
Expand All @@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
LL | fn question_mark() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn assignment() {
| ^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitDefault` will fail
Expand All @@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
LL | fn assignment_rev() {
| ^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitDefault` will fail
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/never_type/diverging-fallback-control-flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl UnitDefault for () {

fn assignment() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| 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;

if true {
Expand All @@ -41,7 +41,7 @@ fn assignment() {

fn assignment_rev() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| 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;

if true {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn main() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Test` will fail
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/never_type/diverging-fallback-no-leak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn unconstrained_arg<T: Test>(_: T) {}

fn main() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| 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!

// Here the type variable falls back to `!`,
// and hence we get a type error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn main() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitReturn` will fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn unconstrained_return<T: UnitReturn>() -> T {

fn main() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| 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!

// In Ye Olde Days, the `T` parameter of `unconstrained_return`
// winds up "entangled" with the `!` type that results from
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/never_type/fallback-closure-ret.nofallback.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn main() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Bar` will fail
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/never_type/fallback-closure-ret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ fn foo<R: Bar>(_: impl Fn() -> R) {}

fn main() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| 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!
foo(|| panic!());
}
2 changes: 1 addition & 1 deletion tests/ui/never_type/impl_trait_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ impl T for () {}

fn should_ret_unit() -> impl T {
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| 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!
panic!()
}
2 changes: 1 addition & 1 deletion tests/ui/never_type/impl_trait_fallback.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn should_ret_unit() -> impl T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: 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!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: T` will fail
Expand Down
Loading

0 comments on commit 46967bd

Please sign in to comment.