2013-06-21 18:46:34 -07: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.
|
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
static mut a: isize = 3;
|
2013-06-21 18:46:34 -07:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// If they can't be matched against, then it's possible to capture the same
|
|
|
|
// name as a variable, hence this should be an unreachable pattern situation
|
|
|
|
// instead of spitting out a custom error about some identifier collisions
|
|
|
|
// (we should allow shadowing)
|
2015-01-31 17:23:42 +01:00
|
|
|
match 4 {
|
2016-06-03 23:15:00 +03:00
|
|
|
a => {} //~ ERROR match bindings cannot shadow statics
|
2014-07-13 15:12:47 +02:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NewBool(bool);
|
|
|
|
enum Direction {
|
|
|
|
North,
|
|
|
|
East,
|
|
|
|
South,
|
|
|
|
West
|
|
|
|
}
|
2014-10-06 21:16:35 -07:00
|
|
|
const NEW_FALSE: NewBool = NewBool(false);
|
2014-07-13 15:12:47 +02:00
|
|
|
struct Foo {
|
|
|
|
bar: Option<Direction>,
|
|
|
|
baz: NewBool
|
|
|
|
}
|
|
|
|
|
2014-11-06 00:05:53 -08:00
|
|
|
static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(Direction::West), baz: NEW_FALSE };
|
2014-07-13 15:12:47 +02:00
|
|
|
|
|
|
|
fn mutable_statics() {
|
2014-11-06 00:05:53 -08:00
|
|
|
match (Foo { bar: Some(Direction::North), baz: NewBool(true) }) {
|
2014-07-13 15:12:47 +02:00
|
|
|
Foo { bar: None, baz: NewBool(true) } => (),
|
|
|
|
STATIC_MUT_FOO => (),
|
2016-06-03 23:15:00 +03:00
|
|
|
//~^ ERROR match bindings cannot shadow statics
|
2014-11-06 00:05:53 -08:00
|
|
|
Foo { bar: Some(Direction::South), .. } => (),
|
2014-07-13 15:12:47 +02:00
|
|
|
Foo { bar: Some(EAST), .. } => (),
|
2014-11-06 00:05:53 -08:00
|
|
|
Foo { bar: Some(Direction::North), baz: NewBool(true) } => (),
|
2014-07-13 15:12:47 +02:00
|
|
|
Foo { bar: Some(EAST), baz: NewBool(false) } => ()
|
2013-06-21 18:46:34 -07:00
|
|
|
}
|
|
|
|
}
|