Skip to content

Commit 8cb3d5d

Browse files
committed
Mention both release *and* edition breackage for never type lints
+ Make them into lints which are reported in deps.
1 parent db07404 commit 8cb3d5d

23 files changed

+648
-64
lines changed

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::EditionAndFutureReleaseError(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

compiler/rustc_lint_defs/src/lib.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,9 @@ pub enum FutureIncompatibilityReason {
366366
/// This will be an error in a future release, and
367367
/// Cargo should create a report even for dependencies
368368
///
369-
/// This is the *only* reason that will make future incompatibility warnings show up in cargo's
370-
/// reports. All other future incompatibility warnings are not visible when they occur in a
369+
/// This and [`FutureReleaseError`] are the *only* reasons that will make
370+
/// future incompatibility warnings show up in cargo's reports. All other
371+
/// future incompatibility warnings are not visible when they occur in a
371372
/// dependency.
372373
///
373374
/// Choose this variant after the lint has been sitting in the
@@ -419,6 +420,17 @@ pub enum FutureIncompatibilityReason {
419420
/// slightly changes the text of the diagnostic, but is otherwise the
420421
/// same.
421422
EditionSemanticsChange(Edition),
423+
/// This will be an error in the provided edition *and* in a future
424+
/// release.
425+
///
426+
/// This variant a combination of [`FutureReleaseErrorReportInDeps`]
427+
/// and [`EditionError`]. This is useful in rare cases when we
428+
/// want to have "preview" of a breaking change in an edition, but do a
429+
/// breaking change later on all editions anyway.
430+
///
431+
/// [`EditionError`]: FutureIncompatibilityReason::EditionError
432+
/// [`FutureReleaseErrorReportInDeps`]: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
433+
EditionAndFutureReleaseError(Edition),
422434
/// A custom reason.
423435
///
424436
/// Choose this variant if the built-in text of the diagnostic of the
@@ -431,9 +443,14 @@ pub enum FutureIncompatibilityReason {
431443
impl FutureIncompatibilityReason {
432444
pub fn edition(self) -> Option<Edition> {
433445
match self {
434-
Self::EditionError(e) => Some(e),
435-
Self::EditionSemanticsChange(e) => Some(e),
436-
_ => None,
446+
Self::EditionError(e)
447+
| Self::EditionSemanticsChange(e)
448+
| Self::EditionAndFutureReleaseError(e) => Some(e),
449+
450+
FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
451+
| FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
452+
| FutureIncompatibilityReason::FutureReleaseSemanticsChange
453+
| FutureIncompatibilityReason::Custom(_) => None,
437454
}
438455
}
439456
}

compiler/rustc_middle/src/lint.rs

+7
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ pub fn lint_level(
294294
matches!(
295295
incompat.reason,
296296
FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
297+
| FutureIncompatibilityReason::EditionAndFutureReleaseError(_)
297298
)
298299
},
299300
);
@@ -382,6 +383,12 @@ pub fn lint_level(
382383
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
383384
format!("this changes meaning in Rust {edition}")
384385
}
386+
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
387+
format!(
388+
"this was previously accepted by the compiler but is being phased out; \
389+
it will become a hard error in Rust {edition} and in a future release in all editions!"
390+
)
391+
}
385392
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
386393
};
387394

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(())

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

+66-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
@@ -58,3 +58,66 @@ LL | help::<(), _>(1)?;
5858

5959
warning: 3 warnings emitted
6060

61+
Future incompatibility report: Future breakage diagnostic:
62+
warning: this function depends on never type fallback being `()`
63+
--> $DIR/never-type-fallback-breaking.rs:17:1
64+
|
65+
LL | fn m() {
66+
| ^^^^^^
67+
|
68+
= 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!
69+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
70+
= help: specify the types explicitly
71+
note: in edition 2024, the requirement `!: Default` will fail
72+
--> $DIR/never-type-fallback-breaking.rs:21:17
73+
|
74+
LL | true => Default::default(),
75+
| ^^^^^^^^^^^^^^^^^^
76+
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
77+
help: use `()` annotations to avoid fallback changes
78+
|
79+
LL | let x: () = match true {
80+
| ++++
81+
82+
Future breakage diagnostic:
83+
warning: this function depends on never type fallback being `()`
84+
--> $DIR/never-type-fallback-breaking.rs:29:1
85+
|
86+
LL | fn q() -> Option<()> {
87+
| ^^^^^^^^^^^^^^^^^^^^
88+
|
89+
= 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!
90+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
91+
= help: specify the types explicitly
92+
note: in edition 2024, the requirement `!: Default` will fail
93+
--> $DIR/never-type-fallback-breaking.rs:36:5
94+
|
95+
LL | deserialize()?;
96+
| ^^^^^^^^^^^^^
97+
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
98+
help: use `()` annotations to avoid fallback changes
99+
|
100+
LL | deserialize::<()>()?;
101+
| ++++++
102+
103+
Future breakage diagnostic:
104+
warning: this function depends on never type fallback being `()`
105+
--> $DIR/never-type-fallback-breaking.rs:46:1
106+
|
107+
LL | fn meow() -> Result<(), ()> {
108+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
109+
|
110+
= 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!
111+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
112+
= help: specify the types explicitly
113+
note: in edition 2024, the requirement `(): From<!>` will fail
114+
--> $DIR/never-type-fallback-breaking.rs:49:5
115+
|
116+
LL | help(1)?;
117+
| ^^^^^^^
118+
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
119+
help: use `()` annotations to avoid fallback changes
120+
|
121+
LL | help::<(), _>(1)?;
122+
| +++++++++
123+

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(())

tests/ui/never_type/defaulted-never-note.nofallback.stderr

+22-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
@@ -20,3 +20,24 @@ LL | let _x: () = return;
2020

2121
warning: 1 warning emitted
2222

23+
Future incompatibility report: Future breakage diagnostic:
24+
warning: this function depends on never type fallback being `()`
25+
--> $DIR/defaulted-never-note.rs:28:1
26+
|
27+
LL | fn smeg() {
28+
| ^^^^^^^^^
29+
|
30+
= 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!
31+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
32+
= help: specify the types explicitly
33+
note: in edition 2024, the requirement `!: ImplementedForUnitButNotNever` will fail
34+
--> $DIR/defaulted-never-note.rs:32:9
35+
|
36+
LL | foo(_x);
37+
| ^^
38+
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
39+
help: use `()` annotations to avoid fallback changes
40+
|
41+
LL | let _x: () = return;
42+
| ++++
43+

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

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
}

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

+44-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
@@ -39,3 +39,45 @@ LL | deserialize::<()>()?;
3939

4040
warning: 2 warnings emitted
4141

42+
Future incompatibility report: Future breakage diagnostic:
43+
warning: this function depends on never type fallback being `()`
44+
--> $DIR/dependency-on-fallback-to-unit.rs:8:1
45+
|
46+
LL | fn def() {
47+
| ^^^^^^^^
48+
|
49+
= 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!
50+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
51+
= help: specify the types explicitly
52+
note: in edition 2024, the requirement `!: Default` will fail
53+
--> $DIR/dependency-on-fallback-to-unit.rs:12:19
54+
|
55+
LL | false => <_>::default(),
56+
| ^
57+
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
58+
help: use `()` annotations to avoid fallback changes
59+
|
60+
LL | false => <()>::default(),
61+
| ~~
62+
63+
Future breakage diagnostic:
64+
warning: this function depends on never type fallback being `()`
65+
--> $DIR/dependency-on-fallback-to-unit.rs:19:1
66+
|
67+
LL | fn question_mark() -> Result<(), ()> {
68+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69+
|
70+
= 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!
71+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
72+
= help: specify the types explicitly
73+
note: in edition 2024, the requirement `!: Default` will fail
74+
--> $DIR/dependency-on-fallback-to-unit.rs:22:5
75+
|
76+
LL | deserialize()?;
77+
| ^^^^^^^^^^^^^
78+
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
79+
help: use `()` annotations to avoid fallback changes
80+
|
81+
LL | deserialize::<()>()?;
82+
| ++++++
83+

0 commit comments

Comments
 (0)