]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
Auto merge of #89123 - the8472:push_in_capacity, r=amanieu
[rust.git] / src / test / ui / rfc-2497-if-let-chains / irrefutable-lets.rs
1 // revisions: allowed disallowed
2 //[allowed] check-pass
3
4 #![feature(if_let_guard, let_chains)]
5 #![cfg_attr(allowed, allow(irrefutable_let_patterns))]
6 #![cfg_attr(disallowed, deny(irrefutable_let_patterns))]
7
8 use std::ops::Range;
9
10 fn main() {
11     let opt = Some(None..Some(1));
12
13     if let first = &opt && let Some(ref second) = first && let None = second.start {}
14     //[disallowed]~^ ERROR leading irrefutable pattern in let chain
15
16     // No lint as the irrefutable pattern is surrounded by other stuff
17     if 4 * 2 == 0 && let first = &opt && let Some(ref second) = first && let None = second.start {}
18
19     if let first = &opt && let (a, b) = (1, 2) {}
20     //[disallowed]~^ ERROR irrefutable `if let` patterns
21
22     if let first = &opt && let Some(ref second) = first && let None = second.start && let v = 0 {}
23     //[disallowed]~^ ERROR leading irrefutable pattern in let chain
24     //[disallowed]~^^ ERROR trailing irrefutable pattern in let chain
25
26     if let Some(ref first) = opt && let second = first && let _third = second {}
27     //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
28
29     if let Range { start: local_start, end: _ } = (None..Some(1)) && let None = local_start {}
30     //[disallowed]~^ ERROR leading irrefutable pattern in let chain
31
32     if let (a, b, c) = (Some(1), Some(1), Some(1)) && let None = Some(1) {}
33     //[disallowed]~^ ERROR leading irrefutable pattern in let chain
34
35     if let first = &opt && let None = Some(1) {}
36     //[disallowed]~^ ERROR leading irrefutable pattern in let chain
37
38     if let Some(ref first) = opt
39         && let Range { start: local_start, end: _ } = first
40         && let None = local_start {
41     }
42
43     match opt {
44         Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
45         //[disallowed]~^ ERROR irrefutable `let` patterns
46         _ => {}
47     }
48
49     match opt {
50         Some(ref first) if let Range { start: local_start, end: _ } = first
51         //[disallowed]~^ ERROR leading irrefutable pattern in let chain
52             && let None = local_start => {},
53         _ => {}
54     }
55
56     // No error, despite the prefix being irrefutable
57     while let first = &opt && let Some(ref second) = first && let None = second.start {}
58
59     while let first = &opt && let (a, b) = (1, 2) {}
60     //[disallowed]~^ ERROR irrefutable `while let` patterns
61
62     while let Some(ref first) = opt && let second = first && let _third = second {}
63     //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
64
65     while let Some(ref first) = opt
66         && let Range { start: local_start, end: _ } = first
67         && let None = local_start {
68     }
69 }