-
Notifications
You must be signed in to change notification settings - Fork 13.3k
regression: #[forbid(unreachable_code)] incompatible with the Try ('?') operator #76053
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
According to Godbolt this is the case since 1.22.0 where the |
This bug can also be reproduced with a #![forbid(unreachable_code)]
#[allow(dead_code)] // Remove warning.
fn foo() -> Result<(), ()> {
Ok(0)?;
Err(()) // Just so it doesn't emit error here.
} Which allows to find out that this regressed in 1.16.0. |
Assigning |
a new warning was caused by the `?` operator as it contains `#[allow(unreachable_code)]`, which clashes with the previous `forbid` rule. as `forbid` does not allow `deny` to override it this would cause a compile error, however due to a compiler bug this was previously not reported at all and has now been changed to a warning in a recent(-ish) version of rustc and will eventually become a compile error. with `deny` it's still possible to use `allow`, thus there's no warning see also rust-lang/rust#76053 thanks @jannic
This code now compiles fine, we just need a test added against this to close the issue |
Agreed with release 1.83 the sample code compiles with no errors or warnings. Has the test been added? |
I tried this code:
Both on debug and release it generates an error saying that
#[allow(unreachable_code)]
was overridden by the#[forbid(...)]
attribute, while pointing at the "try" expression.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: