2013-06-21 20:46:34 -05: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 04:54:35 -06:00
|
|
|
static mut a: isize = 3;
|
2013-06-21 20:46:34 -05: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 10:23:42 -06:00
|
|
|
match 4 {
|
2016-06-03 15:15:00 -05:00
|
|
|
a => {} //~ ERROR match bindings cannot shadow statics
|
2014-07-13 08:12:47 -05:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NewBool(bool);
|
|
|
|
enum Direction {
|
|
|
|
North,
|
|
|
|
East,
|
|
|
|
South,
|
|
|
|
West
|
|
|
|
}
|
2014-10-06 23:16:35 -05:00
|
|
|
const NEW_FALSE: NewBool = NewBool(false);
|
2014-07-13 08:12:47 -05:00
|
|
|
struct Foo {
|
|
|
|
bar: Option<Direction>,
|
|
|
|
baz: NewBool
|
|
|
|
}
|
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(Direction::West), baz: NEW_FALSE };
|
2014-07-13 08:12:47 -05:00
|
|
|
|
|
|
|
fn mutable_statics() {
|
2014-11-06 02:05:53 -06:00
|
|
|
match (Foo { bar: Some(Direction::North), baz: NewBool(true) }) {
|
2014-07-13 08:12:47 -05:00
|
|
|
Foo { bar: None, baz: NewBool(true) } => (),
|
|
|
|
STATIC_MUT_FOO => (),
|
2016-06-03 15:15:00 -05:00
|
|
|
//~^ ERROR match bindings cannot shadow statics
|
2014-11-06 02:05:53 -06:00
|
|
|
Foo { bar: Some(Direction::South), .. } => (),
|
2014-07-13 08:12:47 -05:00
|
|
|
Foo { bar: Some(EAST), .. } => (),
|
2014-11-06 02:05:53 -06:00
|
|
|
Foo { bar: Some(Direction::North), baz: NewBool(true) } => (),
|
2014-07-13 08:12:47 -05:00
|
|
|
Foo { bar: Some(EAST), baz: NewBool(false) } => ()
|
2013-06-21 20:46:34 -05:00
|
|
|
}
|
|
|
|
}
|