Skip to content

Commit b41f2e4

Browse files
authored
Emit collapsible_match at the right node (rust-lang#14311)
Fixes rust-lang/rust-clippy#14281 changelog: none
2 parents d993432 + 92fc2bb commit b41f2e4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clippy_lints/src/matches/collapsible_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_then;
1+
use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::higher::IfLetOrMatch;
33
use clippy_utils::msrvs::Msrv;
44
use clippy_utils::source::snippet;
@@ -99,7 +99,7 @@ fn check_arm<'tcx>(
9999
} else {
100100
String::new()
101101
};
102-
span_lint_and_then(cx, COLLAPSIBLE_MATCH, inner_expr.span, msg, |diag| {
102+
span_lint_hir_and_then(cx, COLLAPSIBLE_MATCH, inner_expr.hir_id, inner_expr.span, msg, |diag| {
103103
let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_then_pat.span]);
104104
help_span.push_span_label(binding_span, "replace this binding");
105105
help_span.push_span_label(inner_then_pat.span, format!("with this pattern{replace_msg}"));

tests/ui/collapsible_match.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,18 @@ pub fn test_2(x: Issue9647) {
303303
}
304304
}
305305

306+
// https://github.com/rust-lang/rust-clippy/issues/14281
307+
fn lint_emitted_at_right_node(opt: Option<Result<u64, String>>) {
308+
let n = match opt {
309+
#[expect(clippy::collapsible_match)]
310+
Some(n) => match n {
311+
Ok(n) => n,
312+
_ => return,
313+
},
314+
None => return,
315+
};
316+
}
317+
306318
fn make<T>() -> T {
307319
unimplemented!()
308320
}

0 commit comments

Comments
 (0)