Skip to content

Match assumes extern statics stay the same forever #8694

Closed
@bytwise

Description

@bytwise

The code:

// aux.rs
#[crate_type = "lib"];
pub static Foo: uint = 1;
// main.rs
extern mod aux;
fn main() {
    let x = aux::Foo;
    match x {
        aux::Foo => println("Foo == Foo"),
        _ => println("Foo != Foo")
    }
}

produces the expected output: Foo == Foo
But after changing aux.rs to

#[crate_type = "lib"];
pub static Foo: uint = 2;

and recompiling only aux.rs, the output is Foo != Foo

This is because rustc is too eager and replaces the match pattern aux::Foo with 1 at compile-time. That works until we change aux::Foo. Because x gets its value at runtime, it becomes 2 and doesn't fit the first match arm.

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