]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/static-mut-not-pat.rs
Update compile fail tests to use isize.
[rust.git] / src / test / compile-fail / static-mut-not-pat.rs
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.
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 static mut a: isize = 3;
16
17 fn main() {
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)
22     match 4i {
23         a => {} //~ ERROR static variables cannot be referenced in a pattern
24         _ => {}
25     }
26 }
27
28 struct NewBool(bool);
29 enum Direction {
30     North,
31     East,
32     South,
33     West
34 }
35 const NEW_FALSE: NewBool = NewBool(false);
36 struct Foo {
37     bar: Option<Direction>,
38     baz: NewBool
39 }
40
41 static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(Direction::West), baz: NEW_FALSE };
42
43 fn mutable_statics() {
44     match (Foo { bar: Some(Direction::North), baz: NewBool(true) }) {
45         Foo { bar: None, baz: NewBool(true) } => (),
46         STATIC_MUT_FOO => (),
47         //~^ ERROR static variables cannot be referenced in a pattern
48         Foo { bar: Some(Direction::South), .. } => (),
49         Foo { bar: Some(EAST), .. } => (),
50         Foo { bar: Some(Direction::North), baz: NewBool(true) } => (),
51         Foo { bar: Some(EAST), baz: NewBool(false) } => ()
52     }
53 }