Skip to content

Commit 01c75e4

Browse files
committed
Added tests for Cow and Result
1 parent b0c2030 commit 01c75e4

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

tests/ui/single_match_else.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,23 @@ fn main() {
9797
return;
9898
},
9999
}
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+
}
100119
}

tests/ui/single_match_else.stderr

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,45 @@ LL + return;
6060
LL + }
6161
|
6262

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
64104

0 commit comments

Comments
 (0)