Open DustinByfuglien opened 4 years ago
I can illustrate by screenshot.
x
have closure type || -> i32
but really it have generator typeInterestingly, despite the bogus syntax error for no.1, rust-analyzer seems to typecheck yield arguments properly.
fn foo() {
let bar = || {
yield "baz";
yield 0i32; // E0308: expected `&str`, found `i32`
yield; // E0308: expected `&str`, found `()`
};
}
Any such error is coming from cargo check, not rust-analyzer's analysis.
Cargo check passed without errors. Program compiled and executed without errors.
Sorry, I meant the E308 type checker errors.
Parsing has been implemented in #7209, type inference is yet to be implemented.
Type inference for the parameter should also be covered:
fn wrapper(mut generator: impl Generator<i32, Yield = i32> + Unpin) {
while let Yielded(x) = Pin::new(&mut generator).resume(42) {
println!("{}", x);
}
}
fn main() {
wrapper(|i| { // i: {unknown}
yield i + 1;
yield i + 2;
yield i + 3;
});
}
When using VSCode with this code I notice that:
yield
with argument is reported by analyzer as error.x
type displays thatx
have closure type|| -> i32
instead of generator trait type.