-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-coroutinesArea: CoroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code (playground):
#![feature(generators, generator_trait)]
use std::ops::Generator;
fn foo(bar: bool) -> impl Generator<(bool,)> {
|bar| {
if bar {
yield bar;
}
}
}
The current output is:
error[E0631]: type mismatch in function arguments
--> src/lib.rs:5:22
|
5 | fn foo(bar: bool) -> impl Generator<(bool,)> {
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected signature of `fn(bool) -> _`
| found signature of `fn(bool) -> _`
For more information about this error, try `rustc --explain E0631`.
error: could not compile `playground` due to previous error
This diagnostic seems bizarre since, as far as I'm aware, the type parameter on Generator
represents the arguments to the generator (like how Fn
is represented at the time of writing), and the generator's parameters can be trivially seen to consist of one bool
. Ideally, this should either compile or emit a less confusing diagnostic. I'm not sure whether this is an issue with E0631 or a bug in generators.
This still occurs when returning a bool
from the generator, yielding a different type, giving an explicit type to the generator's bar
parameter, and when specifying the Return
and Yield
types in impl Generator
.
@rustbot modify labels: +A-generators +D-confusing +F-generators
Metadata
Metadata
Assignees
Labels
A-coroutinesArea: CoroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.