]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/statics/static-mut-xc.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / run-pass / statics / 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 // run-pass
12 #![allow(non_upper_case_globals)]
13
14 // Constants (static variables) can be used to match in patterns, but mutable
15 // statics cannot. This ensures that there's some form of error if this is
16 // attempted.
17
18 // aux-build:static_mut_xc.rs
19
20
21 extern crate static_mut_xc;
22
23 unsafe fn static_bound(_: &'static isize) {}
24
25 fn static_bound_set(a: &'static mut isize) {
26 *a = 3;
27 }
28
29 unsafe fn run() {
30 assert_eq!(static_mut_xc::a, 3);
31 static_mut_xc::a = 4;
32 assert_eq!(static_mut_xc::a, 4);
33 static_mut_xc::a += 1;
34 assert_eq!(static_mut_xc::a, 5);
35 static_mut_xc::a *= 3;
36 assert_eq!(static_mut_xc::a, 15);
37 static_mut_xc::a = -3;
38 assert_eq!(static_mut_xc::a, -3);
39 static_bound(&static_mut_xc::a);
40 static_bound_set(&mut static_mut_xc::a);
41 }
42
43 pub fn main() {
44 unsafe { run() }
45 }
46
47 pub mod inner {
48 pub static mut a: isize = 4;
49 }