]> git.lizzy.rs Git - rust.git/blob - src/test/ui/static/static-mut-not-pat.rs
Rollup merge of #105955 - Nilstrieb:no-trivial-opt-wrappers-we-have-field-accesses...
[rust.git] / src / test / ui / static / static-mut-not-pat.rs
1 // Constants (static variables) can be used to match in patterns, but mutable
2 // statics cannot. This ensures that there's some form of error if this is
3 // attempted.
4
5 static mut a: isize = 3;
6
7 fn main() {
8     // If they can't be matched against, then it's possible to capture the same
9     // name as a variable, hence this should be an unreachable pattern situation
10     // instead of spitting out a custom error about some identifier collisions
11     // (we should allow shadowing)
12     match 4 {
13         a => {} //~ ERROR match bindings cannot shadow statics
14         _ => {}
15     }
16 }
17
18 struct NewBool(bool);
19 enum Direction {
20     North,
21     East,
22     South,
23     West
24 }
25 const NEW_FALSE: NewBool = NewBool(false);
26 struct Foo {
27     bar: Option<Direction>,
28     baz: NewBool
29 }
30
31 static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(Direction::West), baz: NEW_FALSE };
32
33 fn mutable_statics() {
34     match (Foo { bar: Some(Direction::North), baz: NewBool(true) }) {
35         Foo { bar: None, baz: NewBool(true) } => (),
36         STATIC_MUT_FOO => (),
37         //~^ ERROR match bindings cannot shadow statics
38         Foo { bar: Some(Direction::South), .. } => (),
39         Foo { bar: Some(EAST), .. } => (),
40         Foo { bar: Some(Direction::North), baz: NewBool(true) } => (),
41         Foo { bar: Some(EAST), baz: NewBool(false) } => ()
42     }
43 }