]> git.lizzy.rs Git - rust.git/blob - tests/ui/statics/static-mut-xc.rs
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
[rust.git] / tests / ui / statics / static-mut-xc.rs
1 // run-pass
2 #![allow(non_upper_case_globals)]
3
4 // Constants (static variables) can be used to match in patterns, but mutable
5 // statics cannot. This ensures that there's some form of error if this is
6 // attempted.
7
8 // aux-build:static_mut_xc.rs
9
10
11 extern crate static_mut_xc;
12
13 unsafe fn static_bound(_: &'static isize) {}
14
15 fn static_bound_set(a: &'static mut isize) {
16     *a = 3;
17 }
18
19 unsafe fn run() {
20     assert_eq!(static_mut_xc::a, 3);
21     static_mut_xc::a = 4;
22     assert_eq!(static_mut_xc::a, 4);
23     static_mut_xc::a += 1;
24     assert_eq!(static_mut_xc::a, 5);
25     static_mut_xc::a *= 3;
26     assert_eq!(static_mut_xc::a, 15);
27     static_mut_xc::a = -3;
28     assert_eq!(static_mut_xc::a, -3);
29     static_bound(&static_mut_xc::a);
30     static_bound_set(&mut static_mut_xc::a);
31 }
32
33 pub fn main() {
34     unsafe { run() }
35 }
36
37 pub mod inner {
38     pub static mut a: isize = 4;
39 }