Skip to content

Commit 23d10cd

Browse files
Make sure that we suggest turbofishing the right type arg
1 parent 81eef2d commit 23d10cd

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,11 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
621621
.iter()
622622
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
623623
.count();
624-
for (idx, arg) in args.iter().enumerate() {
624+
for (idx, arg) in args
625+
.iter()
626+
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
627+
.enumerate()
628+
{
625629
if let Some(ty) = arg.as_type()
626630
&& let Some(vid) = self.fcx.root_vid(ty)
627631
&& self.reachable_vids.contains(&vid)

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: this function depends on never type fallback being `()`
2-
--> $DIR/never-type-fallback-breaking.rs:15:1
2+
--> $DIR/never-type-fallback-breaking.rs:16:1
33
|
44
LL | fn m() {
55
| ^^^^^^
@@ -8,7 +8,7 @@ LL | fn m() {
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
11-
--> $DIR/never-type-fallback-breaking.rs:19:17
11+
--> $DIR/never-type-fallback-breaking.rs:20:17
1212
|
1313
LL | true => Default::default(),
1414
| ^^^^^^^^^^^^^^^^^^
@@ -19,7 +19,7 @@ LL | let x: () = match true {
1919
| ++++
2020

2121
warning: this function depends on never type fallback being `()`
22-
--> $DIR/never-type-fallback-breaking.rs:27:1
22+
--> $DIR/never-type-fallback-breaking.rs:28:1
2323
|
2424
LL | fn q() -> Option<()> {
2525
| ^^^^^^^^^^^^^^^^^^^^
@@ -28,7 +28,7 @@ LL | fn q() -> Option<()> {
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
31-
--> $DIR/never-type-fallback-breaking.rs:34:5
31+
--> $DIR/never-type-fallback-breaking.rs:35:5
3232
|
3333
LL | deserialize()?;
3434
| ^^^^^^^^^^^^^
@@ -37,5 +37,24 @@ help: use `()` annotations to avoid fallback changes
3737
LL | deserialize::<()>()?;
3838
| ++++++
3939

40-
warning: 2 warnings emitted
40+
warning: this function depends on never type fallback being `()`
41+
--> $DIR/never-type-fallback-breaking.rs:45:1
42+
|
43+
LL | fn meow() -> Result<(), ()> {
44+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
|
46+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
47+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
48+
= help: specify the types explicitly
49+
note: in edition 2024, the requirement `(): From<!>` will fail
50+
--> $DIR/never-type-fallback-breaking.rs:48:5
51+
|
52+
LL | help(1)?;
53+
| ^^^^^^^
54+
help: use `()` annotations to avoid fallback changes
55+
|
56+
LL | help::<(), _>(1)?;
57+
| +++++++++
58+
59+
warning: 3 warnings emitted
4160

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `!: Default` is not satisfied
2-
--> $DIR/never-type-fallback-breaking.rs:19:17
2+
--> $DIR/never-type-fallback-breaking.rs:20:17
33
|
44
LL | true => Default::default(),
55
| ^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `!`
@@ -8,19 +8,42 @@ LL | true => Default::default(),
88
= help: did you intend to use the type `()` here instead?
99

1010
error[E0277]: the trait bound `!: Default` is not satisfied
11-
--> $DIR/never-type-fallback-breaking.rs:34:5
11+
--> $DIR/never-type-fallback-breaking.rs:35:5
1212
|
1313
LL | deserialize()?;
1414
| ^^^^^^^^^^^^^ the trait `Default` is not implemented for `!`
1515
|
1616
= 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)
1717
= help: did you intend to use the type `()` here instead?
1818
note: required by a bound in `deserialize`
19-
--> $DIR/never-type-fallback-breaking.rs:30:23
19+
--> $DIR/never-type-fallback-breaking.rs:31:23
2020
|
2121
LL | fn deserialize<T: Default>() -> Option<T> {
2222
| ^^^^^^^ required by this bound in `deserialize`
2323

24-
error: aborting due to 2 previous errors
24+
error[E0277]: the trait bound `(): From<!>` is not satisfied
25+
--> $DIR/never-type-fallback-breaking.rs:48:5
26+
|
27+
LL | help(1)?;
28+
| ^^^^^^^ the trait `From<!>` is not implemented for `()`
29+
|
30+
= help: the following other types implement trait `From<T>`:
31+
`(T, T)` implements `From<[T; 2]>`
32+
`(T, T, T)` implements `From<[T; 3]>`
33+
`(T, T, T, T)` implements `From<[T; 4]>`
34+
`(T, T, T, T, T)` implements `From<[T; 5]>`
35+
`(T, T, T, T, T, T)` implements `From<[T; 6]>`
36+
`(T, T, T, T, T, T, T)` implements `From<[T; 7]>`
37+
`(T, T, T, T, T, T, T, T)` implements `From<[T; 8]>`
38+
`(T, T, T, T, T, T, T, T, T)` implements `From<[T; 9]>`
39+
and 4 others
40+
= note: required for `!` to implement `Into<()>`
41+
note: required by a bound in `help`
42+
--> $DIR/never-type-fallback-breaking.rs:42:20
43+
|
44+
LL | fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
45+
| ^^^^^^^^ required by this bound in `help`
46+
47+
error: aborting due to 3 previous errors
2548

2649
For more information about this error, try `rustc --explain E0277`.

tests/ui/editions/never-type-fallback-breaking.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
fn main() {
1111
m();
1212
q();
13+
let _ = meow();
1314
}
1415

1516
fn m() {
@@ -36,3 +37,15 @@ fn q() -> Option<()> {
3637

3738
None
3839
}
40+
41+
// Make sure we turbofish the right argument
42+
fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
43+
Err(())
44+
}
45+
fn meow() -> Result<(), ()> {
46+
//[e2021]~^ this function depends on never type fallback being `()`
47+
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
48+
help(1)?;
49+
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
50+
Ok(())
51+
}

0 commit comments

Comments
 (0)