Skip to content

"raw pointers cannot be cast to integers in statics" justification is incorrect #30705

Closed
@mahkoh

Description

@mahkoh
pub static mut X: usize = unsafe { &X as *const _ as usize };
The value of static and const variables must be known at compile time. You
can't cast a pointer as an integer because we can't know what value the
address will take.

This is incorrect as the following code shows:

pub static mut X: *const u8 = unsafe { &X as *const _ as *const _ };

The value of X is only known at link time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions