forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#88911 - FabianWolff:issue-88653, r=petroche…
…nkov Improve error message for type mismatch in generator arguments Fixes rust-lang#88653. The code example given there is invalid because the `Generator` trait (unlike the `Fn` traits) does not take the generator arguments in tupled-up form (because there can only be one argument, from my understanding). Hence, the type error in the example in rust-lang#88653 is correct, because the given generator takes a `bool` argument, whereas the function's return type talks about a generator with a `(bool,)` argument. The error message is both confusing and wrong, though: It is wrong because it displays the wrong "expected signature", and it is confusing because both the "expected" and "found" notes point at the same span. With my changes, I get the following, more helpful output: ``` error[E0631]: type mismatch in generator arguments --> test.rs:5:22 | 5 | fn foo(bar: bool) -> impl Generator<(bool,)> { | ^^^^^^^^^^^^^^^^^^^^^^^ expected signature of `fn((bool,)) -> _` 6 | |bar| { | ----- found signature of `fn(bool) -> _` ```
- Loading branch information
Showing
4 changed files
with
55 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Regression test for #88653, where a confusing warning about a | ||
// type mismatch in generator arguments was issued. | ||
|
||
#![feature(generators, generator_trait)] | ||
|
||
use std::ops::Generator; | ||
|
||
fn foo(bar: bool) -> impl Generator<(bool,)> { | ||
//~^ ERROR: type mismatch in generator arguments [E0631] | ||
//~| NOTE: expected signature of `fn((bool,)) -> _` | ||
|bar| { | ||
//~^ NOTE: found signature of `fn(bool) -> _` | ||
if bar { | ||
yield bar; | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
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,12 @@ | ||
error[E0631]: type mismatch in generator arguments | ||
--> $DIR/issue-88653.rs:8:22 | ||
| | ||
LL | fn foo(bar: bool) -> impl Generator<(bool,)> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected signature of `fn((bool,)) -> _` | ||
... | ||
LL | |bar| { | ||
| ----- found signature of `fn(bool) -> _` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0631`. |