]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0017.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0017.md
1 References in statics and constants may only refer to immutable values.
2
3 Erroneous code example:
4
5 ```compile_fail,E0017
6 static X: i32 = 1;
7 const C: i32 = 2;
8
9 // these three are not allowed:
10 const CR: &mut i32 = &mut C;
11 static STATIC_REF: &'static mut i32 = &mut X;
12 static CONST_REF: &'static mut i32 = &mut C;
13 ```
14
15 Statics are shared everywhere, and if they refer to mutable data one might
16 violate memory safety since holding multiple mutable references to shared data
17 is not allowed.
18
19 If you really want global mutable state, try using `static mut` or a global
20 `UnsafeCell`.