2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
|
2013-06-22 01:46:34 +00:00
|
|
|
// Constants (static variables) can be used to match in patterns, but mutable
|
|
|
|
// statics cannot. This ensures that there's some form of error if this is
|
|
|
|
// attempted.
|
|
|
|
|
|
|
|
//@ aux-build:static_mut_xc.rs
|
|
|
|
|
2014-02-14 18:10:06 +00:00
|
|
|
extern crate static_mut_xc;
|
2013-06-22 01:46:34 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
unsafe fn static_bound(_: &'static isize) {}
|
2013-06-22 01:46:34 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn static_bound_set(a: &'static mut isize) {
|
2013-06-22 01:46:34 +00:00
|
|
|
*a = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn run() {
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(static_mut_xc::a, 3);
|
2013-06-22 01:46:34 +00:00
|
|
|
static_mut_xc::a = 4;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(static_mut_xc::a, 4);
|
2013-06-22 01:46:34 +00:00
|
|
|
static_mut_xc::a += 1;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(static_mut_xc::a, 5);
|
2013-06-22 01:46:34 +00:00
|
|
|
static_mut_xc::a *= 3;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(static_mut_xc::a, 15);
|
2013-06-22 01:46:34 +00:00
|
|
|
static_mut_xc::a = -3;
|
2015-06-07 18:00:38 +00:00
|
|
|
assert_eq!(static_mut_xc::a, -3);
|
2013-06-22 01:46:34 +00:00
|
|
|
static_bound(&static_mut_xc::a);
|
2024-02-17 19:01:56 +00:00
|
|
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
2013-06-22 01:46:34 +00:00
|
|
|
static_bound_set(&mut static_mut_xc::a);
|
2024-02-17 19:01:56 +00:00
|
|
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
2013-06-22 01:46:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 14:42:22 +00:00
|
|
|
pub fn main() {
|
2013-06-22 01:46:34 +00:00
|
|
|
unsafe { run() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod inner {
|
2015-03-26 00:06:52 +00:00
|
|
|
pub static mut a: isize = 4;
|
2013-06-22 01:46:34 +00:00
|
|
|
}
|