Skip to content
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 block does not propagate into array length #105204

Open
RalfJung opened this issue Dec 3, 2022 · 0 comments
Open

Unsafe block does not propagate into array length #105204

RalfJung opened this issue Dec 3, 2022 · 0 comments
Labels
A-array Area: [T; N]

Comments

@RalfJung
Copy link
Member

RalfJung commented Dec 3, 2022

The lang team indicated that the following code should compile:

const unsafe fn test() -> usize { 42 }

fn main() { unsafe {
    let x = [0; test()];
} }

However currently the array length does not "inherit" unsafety from the surrounding block.

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
 --> src/main.rs:4:17
  |
4 |     let x = [0; test()];
  |                 ^^^^^^ call to unsafe function
  |
  = note: consult the function's documentation for information on how to avoid undefined behavior
@workingjubilee workingjubilee added the A-array Area: [T; N] label Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: [T; N]
Projects
None yet
Development

No branches or pull requests

2 participants