-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Nightly: unsafe code is allowed outside unsafe
blocks when the code is unreachable
#45087
Comments
cc @rust-lang/lang as well This is clearly a result of doing unsafe checking on MIR. My preference would be to continue issuing the error, but we have sometimes decided to let errors in unreachable code slide -- but that was primarily around the borrow check, i.e., checks that are very flow-sensitive. Effect check doesn't seem to fall into that category. Probably if we just perform the unsafe check before we remove dead code, it'd be fine? But @arielb1 can correct. |
triage: P-high We have to reach a decision of some kind. |
I think it's entirely wrong to fail to issue the warning, here. Even if code is unreachable, we shouldn't allow incorrect usage/non-usage of Among other things, that might also break code in |
I think the problem is not so much that the compiler dosen't mind unreachable unsafe code outside of |
Yeah it shouldn't be a problem to fix this |
Affects 1.22 beta too. |
Fix is in queue, nice work @arielb1. |
I'm not sure if this is a feature or a bug, but the compiler behaves differently for the following program on stable, beta, and nightly:
On stable:
On beta:
On nightly:
Note that wrapping the final statement in an
unsafe
block will allow the program to compile on all three versions, but on nightly the compiler will complain:I suppose that the compiler is technically correct, because dead code
tells no talescannot cause memory unsafety, so nounsafe
block is needed... but the current situation does seem like an accident, as the compiler does perform other checks on dead code (typechecking, borrow-checking, ...).The text was updated successfully, but these errors were encountered: