Skip to content

Commit 5ee0dba

Browse files
committed
fix: match_single_binding suggests wrongly inside tuple
1 parent 55286e7 commit 5ee0dba

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

clippy_lints/src/matches/match_single_binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn expr_in_nested_block(cx: &LateContext<'_>, match_expr: &Expr<'_>) -> bool {
310310
fn expr_must_have_curlies(cx: &LateContext<'_>, match_expr: &Expr<'_>) -> bool {
311311
let parent = cx.tcx.parent_hir_node(match_expr.hir_id);
312312
if let Node::Expr(Expr {
313-
kind: ExprKind::Closure(..) | ExprKind::Binary(..),
313+
kind: ExprKind::Closure(..) | ExprKind::Binary(..) | ExprKind::Tup(..),
314314
..
315315
})
316316
| Node::AnonConst(..) = parent

tests/ui/match_single_binding.fixed

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,22 @@ fn issue15269(a: usize, b: usize, c: usize) -> bool {
266266
a < b
267267
&& b < c
268268
}
269+
270+
#[allow(clippy::blocks_in_conditions, clippy::unused_unit)]
271+
fn issue15537(a: i32, b: i32, nothing: ((), (), ()), x: bool) -> ((), (), ()) {
272+
'scope: {
273+
(
274+
{
275+
let _z = b;
276+
if x {
277+
break 'scope nothing;
278+
}
279+
},
280+
{
281+
{ a };
282+
()
283+
},
284+
(),
285+
)
286+
}
287+
}

tests/ui/match_single_binding.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,22 @@ fn issue15269(a: usize, b: usize, c: usize) -> bool {
343343
(a, b) => b < c,
344344
}
345345
}
346+
347+
#[allow(clippy::blocks_in_conditions, clippy::unused_unit)]
348+
fn issue15537(a: i32, b: i32, nothing: ((), (), ()), x: bool) -> ((), (), ()) {
349+
'scope: {
350+
(
351+
{
352+
let _z = b;
353+
if x {
354+
break 'scope nothing;
355+
}
356+
},
357+
match { a } {
358+
//~^ match_single_binding
359+
_ => (),
360+
},
361+
(),
362+
)
363+
}
364+
}

tests/ui/match_single_binding.stderr

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,22 @@ LL | | (a, b) => b < c,
525525
LL | | }
526526
| |_________^ help: consider using the match body instead: `b < c`
527527

528-
error: aborting due to 37 previous errors
528+
error: this match could be replaced by its scrutinee and body
529+
--> tests/ui/match_single_binding.rs:357:13
530+
|
531+
LL | / match { a } {
532+
LL | |
533+
LL | | _ => (),
534+
LL | | },
535+
| |_____________^
536+
|
537+
help: consider using the scrutinee and body instead
538+
|
539+
LL ~ {
540+
LL + { a };
541+
LL + ()
542+
LL ~ },
543+
|
544+
545+
error: aborting due to 38 previous errors
529546

0 commit comments

Comments
 (0)