From 5284af6ec7b1a6957d0380b0eddc7baa67049d36 Mon Sep 17 00:00:00 2001 From: Shashank <109198739+shashu8660@users.noreply.github.com> Date: Sun, 12 Apr 2026 00:41:43 +0530 Subject: [PATCH 1/3] added the UI test for the issue --- tests/ui/match_same_arm_vertical_tab2.rs | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/ui/match_same_arm_vertical_tab2.rs diff --git a/tests/ui/match_same_arm_vertical_tab2.rs b/tests/ui/match_same_arm_vertical_tab2.rs new file mode 100644 index 000000000000..dbef3cc195f9 --- /dev/null +++ b/tests/ui/match_same_arm_vertical_tab2.rs @@ -0,0 +1,89 @@ +#![warn(clippy::match_same_arms)] +#![allow(clippy::manual_range_patterns)] + +// This test ensures `match_same_arms` correctly handles all Rust whitespace. +//@no-rustfix +#[rustfmt::skip] +fn main() { + let x = 1; + + // ================= ASCII WHITESPACE ================= + + // Space + match x { + 1 => println!("same"), //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // Horizontal tab \t + match x { + 1 => println!("same"), /* TAB */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // ================= IMPORTANT BUG TARGET ================= + + // Vertical tab (U+000B) + match x { + 1 => println!("same"), /* VT (U+000B) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // ================= OTHER NON-ASCII WHITESPACE ================= + + // Form feed (U+000C) + match x { + 1 => println!("same"), /* FF (U+000C) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // Next line (U+0085) + match x { + 1 => println!("same"), /* NEL (U+0085) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // ================= UNICODE WHITESPACE ================= + + // Left-to-right mark (U+200E) + match x { + 1 => println!("same"), /* LRM (U+200E) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {} + } + + // Right-to-left mark (U+200F) + match x { + 1 => println!("same"), /* RLM (U+200F) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {} + } + + // Line separator (U+2028) + match x { + 1 => println!("same"), /* LS (U+2028) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // Paragraph separator (U+2029) + match x { + 1 => println!("same"), /* PS (U+2029) */ //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + _ => {}, + } + + // ================= MULTIPLE DUPLICATE ARMS ================= + + match x { + 1 => println!("same"), //~ ERROR: these match arms have identical bodies + 2 => println!("same"), + 3 => println!("same"), + _ => {}, + } +} \ No newline at end of file From e899c4397e1bb987d395dccf33d761d5ec946323 Mon Sep 17 00:00:00 2001 From: Shashank <109198739+shashu8660@users.noreply.github.com> Date: Sun, 12 Apr 2026 00:45:13 +0530 Subject: [PATCH 2/3] before fix no highlight in comma and the tabs --- tests/ui/match_same_arm_vertical_tab2.stderr | 156 +++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 tests/ui/match_same_arm_vertical_tab2.stderr diff --git a/tests/ui/match_same_arm_vertical_tab2.stderr b/tests/ui/match_same_arm_vertical_tab2.stderr new file mode 100644 index 000000000000..8b290e549250 --- /dev/null +++ b/tests/ui/match_same_arm_vertical_tab2.stderr @@ -0,0 +1,156 @@ +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:14:9 + | +LL | 1 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values + = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` +help: otherwise merge the patterns into a single arm + | +LL ~ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:21:9 + | +LL | 1 => println!("same"), /* TAB */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* TAB */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:30:9 + | +LL | 1 => println!("same"), /* VT (U+000B) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* VT (U+000B) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:39:9 + | +LL | 1 => println!("same"), /* FF (U+000C) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* FF (U+000C) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:46:9 + | +LL | 1 => println!("same"), /* NEL (U+0085) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* NEL (U+0085) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:55:9 + | +LL | 1 => println!("same"), /* LRM (U+200E) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* LRM (U+200E) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:62:9 + | +LL | 1 => println!("same"), /* RLM (U+200F) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* RLM (U+200F) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:69:9 + | +LL | 1 => println!("same"), /* LS (U+2028) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* LS (U+2028) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:76:9 + | +LL | 1 => println!("same"), /* PS (U+2029) */ + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ /* PS (U+2029) */ +LL ~ 1 | 2 => println!("same"), + | + +error: these match arms have identical bodies + --> tests/ui/match_same_arm_vertical_tab2.rs:84:9 + | +LL | 1 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 2 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ +LL | 3 => println!("same"), + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: if this is unintentional make the arms return different values +help: otherwise merge the patterns into a single arm + | +LL ~ +LL ~ 1 | 2 | 3 => println!("same"), + | + +error: aborting due to 10 previous errors + From b208bb5f9363dcc0691857e83b2b8871b71e3e55 Mon Sep 17 00:00:00 2001 From: Shashank <109198739+shashu8660@users.noreply.github.com> Date: Sun, 12 Apr 2026 01:02:55 +0530 Subject: [PATCH 3/3] after fix --- clippy_lints/src/matches/match_same_arms.rs | 16 +- tests/ui/match_same_arm_vertical_tab2.rs | 2 +- tests/ui/match_same_arm_vertical_tab2.stderr | 20 +-- tests/ui/match_same_arms.stderr | 75 +++++---- tests/ui/match_same_arms2.stderr | 150 +++++++++--------- .../ui/match_same_arms_non_exhaustive.stderr | 48 +++--- 6 files changed, 163 insertions(+), 148 deletions(-) diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index a8312a04f36f..89a0fa805ac6 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -120,7 +120,19 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { span_lint_and_then( cx, MATCH_SAME_ARMS, - group.iter().map(|(_, arm)| arm.span).collect_vec(), + group + .iter() + .enumerate() // gives index + .map(|(i, (_, arm))| { + // i gives postion of the arm + if i == 0 { + //target only primary arm + adjusted_arm_span(cx, arm.span) //fixes the span to include the comma and whitespaces + } else { + arm.span // other arms keep the original span + } + }) + .collect_vec(), "these match arms have identical bodies", |diag| { diag.help("if this is unintentional make the arms return different values"); @@ -177,7 +189,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { fn adjusted_arm_span(cx: &LateContext<'_>, span: Span) -> Span { let source_map = cx.sess().source_map(); source_map - .span_extend_while(span, |c| c == ',' || c.is_ascii_whitespace()) + .span_extend_while(span, |c| c == ',' || c.is_whitespace()) .unwrap_or(span) } diff --git a/tests/ui/match_same_arm_vertical_tab2.rs b/tests/ui/match_same_arm_vertical_tab2.rs index dbef3cc195f9..3b62dfb28e09 100644 --- a/tests/ui/match_same_arm_vertical_tab2.rs +++ b/tests/ui/match_same_arm_vertical_tab2.rs @@ -86,4 +86,4 @@ fn main() { 3 => println!("same"), _ => {}, } -} \ No newline at end of file +} diff --git a/tests/ui/match_same_arm_vertical_tab2.stderr b/tests/ui/match_same_arm_vertical_tab2.stderr index 8b290e549250..22d5c6b0ee93 100644 --- a/tests/ui/match_same_arm_vertical_tab2.stderr +++ b/tests/ui/match_same_arm_vertical_tab2.stderr @@ -2,7 +2,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:14:9 | LL | 1 => println!("same"), - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -19,7 +19,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:21:9 | LL | 1 => println!("same"), /* TAB */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -34,7 +34,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:30:9 | LL | 1 => println!("same"), /* VT (U+000B) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -49,7 +49,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:39:9 | LL | 1 => println!("same"), /* FF (U+000C) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -64,7 +64,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:46:9 | LL | 1 => println!("same"), /* NEL (U+0085) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -79,7 +79,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:55:9 | LL | 1 => println!("same"), /* LRM (U+200E) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -94,7 +94,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:62:9 | LL | 1 => println!("same"), /* RLM (U+200F) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -109,7 +109,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:69:9 | LL | 1 => println!("same"), /* LS (U+2028) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -124,7 +124,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:76:9 | LL | 1 => println!("same"), /* PS (U+2029) */ - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ | @@ -139,7 +139,7 @@ error: these match arms have identical bodies --> tests/ui/match_same_arm_vertical_tab2.rs:84:9 | LL | 1 => println!("same"), - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ LL | 2 => println!("same"), | ^^^^^^^^^^^^^^^^^^^^^ LL | 3 => println!("same"), diff --git a/tests/ui/match_same_arms.stderr b/tests/ui/match_same_arms.stderr index bd0b7b2871ec..f537c4673624 100644 --- a/tests/ui/match_same_arms.stderr +++ b/tests/ui/match_same_arms.stderr @@ -1,11 +1,11 @@ error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:12:9 | -LL | Abc::A => 0, - | ^^^^^^^^^^^ -LL | Abc::B => 1, -LL | _ => 0, - | ^^^^^^ the wildcard arm +LL | / Abc::A => 0, +LL | | Abc::B => 1, + | |________^ +LL | _ => 0, + | ^^^^^^ the wildcard arm | = help: if this is unintentional make the arms return different values = note: `-D clippy::match-same-arms` implied by `-D warnings` @@ -18,12 +18,11 @@ LL - Abc::A => 0, error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:20:9 | -LL | 2 => 'b', - | ^^^^^^^^ -LL | 3 => 'b', - | ^^^^^^^^ -LL | _ => 'b', - | ^^^^^^^^ the wildcard arm +LL | / 2 => 'b', +LL | | 3 => 'b', + | |________^^^^^^^^^ +LL | _ => 'b', + | ^^^^^^^^ the wildcard arm | = help: if this is unintentional make the arms return different values help: otherwise remove the non-wildcard arms @@ -35,11 +34,11 @@ LL - 3 => 'b', error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:27:9 | -LL | (1, .., 3) => 42, - | ^^^^^^^^^^^^^^^^ -LL | -LL | (.., 3) => 42, - | ^^^^^^^^^^^^^ +LL | / (1, .., 3) => 42, +LL | | + | |________^ +LL | (.., 3) => 42, + | ^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -52,11 +51,11 @@ LL ~ _ => 0, error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:34:9 | -LL | 42 => 1, - | ^^^^^^^ -LL | -LL | 51 => 1, - | ^^^^^^^ +LL | / 42 => 1, +LL | | + | |________^ +LL | 51 => 1, + | ^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -68,11 +67,11 @@ LL ~ 42 | 51 => 1, error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:37:9 | -LL | 41 => 2, - | ^^^^^^^ -LL | -LL | 52 => 2, - | ^^^^^^^ +LL | / 41 => 2, +LL | | + | |________^ +LL | 52 => 2, + | ^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -85,13 +84,13 @@ LL ~ _ => 0, error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:44:9 | -LL | 1 => 2, - | ^^^^^^ -LL | -LL | 2 => 2, - | ^^^^^^ -LL | 3 => 2, - | ^^^^^^ +LL | / 1 => 2, +LL | | + | |________^ +LL | 2 => 2, + | ^^^^^^ +LL | 3 => 2, + | ^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -103,11 +102,11 @@ LL ~ 1 | 2 | 3 => 2, error: these match arms have identical bodies --> tests/ui/match_same_arms.rs:63:17 | -LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | CommandInfo::External { name, .. } => name.to_string(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / CommandInfo::BuiltIn { name, .. } => name.to_string(), +LL | | + | |________________^ +LL | CommandInfo::External { name, .. } => name.to_string(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr index f3031619cce5..4753f8c3f163 100644 --- a/tests/ui/match_same_arms2.stderr +++ b/tests/ui/match_same_arms2.stderr @@ -6,10 +6,9 @@ LL | | foo(); LL | | let mut a = 42 + [23].len() as i32; LL | | if true { ... | -LL | | a LL | | }, - | |_________^ -LL | +LL | | + | |________^ LL | / _ => { LL | | foo(); LL | | let mut a = 42 + [23].len() as i32; @@ -38,11 +37,11 @@ LL - }, error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:39:9 | -LL | 42 => foo(), - | ^^^^^^^^^^^ -LL | -LL | 51 => foo(), - | ^^^^^^^^^^^ +LL | / 42 => foo(), +LL | | + | |________^ +LL | 51 => foo(), + | ^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -54,11 +53,11 @@ LL ~ 42 | 51 => foo(), error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:46:9 | -LL | Some(_) => 24, - | ^^^^^^^^^^^^^ -LL | -LL | None => 24, - | ^^^^^^^^^^ +LL | / Some(_) => 24, +LL | | + | |________^ +LL | None => 24, + | ^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -70,11 +69,11 @@ LL ~ Some(_) | None => 24, error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:69:9 | -LL | (Some(a), None) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | (None, Some(a)) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / (Some(a), None) => bar(a), +LL | | + | |________^ +LL | (None, Some(a)) => bar(a), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -86,11 +85,11 @@ LL ~ (Some(a), None) | (None, Some(a)) => bar(a), error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:84:9 | -LL | (Some(a), None) if a == 42 => a, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | (None, Some(a)) if a == 42 => a, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / (Some(a), None) if a == 42 => a, +LL | | + | |________^ +LL | (None, Some(a)) if a == 42 => a, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -102,11 +101,11 @@ LL ~ (Some(a), None) | (None, Some(a)) if a == 42 => a, error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:91:9 | -LL | (Some(a), ..) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | (.., Some(a)) => bar(a), - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | / (Some(a), ..) => bar(a), +LL | | + | |________^ +LL | (.., Some(a)) => bar(a), + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -119,11 +118,11 @@ LL ~ _ => (), error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:126:9 | -LL | (Ok(x), Some(_)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | (Ok(_), Some(x)) => println!("ok {}", x), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / (Ok(x), Some(_)) => println!("ok {}", x), +LL | | + | |________^ +LL | (Ok(_), Some(x)) => println!("ok {}", x), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -136,11 +135,11 @@ LL ~ _ => println!("err"), error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:142:9 | -LL | Ok(3) => println!("ok"), - | ^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | Ok(_) => println!("ok"), - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | / Ok(3) => println!("ok"), +LL | | + | |________^ +LL | Ok(_) => println!("ok"), + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -155,8 +154,8 @@ error: these match arms have identical bodies LL | / 0 => { LL | | empty!(0); LL | | }, - | |_________^ -LL | +LL | | + | |________^ LL | / 1 => { LL | | empty!(0); LL | | }, @@ -172,11 +171,12 @@ LL ~ 0 | 1 => { error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:222:9 | -LL | Foo::X(0) => 1, - | ^^^^^^^^^^^^^^ -... -LL | Foo::Z(_) => 1, - | ^^^^^^^^^^^^^^ +LL | / Foo::X(0) => 1, +LL | | + | |________^ +LL | Foo::X(_) | Foo::Y(_) => 2, +LL | Foo::Z(_) => 1, + | ^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -190,11 +190,12 @@ LL ~ _ => 0, error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:231:9 | -LL | Foo::X(0) => 1, - | ^^^^^^^^^^^^^^ -... -LL | Foo::Z(_) => 1, - | ^^^^^^^^^^^^^^ +LL | / Foo::X(0) => 1, +LL | | + | |________^ +LL | Foo::Y(_) | Foo::Z(0) => 2, +LL | Foo::Z(_) => 1, + | ^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -207,11 +208,12 @@ LL ~ Foo::X(0) | Foo::Z(_) => 1, error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:254:9 | -LL | Some(Bar { x: 0, y: 5, .. }) => 1, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / Some(Bar { x: 0, y: 5, .. }) => 1, +LL | | + | |________^ ... -LL | Some(Bar { y: 0, x: 5, .. }) => 1, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Some(Bar { y: 0, x: 5, .. }) => 1, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -225,11 +227,11 @@ LL ~ Some(Bar { x: 0, y: 5, .. }) | Some(Bar { y: 0, x: 5, .. }) => 1, error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:271:9 | -LL | 0 => cfg!(not_enable), - | ^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | 1 => cfg!(not_enable), - | ^^^^^^^^^^^^^^^^^^^^^ +LL | / 0 => cfg!(not_enable), +LL | | + | |________^ +LL | 1 => cfg!(not_enable), + | ^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -241,11 +243,11 @@ LL ~ 0 | 1 => cfg!(not_enable), error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:288:17 | -LL | MaybeStaticStr::Static(s) => s, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | MaybeStaticStr::Borrowed(s) => s, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / MaybeStaticStr::Static(s) => s, +LL | | + | |________________^ +LL | MaybeStaticStr::Borrowed(s) => s, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -257,11 +259,11 @@ LL ~ MaybeStaticStr::Static(s) | MaybeStaticStr::Borrowed(s) => error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:306:9 | -LL | 1 => "b", - | ^^^^^^^^ -LL | -LL | 2 => "b", - | ^^^^^^^^ +LL | / 1 => "b", +LL | | + | |________^ +LL | 2 => "b", + | ^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -274,11 +276,11 @@ LL ~ #[allow(clippy::match_same_arms)] error: these match arms have identical bodies --> tests/ui/match_same_arms2.rs:315:9 | -LL | 1 => "b", - | ^^^^^^^^ -LL | -LL | 2 => "b", - | ^^^^^^^^ +LL | / 1 => "b", +LL | | + | |________^ +LL | 2 => "b", + | ^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm diff --git a/tests/ui/match_same_arms_non_exhaustive.stderr b/tests/ui/match_same_arms_non_exhaustive.stderr index 03252f346c6c..d843fa1672ff 100644 --- a/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/tests/ui/match_same_arms_non_exhaustive.stderr @@ -1,11 +1,11 @@ error: these match arms have identical bodies --> tests/ui/match_same_arms_non_exhaustive.rs:16:9 | -LL | Ordering::AcqRel | Ordering::SeqCst => repeat(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | _ => repeat(), - | ^^^^^^^^^^^^^ +LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(), +LL | | + | |________^ +LL | _ => repeat(), + | ^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values = note: `-D clippy::match-same-arms` implied by `-D warnings` @@ -19,11 +19,11 @@ LL ~ Ordering::AcqRel | Ordering::SeqCst | _ => repeat(), error: these match arms have identical bodies --> tests/ui/match_same_arms_non_exhaustive.rs:25:9 | -LL | Ordering::AcqRel => repeat(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | Ordering::SeqCst | _ => repeat(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / Ordering::AcqRel => repeat(), +LL | | + | |________^ +LL | Ordering::SeqCst | _ => repeat(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -35,11 +35,11 @@ LL ~ Ordering::AcqRel | Ordering::SeqCst | _ => repeat(), error: these match arms have identical bodies --> tests/ui/match_same_arms_non_exhaustive.rs:41:13 | -LL | Ordering::AcqRel | Ordering::SeqCst => repeat(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | -LL | _ => repeat(), - | ^^^^^^^^^^^^^ +LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(), +LL | | + | |____________^ +LL | _ => repeat(), + | ^^^^^^^^^^^^^ | = help: if this is unintentional make the arms return different values help: otherwise merge the patterns into a single arm @@ -51,10 +51,11 @@ LL ~ Ordering::AcqRel | Ordering::SeqCst | _ => repeat(), error: these match arms have identical bodies --> tests/ui/match_same_arms_non_exhaustive.rs:55:9 | -LL | Ordering::AcqRel | Ordering::SeqCst => repeat(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => repeat(), - | ^^^^^^^^^^^^^ the wildcard arm +LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(), +LL | | _ => repeat(), + | | ^^^^^^^^^^^^^^ the wildcard arm + | |________| + | | = help: if this is unintentional make the arms return different values help: otherwise remove the non-wildcard arm @@ -65,10 +66,11 @@ LL - Ordering::AcqRel | Ordering::SeqCst => repeat(), error: these match arms have identical bodies --> tests/ui/match_same_arms_non_exhaustive.rs:69:13 | -LL | Ordering::AcqRel | Ordering::SeqCst => repeat(), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => repeat(), - | ^^^^^^^^^^^^^ the wildcard arm +LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(), +LL | | _ => repeat(), + | | ^^^^^^^^^^^^^^ the wildcard arm + | |____________| + | | = help: if this is unintentional make the arms return different values help: otherwise remove the non-wildcard arm