]> git.proxmox.com Git - rustc.git/blob - src/test/ui/match/match-arm-statics.rs
New upstream version 1.30.0~beta.7+dfsg1
[rustc.git] / src / test / ui / match / match-arm-statics.rs
1 // Copyright 2014 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 #![allow(dead_code)]
12 #![deny(unreachable_patterns)]
13
14 use self::Direction::{North, East, South, West};
15
16 #[derive(PartialEq, Eq)]
17 struct NewBool(bool);
18
19 #[derive(PartialEq, Eq)]
20 enum Direction {
21 North,
22 East,
23 South,
24 West
25 }
26
27 const TRUE_TRUE: (bool, bool) = (true, true);
28
29 fn unreachable_1() {
30 match (true, false) {
31 TRUE_TRUE => (),
32 (false, false) => (),
33 (false, true) => (),
34 (true, false) => (),
35 (true, true) => ()
36 //~^ ERROR unreachable pattern
37 }
38 }
39
40 const NONE: Option<Direction> = None;
41 const EAST: Direction = East;
42
43 fn unreachable_2() {
44 match Some(Some(North)) {
45 Some(NONE) => (),
46 Some(Some(North)) => (),
47 Some(Some(EAST)) => (),
48 Some(Some(South)) => (),
49 Some(Some(West)) => (),
50 Some(Some(East)) => (),
51 //~^ ERROR unreachable pattern
52 None => ()
53 }
54 }
55
56 const NEW_FALSE: NewBool = NewBool(false);
57 struct Foo {
58 bar: Option<Direction>,
59 baz: NewBool
60 }
61
62 fn unreachable_3() {
63 match (Foo { bar: Some(EAST), baz: NewBool(true) }) {
64 Foo { bar: None, baz: NewBool(true) } => (),
65 Foo { bar: _, baz: NEW_FALSE } => (),
66 Foo { bar: Some(West), baz: NewBool(true) } => (),
67 Foo { bar: Some(South), .. } => (),
68 Foo { bar: Some(EAST), .. } => (),
69 Foo { bar: Some(North), baz: NewBool(true) } => (),
70 Foo { bar: Some(EAST), baz: NewBool(false) } => ()
71 //~^ ERROR unreachable pattern
72 }
73 }
74
75 fn main() {
76 unreachable_1();
77 unreachable_2();
78 unreachable_3();
79 }