Added tests for Cow and Result
This commit is contained in:
parent
b0c20302b7
commit
01c75e4b98
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user