1 // revisions: allowed disallowed
4 #![feature(if_let_guard, let_chains)]
5 #![cfg_attr(allowed, allow(irrefutable_let_patterns))]
6 #![cfg_attr(disallowed, deny(irrefutable_let_patterns))]
11 let opt = Some(None..Some(1));
13 if let first = &opt && let Some(ref second) = first && let None = second.start {}
14 //[disallowed]~^ ERROR leading irrefutable pattern in let chain
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 {}
19 if let first = &opt && let (a, b) = (1, 2) {}
20 //[disallowed]~^ ERROR irrefutable `if let` patterns
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
26 if let Some(ref first) = opt && let second = first && let _third = second {}
27 //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
29 if let Range { start: local_start, end: _ } = (None..Some(1)) && let None = local_start {}
30 //[disallowed]~^ ERROR leading irrefutable pattern in let chain
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
35 if let first = &opt && let None = Some(1) {}
36 //[disallowed]~^ ERROR leading irrefutable pattern in let chain
38 if let Some(ref first) = opt
39 && let Range { start: local_start, end: _ } = first
40 && let None = local_start {
44 Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
45 //[disallowed]~^ ERROR irrefutable `if let` guard patterns
49 // No error about leading irrefutable patterns: the expr on the rhs might
50 // use the bindings created by the match.
52 Some(ref first) if let Range { start: local_start, end: _ } = first
53 && let None = local_start => {},
58 Some(ref first) if let Range { start: Some(_), end: local_end } = first
59 && let v = local_end && let w = v => {},
60 //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
64 // No error, despite the prefix being irrefutable: moving out could change the behaviour,
65 // due to possible side effects of the operation.
66 while let first = &opt && let Some(ref second) = first && let None = second.start {}
68 while let first = &opt && let (a, b) = (1, 2) {}
69 //[disallowed]~^ ERROR irrefutable `while let` patterns
71 while let Some(ref first) = opt && let second = first && let _third = second {}
72 //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
74 while let Some(ref first) = opt
75 && let Range { start: local_start, end: _ } = first
76 && let None = local_start {