diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 862272456ea..04874e60224 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -203,14 +203,10 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) { db.span_note(i.body.span, "same as this"); // Note: this does not use `span_suggestion` on purpose: there is no clean way - // to - // remove the other arm. Building a span and suggest to replace it to "" makes - // an - // even more confusing error message. Also in order not to make up a span for - // the - // whole pattern, the suggestion is only shown when there is only one pattern. - // The - // user should know about `|` if they are already using it… + // to remove the other arm. Building a span and suggest to replace it to "" + // makes an even more confusing error message. Also in order not to make up a + // span for the whole pattern, the suggestion is only shown when there is only + // one pattern. The user should know about `|` if they are already using it… if i.pats.len() == 1 && j.pats.len() == 1 { let lhs = snippet(cx, i.pats[0].span, ""); diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs index f97038ca1f0..f15a57c4f85 100644 --- a/tests/ui/matches.rs +++ b/tests/ui/matches.rs @@ -277,6 +277,26 @@ fn match_wild_err_arm() { Ok(_) => println!("ok"), Err(_) => {unreachable!();} } + + // no warning because of the guard + match x { + Ok(x) if x*x == 64 => println!("ok"), + Ok(_) => println!("ok"), + Err(_) => println!("err") + } + + match (x, Some(1i32)) { + (Ok(x), Some(_)) => println!("ok {}", x), + (Ok(_), Some(x)) => println!("ok {}", x), + _ => println!("err") + } + + // no warning because of the different types for x + match (x, Some(1.0f64)) { + (Ok(x), Some(_)) => println!("ok {}", x), + (Ok(_), Some(x)) => println!("ok {}", x), + _ => println!("err") + } } fn main() { diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index bcb94bab26c..cc7c5a4fee2 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -390,3 +390,21 @@ note: consider refactoring into `Ok(3) | Ok(_)` | ^^^^^^^^^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) +error: this `match` has identical arm bodies + --> $DIR/matches.rs:290:29 + | +290 | (Ok(_), Some(x)) => println!("ok {}", x), + | ^^^^^^^^^^^^^^^^^^^^ + | +note: same as this + --> $DIR/matches.rs:289:29 + | +289 | (Ok(x), Some(_)) => println!("ok {}", x), + | ^^^^^^^^^^^^^^^^^^^^ +note: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` + --> $DIR/matches.rs:289:29 + | +289 | (Ok(x), Some(_)) => println!("ok {}", x), + | ^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) +