-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error "cannot infer type" when using '?' in async block + bad diagnostic #63502
Comments
Opened #63504 for the incorrect suggestion. For the main issue, There are other similar tickets filed about these kind of type inference issues: #49391, #38508, #46333, #46680, #48089, #61152, #58517 and #63082. (larger work around |
The workaround is this: use std::io::Error;
fn make_unit() -> Result<(), Error> {
Ok(())
}
fn main() {
let fut = async {
make_unit()?;
Ok::<(), Error>(())
};
} |
…ntril When needing type annotations in local bindings, account for impl Trait and closures Fix rust-lang#46680, fix rust-lang#63504, fix rust-lang#63506, fix rust-lang#40014, cc rust-lang#63502.
Discussing as part of a "triage effort". A few notes:
We lack a syntax. So maybe we can give a better diagnostic that at least hints at the solution. Or maybe an extended error code description. |
For this case, we probably could suggest a temporary local binding with an explicit type:
As for the syntax, we could borrow the closure syntax and allow something like CC #62570, as it is not the same error, but it is similar enough code that these two errors will likely happen in short temporal distance of each other. |
@estebank did you mean to include the |
Yes, but was missing the final expr |
@estebank That code still would not compile-- the error type annotation doesn't help there because it gets |
You're absolutely right. Need more coffee. |
doesn't |
Current output:
|
The only thing left is for inference to detect that |
This seems related to #42424, except I don't see an obvious workaround like in #42424.
Fails with the error
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ea7e5f7b6e1637f6a39aee0b8209c99e
First of all, it seems like this shouldn't be an error--it should be able to deduce that the return type is
Result<(), io::Error>
, but also the diagnostic does not work. If you try to addimpl std::future::Future<Output=Result<(), Error>>
as a type annotation, it also fails to compile becauseimpl Trait
is only allowed as return types and argument types.Playground link
The text was updated successfully, but these errors were encountered: