]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs
or-patterns: #47390: we rely on names to exercise `IndexMap`.
[rust.git] / src / test / ui / lint / issue-47390-unused-variable-in-struct-pattern.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2
3 #![feature(box_syntax)]
4 #![feature(box_patterns)]
5 #![warn(unused)] // UI tests pass `-A unused` (#43896)
6
7 struct SoulHistory {
8     corridors_of_light: usize,
9     hours_are_suns: bool,
10     endless_and_singing: bool
11 }
12
13 struct LovelyAmbition {
14     lips: usize,
15     fire: usize
16 }
17
18 #[derive(Clone, Copy)]
19 enum Large {
20     Suit { case: () }
21 }
22
23 struct Tuple(Large, ());
24
25 fn main() {
26     let i_think_continually = 2;
27     let who_from_the_womb_remembered = SoulHistory {
28         corridors_of_light: 5,
29         hours_are_suns: true,
30         endless_and_singing: true
31     };
32
33     let mut mut_unused_var = 1;
34
35     let (mut var, unused_var) = (1, 2);
36     // NOTE: `var` comes after `unused_var` lexicographically yet the warning
37     // for `var` will be emitted before the one for `unused_var`. We use an
38     // `IndexMap` to ensure this is the case instead of a `BTreeMap`.
39
40     if let SoulHistory { corridors_of_light,
41                          mut hours_are_suns,
42                          endless_and_singing: true } = who_from_the_womb_remembered {
43         hours_are_suns = false;
44     }
45
46     let the_spirit = LovelyAmbition { lips: 1, fire: 2 };
47     let LovelyAmbition { lips, fire } = the_spirit;
48     println!("{}", lips);
49
50     let bag = Large::Suit {
51         case: ()
52     };
53
54     // Plain struct
55     match bag {
56         Large::Suit { case } => {}
57     };
58
59     // Referenced struct
60     match &bag {
61         &Large::Suit { case } => {}
62     };
63
64     // Boxed struct
65     match box bag {
66         box Large::Suit { case } => {}
67     };
68
69     // Tuple with struct
70     match (bag,) {
71         (Large::Suit { case },) => {}
72     };
73
74     // Slice with struct
75     match [bag] {
76         [Large::Suit { case }] => {}
77     };
78
79     // Tuple struct with struct
80     match Tuple(bag, ()) {
81         Tuple(Large::Suit { case }, ()) => {}
82     };
83 }