mozilla/rust — pull request #14862 by alexcrichton (2014-06-12 23:52:32+00:00)
Title: rustc: Allow safe access of shareable static muts

Taking a shareable loan of a `static mut` is safe if the type contained in the
location is ascribes to `Share`. This commit removes the need to have an
`unsafe` block in these situations.

Unsafe blocks are still required to write to or take mutable loans out of
statics. An example of code that no longer requires unsafe code is:

use std::sync::atomics;

static mut CNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;

let cnt = CNT.fetch_add(1, atomics::SeqCst);

As a consequence of this change, this code is not permitted:

static mut FOO: uint = 30;

println!("{}", FOO);

The type `uint` is `Share`, and the static only has a shareable loan taken out
on it, so the access does not require an unsafe block. Writes to the static are
still unsafe, however, as they can invoke undefined behavior if not properly
synchronized.

Closes #13232