Skip to content

Commit 5dec6b3

Browse files
committed
refactor test for note on !: Tr error
1 parent 98430c4 commit 5dec6b3

File tree

5 files changed

+131
-72
lines changed

5 files changed

+131
-72
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Future incompatibility report: Future breakage diagnostic:
2+
warning: this function depends on never type fallback being `()`
3+
--> $DIR/defaulted-never-note.rs:38:1
4+
|
5+
LL | fn main() {
6+
| ^^^^^^^^^
7+
|
8+
= help: specify the types explicitly
9+
note: in edition 2024, the requirement `!: OnlyUnit` will fail
10+
--> $DIR/defaulted-never-note.rs:40:19
11+
|
12+
LL | requires_unit(x);
13+
| ^
14+
help: use `()` annotations to avoid fallback changes
15+
|
16+
LL | let x: () = return;
17+
| ++++
18+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error[E0277]: the trait bound `!: OnlyUnit` is not satisfied
2+
--> $DIR/defaulted-never-note.rs:40:19
3+
|
4+
LL | requires_unit(x);
5+
| ------------- ^ the trait `OnlyUnit` is not implemented for `!`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
help: the trait `OnlyUnit` is implemented for `()`
10+
--> $DIR/defaulted-never-note.rs:13:1
11+
|
12+
LL | impl OnlyUnit for () {}
13+
| ^^^^^^^^^^^^^^^^^^^^
14+
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15+
= help: you might have intended to use the type `()` here instead
16+
note: required by a bound in `requires_unit`
17+
--> $DIR/defaulted-never-note.rs:16:26
18+
|
19+
LL | fn requires_unit(_: impl OnlyUnit) {}
20+
| ^^^^^^^^ required by this bound in `requires_unit`
21+
22+
error[E0277]: the trait bound `!: OnlyU32` is not satisfied
23+
--> $DIR/defaulted-never-note.rs:48:18
24+
|
25+
LL | requires_u32(x);
26+
| ------------ ^ the trait `OnlyU32` is not implemented for `!`
27+
| |
28+
| required by a bound introduced by this call
29+
|
30+
help: the trait `OnlyU32` is implemented for `u32`
31+
--> $DIR/defaulted-never-note.rs:23:1
32+
|
33+
LL | impl OnlyU32 for u32 {}
34+
| ^^^^^^^^^^^^^^^^^^^^
35+
note: required by a bound in `requires_u32`
36+
--> $DIR/defaulted-never-note.rs:26:25
37+
|
38+
LL | fn requires_u32(_: impl OnlyU32) {}
39+
| ^^^^^^^ required by this bound in `requires_u32`
40+
41+
error[E0277]: the trait bound `!: Nothing` is not satisfied
42+
--> $DIR/defaulted-never-note.rs:54:22
43+
|
44+
LL | requires_nothing(x);
45+
| ---------------- ^ the trait `Nothing` is not implemented for `!`
46+
| |
47+
| required by a bound introduced by this call
48+
|
49+
help: this trait has no implementations, consider adding one
50+
--> $DIR/defaulted-never-note.rs:31:1
51+
|
52+
LL | trait Nothing {}
53+
| ^^^^^^^^^^^^^
54+
note: required by a bound in `requires_nothing`
55+
--> $DIR/defaulted-never-note.rs:34:29
56+
|
57+
LL | fn requires_nothing(_: impl Nothing) {}
58+
| ^^^^^^^ required by this bound in `requires_nothing`
59+
60+
error: aborting due to 3 previous errors
61+
62+
For more information about this error, try `rustc --explain E0277`.

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

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,58 @@
1-
//@ revisions: nofallback fallback
2-
//@[fallback] edition: 2024
3-
//@[nofallback] run-pass
4-
//@[fallback] check-fail
5-
1+
// Test diagnostic for the case where a trait is not implemented for `!`. If it is implemented
2+
// for `()`, we want to add a note saying that this might be caused by a breaking change in the
3+
// compiler.
4+
//
5+
//@ revisions: e2021 e2024
6+
//@[e2021] edition: 2021
7+
//@[e2024] edition: 2024
8+
//@[e2021] run-pass
69
#![expect(dependency_on_unit_never_type_fallback, unused)]
710

8-
trait Deserialize: Sized {
9-
fn deserialize() -> Result<Self, String>;
10-
}
11+
trait OnlyUnit {}
1112

12-
impl Deserialize for () {
13-
fn deserialize() -> Result<(), String> {
14-
Ok(())
15-
}
16-
}
13+
impl OnlyUnit for () {}
14+
//[e2024]~^ help: trait `OnlyUnit` is implemented for `()`
1715

18-
trait ImplementedForUnitButNotNever {}
19-
20-
impl ImplementedForUnitButNotNever for () {} //[fallback]~ HELP trait `ImplementedForUnitButNotNever` is implemented for `()`
21-
22-
fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
23-
//[fallback]~^ note: required by this bound in `foo`
24-
//[fallback]~| note: required by a bound in `foo`
25-
fn smeg() {
26-
let _x = return;
27-
foo(_x);
28-
//[fallback]~^ ERROR the trait bound
29-
//[fallback]~| NOTE the trait `ImplementedForUnitButNotNever` is not implemented
30-
//[fallback]~| NOTE this error might have been caused
31-
//[fallback]~| NOTE required by a bound introduced by this call
32-
//[fallback]~| HELP you might have intended to use the type `()`
33-
}
16+
fn requires_unit(_: impl OnlyUnit) {}
17+
//[e2024]~^ note: required by this bound in `requires_unit`
18+
//[e2024]~| note: required by a bound in `requires_unit`
19+
20+
21+
trait OnlyU32 {}
22+
23+
impl OnlyU32 for u32 {}
24+
//[e2024]~^ help: the trait `OnlyU32` is implemented for `u32`
25+
26+
fn requires_u32(_: impl OnlyU32) {}
27+
//[e2024]~^ note: required by this bound in `requires_u32`
28+
//[e2024]~| note: required by a bound in `requires_u32`
29+
30+
31+
trait Nothing {}
32+
//[e2024]~^ help: this trait has no implementations, consider adding one
33+
34+
fn requires_nothing(_: impl Nothing) {}
35+
//[e2024]~^ note: required by this bound in `requires_nothing`
36+
//[e2024]~| note: required by a bound in `requires_nothing`
3437

3538
fn main() {
36-
smeg();
39+
let x = return;
40+
requires_unit(x);
41+
//[e2024]~^ error: the trait bound `!: OnlyUnit` is not satisfied
42+
//[e2024]~| note: the trait `OnlyUnit` is not implemented for `!`
43+
//[e2024]~| note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
44+
//[e2024]~| note: required by a bound introduced by this call
45+
//[e2024]~| help: you might have intended to use the type `()`
46+
47+
#[cfg(e2024)]
48+
requires_u32(x);
49+
//[e2024]~^ error: the trait bound `!: OnlyU32` is not satisfied
50+
//[e2024]~| note: the trait `OnlyU32` is not implemented for `!`
51+
//[e2024]~| note: required by a bound introduced by this call
52+
53+
#[cfg(e2024)]
54+
requires_nothing(x);
55+
//[e2024]~^ error: the trait bound `!: Nothing` is not satisfied
56+
//[e2024]~| note: the trait `Nothing` is not implemented for `!`
57+
//[e2024]~| note: required by a bound introduced by this call
3758
}

0 commit comments

Comments
 (0)