forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirrefutable-in-let-chains.rs
More file actions
120 lines (94 loc) · 2.84 KB
/
irrefutable-in-let-chains.rs
File metadata and controls
120 lines (94 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// https://github.com/rust-lang/rust/issues/139369
// Test that the lint `irrefutable_let_patterns` now
// only checks single let binding.
//@ edition: 2024
//@ check-pass
use std::ops::Range;
fn main() {
let opt = Some(None..Some(1));
// test `if let`
if let first = &opt {}
//~^ WARN irrefutable `if let` pattern
if let first = &opt && let Some(second) = first {}
if let first = &opt && let (a, b) = (1, 2) {}
if let first = &opt && let None = Some(1) {}
if 4 * 2 == 0 && let first = &opt {}
if let first = &opt
&& let Some(second) = first
&& let None = second.start
&& let v = 0
{}
if let Range { start: local_start, end: _ } = (None..Some(1)) {}
//~^ WARN irrefutable `if let` pattern
if let Range { start: local_start, end: _ } = (None..Some(1))
&& let None = local_start
{}
if let (a, b, c) = (Some(1), Some(1), Some(1)) {}
//~^ WARN irrefutable `if let` pattern
if let (a, b, c) = (Some(1), Some(1), Some(1)) && let None = Some(1) {}
if let Some(ref first) = opt
&& let Range { start: local_start, end: _ } = first
&& let None = local_start
{}
// test `else if let`
if opt == Some(None..None) {
} else if let x = opt.clone().map(|_| 1) {
//~^ WARN irrefutable `if let` pattern
}
if opt == Some(None..None) {
} else if let x = opt.clone().map(|_| 1)
&& x == Some(1)
{}
if opt == Some(None..None) {
} else if opt.is_some() && let x = &opt
{}
if opt == Some(None..None) {
} else {
if let x = opt.clone().map(|_| 1) && x == Some(1)
{}
}
// test `if let guard`
match opt {
Some(ref first) if let second = first => {}
//~^ WARN irrefutable `if let` guard pattern
_ => {}
}
match opt {
Some(ref first)
if let second = first
&& let _third = second
&& let v = 4 + 4 => {}
_ => {}
}
match opt {
Some(ref first)
if let Range { start: local_start, end: _ } = first
&& let None = local_start => {}
_ => {}
}
match opt {
Some(ref first)
if let Range { start: Some(_), end: local_end } = first
&& let v = local_end
&& let w = v => {}
_ => {}
}
// test `while let`
while let first = &opt {}
//~^ WARN irrefutable `while let` pattern
while let first = &opt
&& let (a, b) = (1, 2)
{}
while let first = &opt
&& let Some(second) = first
&& let None = second.start
{}
while let Some(ref first) = opt
&& let second = first
&& let _third = second
{}
while let Some(ref first) = opt
&& let Range { start: local_start, end: _ } = first
&& let None = local_start
{}
}