summaryrefslogtreecommitdiffstats
path: root/tests/ui/thread-local/thread-local-mutation.rs
blob: e738225ce2a48569b7c1beb761ea70bb9cfa9eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Regression test for #54901: immutable thread locals could be mutated. See:
// https://github.com/rust-lang/rust/issues/29594#issuecomment-328177697
// https://github.com/rust-lang/rust/issues/54901

#![feature(thread_local)]

#[thread_local]
static S: &str = "before";

fn set_s() {
    S = "after"; //~ ERROR cannot assign to immutable
}

fn main() {
    println!("{}", S);
    set_s();
    println!("{}", S);
}