-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Semicolon after diverging try operator shouldn't matter #106357
Comments
My understanding is that this is related to the fallback issues that have been preventing stabilization of the |
I was kind of afraid that's the case. If this seems too separate from the existing issues for those, feel free to close it! Although I guess that this is another example that might be useful to test for. |
I'm not sure this is a bug, fn breaks() -> Result<bool, i32> {
Err(1)?;
} gets desugared to fn breaks() -> Result<bool, i32> {
match Err(1) {
Ok(x) => x,
Err(e) => return Err(e.into())
};
} Unless you are relying on the compiler to eliminate the I don't think the compiler should be required to do this elimination, as involving optimizations in exausiveness checks seems like it could get unintuitive fast, and expose many people to accidental breakage. |
So, I would agree with this, except for the fact that the compiler could absolutely infer the type of |
Related: rust-lang/style-team#165 (comment) |
Also related: feature |
So. Mrgh. This issue is indeed with the fallback. fn breaks() -> Result<bool, i32> {
match Err(1) {
Ok(x) => x,
Err(e) => return Err(e.into())
};
} This desugaring causes the type of the match to be inferred to Note however that I would highly advice against writing |
As Waffle suggests, this is related to all of: |
Originally mentioned in this comment: #96373 (comment)
Essentially, semicolons after other diverging expressions are allowed. For example:
Here, the compiler is clever enough to note that because
return Err(1)
always diverges, adding a semicolon after doesn't matter. However, the below code which is equivalent to this does not work properly:Here's a playground link containing the above two examples: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=af894bab48348897a421a9402856b71f
The exact compiler error:
The text was updated successfully, but these errors were encountered: