2022-03-14 21:48:53 -05:00
|
|
|
// revisions: allowed disallowed
|
|
|
|
//[allowed] check-pass
|
2022-01-18 16:38:17 -06:00
|
|
|
|
2022-08-20 13:40:08 -05:00
|
|
|
#![feature(if_let_guard, let_chains)]
|
2022-03-14 21:48:53 -05:00
|
|
|
#![cfg_attr(allowed, allow(irrefutable_let_patterns))]
|
|
|
|
#![cfg_attr(disallowed, deny(irrefutable_let_patterns))]
|
2022-01-18 16:38:17 -06:00
|
|
|
|
|
|
|
use std::ops::Range;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let opt = Some(None..Some(1));
|
|
|
|
|
2022-03-14 21:48:53 -05:00
|
|
|
if let first = &opt && let Some(ref second) = first && let None = second.start {}
|
|
|
|
//[disallowed]~^ ERROR leading irrefutable pattern in let chain
|
|
|
|
|
|
|
|
// No lint as the irrefutable pattern is surrounded by other stuff
|
|
|
|
if 4 * 2 == 0 && let first = &opt && let Some(ref second) = first && let None = second.start {}
|
|
|
|
|
|
|
|
if let first = &opt && let (a, b) = (1, 2) {}
|
|
|
|
//[disallowed]~^ ERROR irrefutable `if let` patterns
|
|
|
|
|
|
|
|
if let first = &opt && let Some(ref second) = first && let None = second.start && let v = 0 {}
|
|
|
|
//[disallowed]~^ ERROR leading irrefutable pattern in let chain
|
|
|
|
//[disallowed]~^^ ERROR trailing irrefutable pattern in let chain
|
|
|
|
|
|
|
|
if let Some(ref first) = opt && let second = first && let _third = second {}
|
|
|
|
//[disallowed]~^ ERROR trailing irrefutable patterns in let chain
|
|
|
|
|
|
|
|
if let Range { start: local_start, end: _ } = (None..Some(1)) && let None = local_start {}
|
|
|
|
//[disallowed]~^ ERROR leading irrefutable pattern in let chain
|
|
|
|
|
|
|
|
if let (a, b, c) = (Some(1), Some(1), Some(1)) && let None = Some(1) {}
|
|
|
|
//[disallowed]~^ ERROR leading irrefutable pattern in let chain
|
|
|
|
|
|
|
|
if let first = &opt && let None = Some(1) {}
|
|
|
|
//[disallowed]~^ ERROR leading irrefutable pattern in let chain
|
|
|
|
|
2022-01-18 16:38:17 -06:00
|
|
|
if let Some(ref first) = opt
|
|
|
|
&& let Range { start: local_start, end: _ } = first
|
|
|
|
&& let None = local_start {
|
|
|
|
}
|
|
|
|
|
2022-01-19 13:23:44 -06:00
|
|
|
match opt {
|
2022-03-14 21:48:53 -05:00
|
|
|
Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
|
2022-10-13 18:46:24 -05:00
|
|
|
//[disallowed]~^ ERROR irrefutable `if let` guard patterns
|
2022-01-19 13:23:44 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
2022-03-14 21:48:53 -05:00
|
|
|
|
2022-10-13 18:46:24 -05:00
|
|
|
// No error about leading irrefutable patterns: the expr on the rhs might
|
|
|
|
// use the bindings created by the match.
|
2022-01-19 13:23:44 -06:00
|
|
|
match opt {
|
|
|
|
Some(ref first) if let Range { start: local_start, end: _ } = first
|
|
|
|
&& let None = local_start => {},
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2022-10-13 18:46:24 -05:00
|
|
|
match opt {
|
|
|
|
Some(ref first) if let Range { start: Some(_), end: local_end } = first
|
|
|
|
&& let v = local_end && let w = v => {},
|
|
|
|
//[disallowed]~^ ERROR trailing irrefutable patterns in let chain
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No error, despite the prefix being irrefutable: moving out could change the behaviour,
|
|
|
|
// due to possible side effects of the operation.
|
2022-03-14 21:48:53 -05:00
|
|
|
while let first = &opt && let Some(ref second) = first && let None = second.start {}
|
|
|
|
|
|
|
|
while let first = &opt && let (a, b) = (1, 2) {}
|
|
|
|
//[disallowed]~^ ERROR irrefutable `while let` patterns
|
|
|
|
|
|
|
|
while let Some(ref first) = opt && let second = first && let _third = second {}
|
|
|
|
//[disallowed]~^ ERROR trailing irrefutable patterns in let chain
|
|
|
|
|
2022-01-18 16:38:17 -06:00
|
|
|
while let Some(ref first) = opt
|
|
|
|
&& let Range { start: local_start, end: _ } = first
|
|
|
|
&& let None = local_start {
|
|
|
|
}
|
|
|
|
}
|