]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/static-mut-xc.rs
5911b6cfa8504e4f22fd6b87517f6b84c92a14dd
[rustc.git] / src / test / run-pass / static-mut-xc.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Constants (static variables) can be used to match in patterns, but mutable
12 // statics cannot. This ensures that there's some form of error if this is
13 // attempted.
14
15 // aux-build:static_mut_xc.rs
16
17
18 extern crate static_mut_xc;
19
20 unsafe fn static_bound(_: &'static isize) {}
21
22 fn static_bound_set(a: &'static mut isize) {
23 *a = 3;
24 }
25
26 unsafe fn run() {
27 assert_eq!(static_mut_xc::a, 3);
28 static_mut_xc::a = 4;
29 assert_eq!(static_mut_xc::a, 4);
30 static_mut_xc::a += 1;
31 assert_eq!(static_mut_xc::a, 5);
32 static_mut_xc::a *= 3;
33 assert_eq!(static_mut_xc::a, 15);
34 static_mut_xc::a = -3;
35 assert_eq!(static_mut_xc::a, -3);
36 static_bound(&static_mut_xc::a);
37 static_bound_set(&mut static_mut_xc::a);
38 }
39
40 pub fn main() {
41 unsafe { run() }
42 }
43
44 pub mod inner {
45 pub static mut a: isize = 4;
46 }