diff options
| author | Micha White <botahamec@outlook.com> | 2022-06-09 21:39:13 -0400 |
|---|---|---|
| committer | Micha White <botahamec@outlook.com> | 2022-06-10 13:12:02 -0400 |
| commit | 01c75e4b98c3fe4cb1e6340bfd3148086ba05879 (patch) | |
| tree | a5023782e5c80b90f717e75173354a945cd636c5 | |
| parent | b0c20302b7a647ae362071d72b382b1bd393e4a5 (diff) | |
| download | rust-01c75e4b98c3fe4cb1e6340bfd3148086ba05879.tar.gz rust-01c75e4b98c3fe4cb1e6340bfd3148086ba05879.zip | |
Added tests for Cow and Result
| -rw-r--r-- | tests/ui/single_match_else.rs | 19 | ||||
| -rw-r--r-- | tests/ui/single_match_else.stderr | 42 |
2 files changed, 60 insertions, 1 deletions
diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index 82387f3d80b..70d6febb71f 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -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; + } + } } diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr index dc603578fde..38fd9c6a678 100644 --- a/tests/ui/single_match_else.stderr +++ b/tests/ui/single_match_else.stderr @@ -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 |
