1
1
//@ revisions: allowed disallowed
2
- //@[allowed] check -pass
2
+ //@ run -pass
3
3
//@ edition: 2024
4
4
5
5
#![ feature( if_let_guard) ]
6
6
#![ cfg_attr( allowed, allow( irrefutable_let_patterns) ) ]
7
7
#![ cfg_attr( disallowed, deny( irrefutable_let_patterns) ) ]
8
+ #![ allow( unused) ]
8
9
9
10
use std:: ops:: Range ;
10
11
11
12
fn main ( ) {
12
13
let opt = Some ( None ..Some ( 1 ) ) ;
13
14
14
15
if let first = & opt && let Some ( second) = first && let None = second. start { }
15
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
16
16
17
17
// No lint as the irrefutable pattern is surrounded by other stuff
18
18
if 4 * 2 == 0 && let first = & opt && let Some ( second) = first && let None = second. start { }
19
19
20
20
if let first = & opt && let ( a, b) = ( 1 , 2 ) { }
21
- //[disallowed]~^ ERROR irrefutable `if let` patterns
22
21
23
22
if let first = & opt && let Some ( second) = first && let None = second. start && let v = 0 { }
24
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
25
- //[disallowed]~^^ ERROR trailing irrefutable pattern in let chain
26
23
27
24
if let Some ( ref first) = opt && let second = first && let _third = second { }
28
- //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
29
25
30
26
if let Range { start : local_start, end : _ } = ( None ..Some ( 1 ) ) && let None = local_start { }
31
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
32
27
33
28
if let ( a, b, c) = ( Some ( 1 ) , Some ( 1 ) , Some ( 1 ) ) && let None = Some ( 1 ) { }
34
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
35
29
36
30
if let first = & opt && let None = Some ( 1 ) { }
37
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
38
31
39
32
if let Some ( ref first) = opt
40
33
&& let Range { start : local_start, end : _ } = first
@@ -43,7 +36,6 @@ fn main() {
43
36
44
37
match opt {
45
38
Some ( ref first) if let second = first && let _third = second && let v = 4 + 4 => { } ,
46
- //[disallowed]~^ ERROR irrefutable `if let` guard patterns
47
39
_ => { }
48
40
}
49
41
@@ -58,23 +50,22 @@ fn main() {
58
50
match opt {
59
51
Some ( ref first) if let Range { start : Some ( _) , end : local_end } = first
60
52
&& let v = local_end && let w = v => { } ,
61
- //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
62
53
_ => { }
63
54
}
64
55
65
56
// No error, despite the prefix being irrefutable: moving out could change the behaviour,
66
57
// due to possible side effects of the operation.
67
- while let first = & opt && let Some ( second) = first && let None = second. start { }
58
+ while let first = & opt && let Some ( second) = first && let None = second. start { break ; }
68
59
69
- while let first = & opt && let ( a, b) = ( 1 , 2 ) { }
70
- //[disallowed]~^ ERROR irrefutable `while let` patterns
60
+ while let first = & opt && let ( a, b) = ( 1 , 2 ) { break ; }
71
61
72
- while let Some ( ref first) = opt && let second = first && let _third = second { }
73
- //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
62
+ while let Some ( ref first) = opt && let second = first && let _third = second { break ; }
74
63
75
64
while let Some ( ref first) = opt
76
65
&& let Range { start : local_start, end : _ } = first
77
- && let None = local_start {
66
+ && let None = local_start
67
+ {
68
+ break ;
78
69
}
79
70
80
71
// No error. An extra nesting level would be required for the `else if`.
@@ -86,13 +77,11 @@ fn main() {
86
77
if opt == Some ( None ..None ) {
87
78
} else if opt. is_some ( )
88
79
&& let x = & opt
89
- //[disallowed]~^ ERROR trailing irrefutable pattern in let chain
90
80
{ }
91
81
92
82
if opt == Some ( None ..None ) {
93
83
} else {
94
84
if let x = opt. clone ( ) . map ( |_| 1 )
95
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
96
85
&& x == Some ( 1 )
97
86
{ }
98
87
}
0 commit comments