File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -97,4 +97,23 @@ fn main() {
97
97
return ;
98
98
} ,
99
99
}
100
+
101
+ // lint here
102
+ use std:: convert:: Infallible ;
103
+ match Result :: < i32 , Infallible > :: Ok ( 1 ) {
104
+ Ok ( a) => println ! ( "${:?}" , a) ,
105
+ Err ( _) => {
106
+ println ! ( "else block" ) ;
107
+ return ;
108
+ }
109
+ }
110
+
111
+ use std:: borrow:: Cow ;
112
+ match Cow :: from ( "moo" ) {
113
+ Cow :: Owned ( a) => println ! ( "${:?}" , a) ,
114
+ Cow :: Borrowed ( _) => {
115
+ println ! ( "else block" ) ;
116
+ return ;
117
+ }
118
+ }
100
119
}
Original file line number Diff line number Diff line change @@ -60,5 +60,45 @@ LL + return;
60
60
LL + }
61
61
|
62
62
63
- error: aborting due to 3 previous errors
63
+ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
64
+ --> $DIR/single_match_else.rs:103:5
65
+ |
66
+ LL | / match Result::<i32, Infallible>::Ok(1) {
67
+ LL | | Ok(a) => println!("${:?}", a),
68
+ LL | | Err(_) => {
69
+ LL | | println!("else block");
70
+ LL | | return;
71
+ LL | | }
72
+ LL | | }
73
+ | |_____^
74
+ |
75
+ help: try this
76
+ |
77
+ LL ~ if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else {
78
+ LL + println!("else block");
79
+ LL + return;
80
+ LL + }
81
+ |
82
+
83
+ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
84
+ --> $DIR/single_match_else.rs:112:5
85
+ |
86
+ LL | / match Cow::from("moo") {
87
+ LL | | Cow::Owned(a) => println!("${:?}", a),
88
+ LL | | Cow::Borrowed(_) => {
89
+ LL | | println!("else block");
90
+ LL | | return;
91
+ LL | | }
92
+ LL | | }
93
+ | |_____^
94
+ |
95
+ help: try this
96
+ |
97
+ LL ~ if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else {
98
+ LL + println!("else block");
99
+ LL + return;
100
+ LL + }
101
+ |
102
+
103
+ error: aborting due to 5 previous errors
64
104
You can’t perform that action at this time.
0 commit comments