1 // Copyright 2013 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.
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.
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
15 static mut a: int = 3;
18 // If they can't be matched against, then it's possible to capture the same
19 // name as a variable, hence this should be an unreachable pattern situation
20 // instead of spitting out a custom error about some identifier collisions
21 // (we should allow shadowing)
23 a => {} //~ ERROR mutable static variables cannot be referenced in a pattern
35 static NEW_FALSE: NewBool = NewBool(false);
37 bar: Option<Direction>,
41 static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(West), baz: NEW_FALSE };
43 fn mutable_statics() {
44 match (Foo { bar: Some(North), baz: NewBool(true) }) {
45 Foo { bar: None, baz: NewBool(true) } => (),
47 //~^ ERROR mutable static variables cannot be referenced in a pattern
48 Foo { bar: Some(South), .. } => (),
49 Foo { bar: Some(EAST), .. } => (),
50 Foo { bar: Some(North), baz: NewBool(true) } => (),
51 Foo { bar: Some(EAST), baz: NewBool(false) } => ()