]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs
Move parse-fail tests to UI
[rust.git] / src / test / ui / lint / issue-47390-unused-variable-in-struct-pattern.rs
1 // Copyright 2018 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 // compile-pass
12
13 #![feature(box_syntax)]
14 #![feature(box_patterns)]
15 #![warn(unused)] // UI tests pass `-A unused` (#43896)
16
17 struct SoulHistory {
18     corridors_of_light: usize,
19     hours_are_suns: bool,
20     endless_and_singing: bool
21 }
22
23 struct LovelyAmbition {
24     lips: usize,
25     fire: usize
26 }
27
28 #[derive(Clone, Copy)]
29 enum Large {
30     Suit { case: () }
31 }
32
33 struct Tuple(Large, ());
34
35 fn main() {
36     let i_think_continually = 2;
37     let who_from_the_womb_remembered = SoulHistory {
38         corridors_of_light: 5,
39         hours_are_suns: true,
40         endless_and_singing: true
41     };
42
43     let mut mut_unused_var = 1;
44
45     let (mut var, unused_var) = (1, 2);
46
47     if let SoulHistory { corridors_of_light,
48                          mut hours_are_suns,
49                          endless_and_singing: true } = who_from_the_womb_remembered {
50         hours_are_suns = false;
51     }
52
53     let the_spirit = LovelyAmbition { lips: 1, fire: 2 };
54     let LovelyAmbition { lips, fire } = the_spirit;
55     println!("{}", lips);
56
57     let bag = Large::Suit {
58         case: ()
59     };
60
61     // Plain struct
62     match bag {
63         Large::Suit { case } => {}
64     };
65
66     // Referenced struct
67     match &bag {
68         &Large::Suit { case } => {}
69     };
70
71     // Boxed struct
72     match box bag {
73         box Large::Suit { case } => {}
74     };
75
76     // Tuple with struct
77     match (bag,) {
78         (Large::Suit { case },) => {}
79     };
80
81     // Slice with struct
82     match [bag] {
83         [Large::Suit { case }] => {}
84     };
85
86     // Tuple struct with struct
87     match Tuple(bag, ()) {
88         Tuple(Large::Suit { case }, ()) => {}
89     };
90 }