]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/pattern-binding-disambiguation.rs
Rollup merge of #56947 - hsivonen:neon, r=alexcrichton
[rust.git] / src / test / ui / pattern / pattern-binding-disambiguation.rs
1 // Copyright 2017 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 struct UnitStruct;
12 struct TupleStruct();
13 struct BracedStruct{}
14
15 enum E {
16     UnitVariant,
17     TupleVariant(),
18     BracedVariant{},
19 }
20 use E::*;
21
22 const CONST: () = ();
23 static STATIC: () = ();
24
25 fn function() {}
26
27 fn main() {
28     let doesnt_matter = 0;
29
30     match UnitStruct {
31         UnitStruct => {} // OK, `UnitStruct` is a unit struct pattern
32     }
33     match doesnt_matter {
34         TupleStruct => {} //~ ERROR match bindings cannot shadow tuple structs
35     }
36     match doesnt_matter {
37         BracedStruct => {} // OK, `BracedStruct` is a fresh binding
38     }
39     match UnitVariant {
40         UnitVariant => {} // OK, `UnitVariant` is a unit variant pattern
41     }
42     match doesnt_matter {
43         TupleVariant => {} //~ ERROR match bindings cannot shadow tuple variants
44     }
45     match doesnt_matter {
46         BracedVariant => {} //~ ERROR match bindings cannot shadow struct variants
47     }
48     match CONST {
49         CONST => {} // OK, `CONST` is a const pattern
50     }
51     match doesnt_matter {
52         STATIC => {} //~ ERROR match bindings cannot shadow statics
53     }
54     match doesnt_matter {
55         function => {} // OK, `function` is a fresh binding
56     }
57
58     let UnitStruct = UnitStruct; // OK, `UnitStruct` is a unit struct pattern
59     let TupleStruct = doesnt_matter; //~ ERROR let bindings cannot shadow tuple structs
60     let BracedStruct = doesnt_matter; // OK, `BracedStruct` is a fresh binding
61     let UnitVariant = UnitVariant; // OK, `UnitVariant` is a unit variant pattern
62     let TupleVariant = doesnt_matter; //~ ERROR let bindings cannot shadow tuple variants
63     let BracedVariant = doesnt_matter; //~ ERROR let bindings cannot shadow struct variants
64     let CONST = CONST; // OK, `CONST` is a const pattern
65     let STATIC = doesnt_matter; //~ ERROR let bindings cannot shadow statics
66     let function = doesnt_matter; // OK, `function` is a fresh binding
67 }