]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/constant-in-match-pattern.rs
Auto merge of #28364 - petrochenkov:usegate, r=alexcrichton
[rust.git] / src / test / debuginfo / constant-in-match-pattern.rs
1 // Copyright 2013-2015 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 // min-lldb-version: 310
12
13 // compile-flags:-g
14
15 #![allow(dead_code, unused_variables)]
16 #![feature(omit_gdb_pretty_printer_section)]
17 #![omit_gdb_pretty_printer_section]
18
19 // This test makes sure that the compiler doesn't crash when trying to assign
20 // debug locations to 'constant' patterns in match expressions.
21
22 const CONSTANT: u64 = 3;
23
24 struct Struct {
25     a: isize,
26     b: usize,
27 }
28 const STRUCT: Struct = Struct { a: 1, b: 2 };
29
30 struct TupleStruct(u32);
31 const TUPLE_STRUCT: TupleStruct = TupleStruct(4);
32
33 enum Enum {
34     Variant1(char),
35     Variant2 { a: u8 },
36     Variant3
37 }
38 const VARIANT1: Enum = Enum::Variant1('v');
39 const VARIANT2: Enum = Enum::Variant2 { a: 2 };
40 const VARIANT3: Enum = Enum::Variant3;
41
42 const STRING: &'static str = "String";
43
44 fn main() {
45
46     match 1 {
47         CONSTANT => {}
48         _ => {}
49     };
50
51     // if let 3 = CONSTANT {}
52
53     match (Struct { a: 2, b: 2 }) {
54         STRUCT => {}
55         _ => {}
56     };
57
58     // if let STRUCT = STRUCT {}
59
60     match TupleStruct(3) {
61         TUPLE_STRUCT => {}
62         _ => {}
63     };
64
65     // if let TupleStruct(4) = TUPLE_STRUCT {}
66
67     match VARIANT3 {
68         VARIANT1 => {},
69         VARIANT2 => {},
70         VARIANT3 => {},
71         _ => {}
72     };
73
74     match (VARIANT3, VARIANT2) {
75         (VARIANT1, VARIANT3) => {},
76         (VARIANT2, VARIANT2) => {},
77         (VARIANT3, VARIANT1) => {},
78         _ => {}
79     };
80
81     // if let VARIANT1 = Enum::Variant3 {}
82     // if let VARIANT2 = Enum::Variant3 {}
83     // if let VARIANT3 = Enum::Variant3 {}
84
85     match "abc" {
86         STRING => {},
87         _ => {}
88     }
89
90     if let STRING = "def" {}
91 }