Skip to content

Commit b3e2981

Browse files
Rollup merge of rust-lang#132978 - WaffleLapkin:very-semantic-change-kind, r=compiler-errors
Mention both release *and* edition breakage for never type lints This PR makes ~~two changes~~ a change to the never type lints (`dependency_on_unit_never_type_fallback` and `never_type_fallback_flowing_into_unsafe`): 1. Change the wording of the note to mention that the breaking change will be made in an edition _and_ in a future release 2. ~~Make these warnings be reported in deps (hopefully the lints are matured enough)~~ r? ``@compiler-errors`` cc ``@ehuss`` closes rust-lang#132930
2 parents 325bc6c + 673bb5e commit b3e2981

25 files changed

+120
-114
lines changed

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,7 @@ declare_lint! {
41854185
Warn,
41864186
"never type fallback affecting unsafe function calls",
41874187
@future_incompatible = FutureIncompatibleInfo {
4188-
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
4188+
reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
41894189
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
41904190
};
41914191
@edition Edition2024 => Deny;
@@ -4239,7 +4239,7 @@ declare_lint! {
42394239
Warn,
42404240
"never type fallback affecting unsafe function calls",
42414241
@future_incompatible = FutureIncompatibleInfo {
4242-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
4242+
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
42434243
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
42444244
};
42454245
report_in_external_macro

Diff for: compiler/rustc_lint_defs/src/lib.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ pub enum FutureIncompatibilityReason {
381381
/// hard errors (and the lint removed). Preferably when there is some
382382
/// confidence that the number of impacted projects is very small (few
383383
/// should have a broken dependency in their dependency tree).
384+
///
385+
/// [`EditionAndFutureReleaseError`]: FutureIncompatibilityReason::EditionAndFutureReleaseError
384386
FutureReleaseErrorReportInDeps,
385387
/// Code that changes meaning in some way in a
386388
/// future release.
@@ -419,6 +421,28 @@ pub enum FutureIncompatibilityReason {
419421
/// slightly changes the text of the diagnostic, but is otherwise the
420422
/// same.
421423
EditionSemanticsChange(Edition),
424+
/// This will be an error in the provided edition *and* in a future
425+
/// release.
426+
///
427+
/// This variant a combination of [`FutureReleaseErrorDontReportInDeps`]
428+
/// and [`EditionError`]. This is useful in rare cases when we
429+
/// want to have "preview" of a breaking change in an edition, but do a
430+
/// breaking change later on all editions anyway.
431+
///
432+
/// [`EditionError`]: FutureIncompatibilityReason::EditionError
433+
/// [`FutureReleaseErrorDontReportInDeps`]: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
434+
EditionAndFutureReleaseError(Edition),
435+
/// This will change meaning in the provided edition *and* in a future
436+
/// release.
437+
///
438+
/// This variant a combination of [`FutureReleaseSemanticsChange`]
439+
/// and [`EditionSemanticsChange`]. This is useful in rare cases when we
440+
/// want to have "preview" of a breaking change in an edition, but do a
441+
/// breaking change later on all editions anyway.
442+
///
443+
/// [`EditionSemanticsChange`]: FutureIncompatibilityReason::EditionSemanticsChange
444+
/// [`FutureReleaseSemanticsChange`]: FutureIncompatibilityReason::FutureReleaseSemanticsChange
445+
EditionAndFutureReleaseSemanticsChange(Edition),
422446
/// A custom reason.
423447
///
424448
/// Choose this variant if the built-in text of the diagnostic of the
@@ -431,9 +455,15 @@ pub enum FutureIncompatibilityReason {
431455
impl FutureIncompatibilityReason {
432456
pub fn edition(self) -> Option<Edition> {
433457
match self {
434-
Self::EditionError(e) => Some(e),
435-
Self::EditionSemanticsChange(e) => Some(e),
436-
_ => None,
458+
Self::EditionError(e)
459+
| Self::EditionSemanticsChange(e)
460+
| Self::EditionAndFutureReleaseError(e)
461+
| Self::EditionAndFutureReleaseSemanticsChange(e) => Some(e),
462+
463+
FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
464+
| FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
465+
| FutureIncompatibilityReason::FutureReleaseSemanticsChange
466+
| FutureIncompatibilityReason::Custom(_) => None,
437467
}
438468
}
439469
}

Diff for: compiler/rustc_middle/src/lint.rs

+11
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ pub fn lint_level(
382382
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
383383
format!("this changes meaning in Rust {edition}")
384384
}
385+
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
386+
format!(
387+
"this was previously accepted by the compiler but is being phased out; \
388+
it will become a hard error in Rust {edition} and in a future release in all editions!"
389+
)
390+
}
391+
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(edition) => {
392+
format!(
393+
"this changes meaning in Rust {edition} and in a future release in all editions!"
394+
)
395+
}
385396
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
386397
};
387398

Diff for: tests/ui/delegation/unsupported.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ mod opaque {
1010
mod to_reuse {
1111
use super::Trait;
1212

13-
pub fn opaque_ret() -> impl Trait { unimplemented!() }
14-
//~^ warn: this function depends on never type fallback being `()`
15-
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13+
pub fn opaque_ret() -> impl Trait { () }
1614
}
1715

1816
trait ToReuse {
19-
fn opaque_ret() -> impl Trait { unimplemented!() }
20-
//~^ warn: this function depends on never type fallback being `()`
21-
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
17+
fn opaque_ret() -> impl Trait { () }
2218
}
2319

2420
// FIXME: Inherited `impl Trait`s create query cycles when used inside trait impls.

Diff for: tests/ui/delegation/unsupported.stderr

+15-46
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,43 @@
1-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>::{synthetic#0}`
2-
--> $DIR/unsupported.rs:26:25
1+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`
2+
--> $DIR/unsupported.rs:22:25
33
|
44
LL | reuse to_reuse::opaque_ret;
55
| ^^^^^^^^^^
66
|
77
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
8-
--> $DIR/unsupported.rs:26:25
8+
--> $DIR/unsupported.rs:22:25
99
|
1010
LL | reuse to_reuse::opaque_ret;
1111
| ^^^^^^^^^^
12-
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>::{synthetic#0}`, completing the cycle
13-
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>` is well-formed
14-
--> $DIR/unsupported.rs:25:5
12+
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`, completing the cycle
13+
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>` is well-formed
14+
--> $DIR/unsupported.rs:21:5
1515
|
1616
LL | impl ToReuse for u8 {
1717
| ^^^^^^^^^^^^^^^^^^^
1818
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1919

20-
warning: this function depends on never type fallback being `()`
21-
--> $DIR/unsupported.rs:13:9
22-
|
23-
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
|
26-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
28-
= help: specify the types explicitly
29-
note: in edition 2024, the requirement `!: opaque::Trait` will fail
30-
--> $DIR/unsupported.rs:13:32
31-
|
32-
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
33-
| ^^^^^^^^^^
34-
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
35-
36-
warning: this function depends on never type fallback being `()`
37-
--> $DIR/unsupported.rs:19:9
38-
|
39-
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
40-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41-
|
42-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
43-
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
44-
= help: specify the types explicitly
45-
note: in edition 2024, the requirement `!: opaque::Trait` will fail
46-
--> $DIR/unsupported.rs:19:28
47-
|
48-
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
49-
| ^^^^^^^^^^
50-
51-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>::{synthetic#0}`
52-
--> $DIR/unsupported.rs:29:24
20+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`
21+
--> $DIR/unsupported.rs:25:24
5322
|
5423
LL | reuse ToReuse::opaque_ret;
5524
| ^^^^^^^^^^
5625
|
5726
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
58-
--> $DIR/unsupported.rs:29:24
27+
--> $DIR/unsupported.rs:25:24
5928
|
6029
LL | reuse ToReuse::opaque_ret;
6130
| ^^^^^^^^^^
62-
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>::{synthetic#0}`, completing the cycle
63-
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>` is well-formed
64-
--> $DIR/unsupported.rs:28:5
31+
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`, completing the cycle
32+
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>` is well-formed
33+
--> $DIR/unsupported.rs:24:5
6534
|
6635
LL | impl ToReuse for u16 {
6736
| ^^^^^^^^^^^^^^^^^^^^
6837
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
6938

7039
error: recursive delegation is not supported yet
71-
--> $DIR/unsupported.rs:42:22
40+
--> $DIR/unsupported.rs:38:22
7241
|
7342
LL | pub reuse to_reuse2::foo;
7443
| --- callee defined here
@@ -77,14 +46,14 @@ LL | reuse to_reuse1::foo;
7746
| ^^^
7847

7948
error[E0283]: type annotations needed
80-
--> $DIR/unsupported.rs:52:18
49+
--> $DIR/unsupported.rs:48:18
8150
|
8251
LL | reuse Trait::foo;
8352
| ^^^ cannot infer type
8453
|
8554
= note: cannot satisfy `_: effects::Trait`
8655

87-
error: aborting due to 4 previous errors; 2 warnings emitted
56+
error: aborting due to 4 previous errors
8857

8958
Some errors have detailed explanations: E0283, E0391.
9059
For more information about an error, try `rustc --explain E0283`.

Diff for: tests/ui/editions/never-type-fallback-breaking.e2021.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616

1717
fn m() {
1818
//[e2021]~^ this function depends on never type fallback being `()`
19-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19+
//[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!
2020
let x: () = match true {
2121
true => Default::default(),
2222
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
@@ -28,7 +28,7 @@ fn m() {
2828

2929
fn q() -> Option<()> {
3030
//[e2021]~^ this function depends on never type fallback being `()`
31-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
//[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!
3232
fn deserialize<T: Default>() -> Option<T> {
3333
Some(T::default())
3434
}
@@ -45,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
4545
}
4646
fn meow() -> Result<(), ()> {
4747
//[e2021]~^ this function depends on never type fallback being `()`
48-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
48+
//[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!
4949
help::<(), _>(1)?;
5050
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
5151
Ok(())

Diff for: tests/ui/editions/never-type-fallback-breaking.e2021.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
44
LL | fn m() {
55
| ^^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7+
= 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!
88
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
99
= help: specify the types explicitly
1010
note: in edition 2024, the requirement `!: Default` will fail
@@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
2424
LL | fn q() -> Option<()> {
2525
| ^^^^^^^^^^^^^^^^^^^^
2626
|
27-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= 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!
2828
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
2929
= help: specify the types explicitly
3030
note: in edition 2024, the requirement `!: Default` will fail
@@ -43,7 +43,7 @@ warning: this function depends on never type fallback being `()`
4343
LL | fn meow() -> Result<(), ()> {
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
4545
|
46-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
46+
= 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!
4747
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
4848
= help: specify the types explicitly
4949
note: in edition 2024, the requirement `(): From<!>` will fail

Diff for: tests/ui/editions/never-type-fallback-breaking.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616

1717
fn m() {
1818
//[e2021]~^ this function depends on never type fallback being `()`
19-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19+
//[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!
2020
let x = match true {
2121
true => Default::default(),
2222
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
@@ -28,7 +28,7 @@ fn m() {
2828

2929
fn q() -> Option<()> {
3030
//[e2021]~^ this function depends on never type fallback being `()`
31-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
//[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!
3232
fn deserialize<T: Default>() -> Option<T> {
3333
Some(T::default())
3434
}
@@ -45,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
4545
}
4646
fn meow() -> Result<(), ()> {
4747
//[e2021]~^ this function depends on never type fallback being `()`
48-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
48+
//[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!
4949
help(1)?;
5050
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
5151
Ok(())

Diff for: tests/ui/never_type/defaulted-never-note.nofallback.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
44
LL | fn smeg() {
55
| ^^^^^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7+
= 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!
88
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
99
= help: specify the types explicitly
1010
note: in edition 2024, the requirement `!: ImplementedForUnitButNotNever` will fail

Diff for: tests/ui/never_type/defaulted-never-note.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
2727
//[fallback]~| NOTE required by a bound in `foo`
2828
fn smeg() {
2929
//[nofallback]~^ warn: this function depends on never type fallback being `()`
30-
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30+
//[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!
3131
let _x = return;
3232
foo(_x);
3333
//[fallback]~^ ERROR the trait bound

Diff for: tests/ui/never_type/dependency-on-fallback-to-unit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77

88
fn def() {
99
//~^ warn: this function depends on never type fallback being `()`
10-
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
10+
//~| 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!
1111
match true {
1212
false => <_>::default(),
1313
true => return,
@@ -18,7 +18,7 @@ fn def() {
1818
// <https://github.com/rust-lang/rust/issues/39216>
1919
fn question_mark() -> Result<(), ()> {
2020
//~^ warn: this function depends on never type fallback being `()`
21-
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
21+
//~| 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!
2222
deserialize()?;
2323
Ok(())
2424
}

Diff for: tests/ui/never_type/dependency-on-fallback-to-unit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
44
LL | fn def() {
55
| ^^^^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7+
= 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!
88
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
99
= help: specify the types explicitly
1010
note: in edition 2024, the requirement `!: Default` will fail
@@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
2424
LL | fn question_mark() -> Result<(), ()> {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
|
27-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= 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!
2828
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
2929
= help: specify the types explicitly
3030
note: in edition 2024, the requirement `!: Default` will fail

0 commit comments

Comments
 (0)