about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2025-03-22 14:35:24 +0000
committerGitHub <noreply@github.com>2025-03-22 14:35:24 +0000
commitb41f2e4653bcad53a8f678276b669d99afa08dd0 (patch)
treee4987c429a692bcc47c2da1dc048c4b628924911
parentd9934328dd72adcd38beb49d0feed1234fa36474 (diff)
parent92fc2bb2b8e2640baa9f8e6ac73d209e506ec99c (diff)
downloadrust-b41f2e4653bcad53a8f678276b669d99afa08dd0.tar.gz
rust-b41f2e4653bcad53a8f678276b669d99afa08dd0.zip
Emit `collapsible_match` at the right node (#14311)
Fixes https://github.com/rust-lang/rust-clippy/issues/14281

changelog: none
-rw-r--r--clippy_lints/src/matches/collapsible_match.rs4
-rw-r--r--tests/ui/collapsible_match.rs12
2 files changed, 14 insertions, 2 deletions
diff --git a/clippy_lints/src/matches/collapsible_match.rs b/clippy_lints/src/matches/collapsible_match.rs
index 6f446bf9565..5b50efad3e4 100644
--- a/clippy_lints/src/matches/collapsible_match.rs
+++ b/clippy_lints/src/matches/collapsible_match.rs
@@ -1,4 +1,4 @@
-use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::diagnostics::span_lint_hir_and_then;
 use clippy_utils::higher::IfLetOrMatch;
 use clippy_utils::msrvs::Msrv;
 use clippy_utils::source::snippet;
@@ -99,7 +99,7 @@ fn check_arm<'tcx>(
         } else {
             String::new()
         };
-        span_lint_and_then(cx, COLLAPSIBLE_MATCH, inner_expr.span, msg, |diag| {
+        span_lint_hir_and_then(cx, COLLAPSIBLE_MATCH, inner_expr.hir_id, inner_expr.span, msg, |diag| {
             let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_then_pat.span]);
             help_span.push_span_label(binding_span, "replace this binding");
             help_span.push_span_label(inner_then_pat.span, format!("with this pattern{replace_msg}"));
diff --git a/tests/ui/collapsible_match.rs b/tests/ui/collapsible_match.rs
index 796cabd4b66..55ef5584495 100644
--- a/tests/ui/collapsible_match.rs
+++ b/tests/ui/collapsible_match.rs
@@ -303,6 +303,18 @@ pub fn test_2(x: Issue9647) {
     }
 }
 
+// https://github.com/rust-lang/rust-clippy/issues/14281
+fn lint_emitted_at_right_node(opt: Option<Result<u64, String>>) {
+    let n = match opt {
+        #[expect(clippy::collapsible_match)]
+        Some(n) => match n {
+            Ok(n) => n,
+            _ => return,
+        },
+        None => return,
+    };
+}
+
 fn make<T>() -> T {
     unimplemented!()
 }