Added tests for Cow and Result

This commit is contained in:
Micha White 2022-06-09 21:39:13 -04:00
parent b0c20302b7
commit 01c75e4b98
No known key found for this signature in database
GPG Key ID: AED94BFA1C301389
2 changed files with 60 additions and 1 deletions

View File

@ -97,4 +97,23 @@ fn main() {
return;
},
}
// lint here
use std::convert::Infallible;
match Result::<i32, Infallible>::Ok(1) {
Ok(a) => println!("${:?}", a),
Err(_) => {
println!("else block");
return;
}
}
use std::borrow::Cow;
match Cow::from("moo") {
Cow::Owned(a) => println!("${:?}", a),
Cow::Borrowed(_) => {
println!("else block");
return;
}
}
}

View File

@ -60,5 +60,45 @@ LL + return;
LL + }
|
error: aborting due to 3 previous errors
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match_else.rs:103:5
|
LL | / match Result::<i32, Infallible>::Ok(1) {
LL | | Ok(a) => println!("${:?}", a),
LL | | Err(_) => {
LL | | println!("else block");
LL | | return;
LL | | }
LL | | }
| |_____^
|
help: try this
|
LL ~ if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else {
LL + println!("else block");
LL + return;
LL + }
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
--> $DIR/single_match_else.rs:112:5
|
LL | / match Cow::from("moo") {
LL | | Cow::Owned(a) => println!("${:?}", a),
LL | | Cow::Borrowed(_) => {
LL | | println!("else block");
LL | | return;
LL | | }
LL | | }
| |_____^
|
help: try this
|
LL ~ if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else {
LL + println!("else block");
LL + return;
LL + }
|
error: aborting due to 5 previous errors