Skip to content

*&X allows referring to the static X by value as if X were a const #26121

Closed
@oli-obk

Description

@oli-obk

Found by @eddyb at #25570 (comment).

fn main() {
    static A: i32 = 0;
    static B: i32 = *&A;
    println!("{:?}", B);
}

aborts the compiler:

Illegal instruction (core dumped)
playpen: application terminated with error code 132

static A: i32 = 0;
static B: i32 = *&A;

fn main() {
    println!("{:?}", B);
}

prints 0 on the terminal without any warnings or errors

It doesn't really cause any weird behavior if it's a global static, it just acts as if the referred to static were a const: PlayPen

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions