-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Cannot infer type even if specified. #42424
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
Comments
Could you provide the entire function for context? |
It's in a |
Well, the whole function would also make it a little easier to see context in general -- right now, I can't even attempt to run this, which makes it hard to debug. |
Oh, I'm sorry. Here it is. Ignore the unfinishedness of it. That's because it is. Unfinished. I'm trying to get rid of the play function and instead use a catch block. |
Is there a chance you could produce an example that doesn't rely on external crates? That makes debugging easier. If that's not possible, no worries. |
The following code triggers the same error on #![feature(catch_expr)]
pub struct X;
pub fn new_x() -> Result<X, ()> {
return Ok(X);
}
fn main() {
do catch {
let x: X = new_x()?;
Ok(())
};
} (https://play.rust-lang.org/?gist=ffd0e7e68eb97486bf742bd63cc9cb2f&version=nightly) |
@Mark-Simulacrum I have no idea why I didn't reply - probably forgot about it. I'm so sorry for being rude. @dsprenkels Thanks!! Seems like the problem is just in general returning a |
I'm not really sure. The following code fails: #![feature(catch_expr)]
fn main() {
do catch {
let x: () = Ok(())?;
Ok(())
};
} But changing the return type does not seem to help. The following code also fails: #![feature(catch_expr)]
fn main() {
do catch {
let x: () = Ok(())?;
Ok(42)
};
} Note: the type of |
To fix it you need to give a type to the #![feature(catch_expr)]
pub struct X;
pub fn new_x() -> Result<X, ()> {
return Ok(X);
}
fn main() {
let _: Result<_, ()> = do catch { // <---------
let x: X = new_x()?;
Ok(())
};
} The library should be able to instruct the inference engine to consider (And yes, the diagnostic is also an issue.) |
The updated code will only work on 2018 edition:
and result in
It should be possible to turn it into the following relatively easily
|
Current output:
After specifying the error type in the tail expression, we get another inference error on the
|
So, I got the
type annotations needed
error. I tried everything. It refuses to work.Error
(please don't tell me the code is stupid. I have a valid reason to ignore the error)
If this is my fault, and not an issue with Rust, apologies for spamming you with yet another false issue :(
I feel horrible
The text was updated successfully, but these errors were encountered: