forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#99942 - compiler-errors:nonsense-un-tupled-…
…fn-trait-error, r=cjgillot Fix nonsense non-tupled `Fn` trait error Given this code: ```rust #![feature(unboxed_closures)] fn a<F: Fn<usize>>(f: F) {} fn main() { a(|_: usize| {}); } ``` We currently emit this error: ``` error[E0631]: type mismatch in closure arguments --> src/main.rs:6:5 | 6 | a(|_: usize| {}); | ^ ---------- found signature of `fn(usize) -> _` | | | expected signature of `fn(usize) -> _` | note: required by a bound in `a` --> src/main.rs:3:9 | 3 | fn a<F: Fn<usize>>(f: F) {} | ^^^^^^^^^ required by this bound in `a` For more information about this error, try `rustc --explain E0631`. error: could not compile `playground` due to previous error ``` Notably, it says the same thing for "expected" and "found"! Fix the output so that we instead emit: ``` error[E0308]: mismatched types --> /home/gh-compiler-errors/test.rs:6:5 | 6 | a(|_: usize| {}); | ^ types differ | = note: expected trait `Fn<usize>` found trait `Fn<(usize,)>` note: required by a bound in `a` --> /home/gh-compiler-errors/test.rs:3:9 | 3 | fn a<F: Fn<usize>>(f: F) {} | ^^^^^^^^^ required by this bound in `a` error: aborting due to previous error ``` The error could still use some work, namely the "mismatched types" part, but I'm leaving it a bit rough since the only way you'd ever get this error is when you're messing with `#![feature(unboxed_closures)]`. Simply making sure we actually print out the difference in trait-refs is good enough for me. I could probably factor in some additional improvements if those are desired.
- Loading branch information
Showing
10 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![feature(unboxed_closures)] | ||
|
||
fn a<F: Fn<usize>>(f: F) {} | ||
|
||
fn main() { | ||
a(|_: usize| {}); | ||
//~^ ERROR mismatched types | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/unboxed-closures/non-tupled-arg-mismatch.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/non-tupled-arg-mismatch.rs:6:5 | ||
| | ||
LL | a(|_: usize| {}); | ||
| ^ types differ | ||
| | ||
= note: expected trait `Fn<usize>` | ||
found trait `Fn<(usize,)>` | ||
note: required by a bound in `a` | ||
--> $DIR/non-tupled-arg-mismatch.rs:3:9 | ||
| | ||
LL | fn a<F: Fn<usize>>(f: F) {} | ||
| ^^^^^^^^^ required by this bound in `a` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |