rust/tests/ui/thread-local/thread-local-mutation.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
416 B
Rust
Raw Normal View History

// 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);
}