-
Couldn't load subscription status.
- Fork 13.9k
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