-
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
unsafe
blocks do not apply to array length expressions they contain
#72359
Comments
The ticket is valid, but of curiosity, why would you need to use |
FWIW, fn foo() { unsafe {
fn bar() { /* not considered in unsafe block */ }
} } But AFAIK they do propagate to closures. I am not sure which one array length expressions are "closer" to... they feel somewhat distinct from both, honestly. |
The example is not derived from real code.
To me, array length expressions feel even more part of their containing item than closures, and much more so than nested functions. Not sure how widely shared this view is. I suppose we don't allow array length expressions to reference in-scope generic parameters, while we do allow closures to refer to them. I think this is more a technical limitation than a concious choice, however. |
I'll try to see if we can special-case const blocks as we do with closures. @rustbot claim |
The following example fails to compile on the latest nightly.
Output:
I would have expected this to compile successfully, but it seems that
unsafe
is not applied to array length expressions. The nightly features are only needed because there are no stableconst unsafe
functions. A user-definedconst unsafe fn
runs into the same error on stable.This arose from discussion in rust-lang/rfcs#2920.
The text was updated successfully, but these errors were encountered: