-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
poor error message with question mark applied to non-Result #32175
Comments
This is because it expands to fn main() {
match 42 {
Err(err) => return Err(From::from(err)),
Ok(val) => val,
};
} so the error comes from the match arms. I know the expansion is done before typechecking, but a possible way to fix it is with type ascription. This expansion produces a better error: #![feature(type_ascription)]
fn main() {
match 42: Result<_,_> {
Err(err) => return Err(From::from(err)),
Ok(val) => val,
};
} |
I think we can swap the expected and found types for these errors when they originate from desugared syntax and seems like we do something like that for if let. I'll give it a try. |
Heh, but if you switch them what of this code? #![feature(question_mark, type_ascription)]
fn main() {
(42: Result<_,_>)?;
} |
I think that error message would remain unchanged between there is no type mismatch between the "head" |
cc me |
I am now seeing a new error message. @durka, how do you feel about this?
|
That's a pretty terrible error message from a user perspective. cc @nrc (about |
Just to clarify: the examples in this issue are also showing the error messages when you try to use fn something() -> Result<(), ()> {
42?;
Ok(())
} which currently results in this single error:
|
Hello |
hey @cengizio 👋 Not yet, no. There's some linked issues/PRs in the comments above, but it has not yet been fixed. |
@nodakai no, this issue is for using the |
|
This code
prints the error
which is confusing. The error is that I put a non-Result where a Result was expected, but the error says the opposite.
cc @japaric
The text was updated successfully, but these errors were encountered: