]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-shorthand-field.rs
Move parse-fail tests to UI
[rust.git] / src / test / ui / lint / lint-shorthand-field.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(nonstandard_style, unused_variables)]
12 #![deny(non_shorthand_field_patterns)]
13
14 struct Foo {
15     x: isize,
16     y: isize,
17 }
18
19 fn main() {
20     {
21         let Foo {
22             x: x, //~ ERROR the `x:` in this pattern is redundant
23             y: ref y, //~ ERROR the `y:` in this pattern is redundant
24         } = Foo { x: 0, y: 0 };
25
26         let Foo {
27             x,
28             ref y,
29         } = Foo { x: 0, y: 0 };
30     }
31
32     {
33         const x: isize = 1;
34
35         match (Foo { x: 1, y: 1 }) {
36             Foo { x: x, ..} => {},
37             _ => {},
38         }
39     }
40
41     {
42         struct Bar {
43             x: x,
44         }
45
46         struct x;
47
48         match (Bar { x: x }) {
49             Bar { x: x } => {},
50         }
51     }
52
53     {
54         struct Bar {
55             x: Foo,
56         }
57
58         enum Foo { x }
59
60         match (Bar { x: Foo::x }) {
61             Bar { x: Foo::x } => {},
62         }
63     }
64 }