@@ -18,34 +18,38 @@ enum ExprNode {
18
18
19
19
static NODE : ExprNode = ExprNode :: Unicorns ;
20
20
21
+ fn dummy ( ) {
22
+ }
23
+
21
24
fn unwrap_addr ( ) -> Option < & ' static ExprNode > {
22
- match ExprNode :: Butterflies { //~ ERROR you seem to be trying to use match
23
- //~^ HELP try
25
+ match ExprNode :: Butterflies {
26
+ //~^ ERROR you seem to be trying to use match
27
+ //~| HELP try
28
+ //~| SUGGESTION if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { let x = 5; None }
24
29
ExprNode :: ExprAddrOf => Some ( & NODE ) ,
25
- _ => {
26
- let x = 5 ;
27
- None
28
- } ,
30
+ _ => { let x = 5 ; None } ,
29
31
}
30
32
}
31
33
32
34
fn single_match ( ) {
33
35
let x = Some ( 1u8 ) ;
34
36
35
- match x { //~ ERROR you seem to be trying to use match
36
- //~^ HELP try
37
- Some ( y ) => {
38
- println ! ( "{:?}" , y) ;
39
- }
37
+ match x {
38
+ //~^ ERROR you seem to be trying to use match
39
+ //~| HELP try
40
+ //~| SUGGESTION if let Some(y) = x { println!("{:?}", y); } ;
41
+ Some ( y ) => { println ! ( "{:?}" , y ) ; }
40
42
_ => ( )
41
- }
43
+ } ;
42
44
43
45
let z = ( 1u8 , 1u8 ) ;
44
- match z { //~ ERROR you seem to be trying to use match
45
- //~^ HELP try
46
- ( 2 ...3 , 7 ...9 ) => println ! ( "{:?}" , z) ,
46
+ match z {
47
+ //~^ ERROR you seem to be trying to use match
48
+ //~| HELP try
49
+ //~| SUGGESTION if let (2...3, 7...9) = z { dummy() };
50
+ ( 2 ...3 , 7 ...9 ) => dummy ( ) ,
47
51
_ => { }
48
- }
52
+ } ;
49
53
50
54
// Not linted (pattern guards used)
51
55
match x {
@@ -64,25 +68,31 @@ fn single_match_know_enum() {
64
68
let x = Some ( 1u8 ) ;
65
69
let y : Result < _ , i8 > = Ok ( 1i8 ) ;
66
70
67
- match x { //~ ERROR you seem to be trying to use match
68
- //~^ HELP try
69
- Some ( y) => println ! ( "{:?}" , y) ,
71
+ match x {
72
+ //~^ ERROR you seem to be trying to use match
73
+ //~| HELP try
74
+ //~| SUGGESTION if let Some(y) = x { dummy() };
75
+ Some ( y) => dummy ( ) ,
70
76
None => ( )
71
- }
77
+ } ;
72
78
73
- match y { //~ ERROR you seem to be trying to use match
74
- //~^ HELP try
75
- Ok ( y) => println ! ( "{:?}" , y) ,
79
+ match y {
80
+ //~^ ERROR you seem to be trying to use match
81
+ //~| HELP try
82
+ //~| SUGGESTION if let Ok(y) = y { dummy() };
83
+ Ok ( y) => dummy ( ) ,
76
84
Err ( ..) => ( )
77
- }
85
+ } ;
78
86
79
87
let c = Cow :: Borrowed ( "" ) ;
80
88
81
- match c { //~ ERROR you seem to be trying to use match
82
- //~^ HELP try
83
- Cow :: Borrowed ( ..) => println ! ( "42" ) ,
89
+ match c {
90
+ //~^ ERROR you seem to be trying to use match
91
+ //~| HELP try
92
+ //~| SUGGESTION if let Cow::Borrowed(..) = c { dummy() };
93
+ Cow :: Borrowed ( ..) => dummy ( ) ,
84
94
Cow :: Owned ( ..) => ( ) ,
85
- }
95
+ } ;
86
96
87
97
let z = Foo :: Bar ;
88
98
// no warning
@@ -209,19 +219,19 @@ fn overlapping() {
209
219
210
220
match 42 {
211
221
0 ... 10 => println ! ( "0 ... 10" ) , //~ERROR: some ranges overlap
212
- 0 ... 11 => println ! ( "0 ... 10" ) ,
222
+ 0 ... 11 => println ! ( "0 ... 10" ) , //~NOTE overlaps with this
213
223
_ => ( ) ,
214
224
}
215
225
216
226
match 42 {
217
227
0 ... 5 => println ! ( "0 ... 5" ) , //~ERROR: some ranges overlap
218
228
6 ... 7 => println ! ( "6 ... 7" ) ,
219
- FOO ... 11 => println ! ( "0 ... 10" ) ,
229
+ FOO ... 11 => println ! ( "0 ... 10" ) , //~NOTE overlaps with this
220
230
_ => ( ) ,
221
231
}
222
232
223
233
match 42 {
224
- 2 => println ! ( "2" ) ,
234
+ 2 => println ! ( "2" ) , //~NOTE overlaps with this
225
235
0 ... 5 => println ! ( "0 ... 5" ) , //~ERROR: some ranges overlap
226
236
_ => ( ) ,
227
237
}
0 commit comments