Skip to content

Unsafe block does not propagate into array length #105204

Open
@RalfJung

Description

@RalfJung

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions