Skip to content

Commit dd943fd

Browse files
committed
fix: match_single_binding misses curlies for const
1 parent f39ed7a commit dd943fd

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

clippy_lints/src/matches/match_single_binding.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::fx::FxHashSet;
88
use rustc_errors::Applicability;
99
use rustc_hir::def::Res;
1010
use rustc_hir::intravisit::{Visitor, walk_block, walk_expr, walk_path, walk_stmt};
11-
use rustc_hir::{Arm, Block, Expr, ExprKind, HirId, Node, PatKind, Path, Stmt, StmtKind};
11+
use rustc_hir::{Arm, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, PatKind, Path, Stmt, StmtKind};
1212
use rustc_lint::LateContext;
1313
use rustc_span::{Span, Symbol};
1414

@@ -391,7 +391,12 @@ fn sugg_with_curlies<'a>(
391391
add_curlies();
392392
}
393393
},
394-
Node::Expr(..) | Node::AnonConst(..) => add_curlies(),
394+
Node::Expr(..)
395+
| Node::AnonConst(..)
396+
| Node::Item(Item {
397+
kind: ItemKind::Const(..),
398+
..
399+
}) => add_curlies(),
395400
Node::Arm(arm) if let ExprKind::Match(..) = arm.body.kind => add_curlies(),
396401
_ => {},
397402
}

tests/ui/match_single_binding.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ LL | | }
526526
| |_________^ help: consider using the match body instead: `b < c`
527527

528528
error: this match could be replaced by its scrutinee and body
529-
--> tests/ui/match_single_binding.rs:358:9
529+
--> tests/ui/match_single_binding.rs:357:9
530530
|
531531
LL | / match { a } {
532532
LL | |
@@ -543,7 +543,7 @@ LL ~ },
543543
|
544544

545545
error: this match could be replaced by its scrutinee and body
546-
--> tests/ui/match_single_binding.rs:367:9
546+
--> tests/ui/match_single_binding.rs:366:9
547547
|
548548
LL | / match { a } {
549549
LL | |
@@ -560,7 +560,7 @@ LL ~ },
560560
|
561561

562562
error: this match could be replaced by its scrutinee and body
563-
--> tests/ui/match_single_binding.rs:377:9
563+
--> tests/ui/match_single_binding.rs:376:9
564564
|
565565
LL | / match { a } {
566566
LL | |
@@ -577,7 +577,7 @@ LL ~ },
577577
|
578578

579579
error: this match could be replaced by its scrutinee and body
580-
--> tests/ui/match_single_binding.rs:391:9
580+
--> tests/ui/match_single_binding.rs:390:9
581581
|
582582
LL | / match { a } {
583583
LL | |
@@ -594,7 +594,7 @@ LL ~ },
594594
|
595595

596596
error: this match could be replaced by its scrutinee and body
597-
--> tests/ui/match_single_binding.rs:398:6
597+
--> tests/ui/match_single_binding.rs:397:6
598598
|
599599
LL | -match { a } {
600600
| ______^
@@ -612,7 +612,7 @@ LL ~ };
612612
|
613613

614614
error: this match could be replaced by its scrutinee and body
615-
--> tests/ui/match_single_binding.rs:403:9
615+
--> tests/ui/match_single_binding.rs:402:9
616616
|
617617
LL | _ = match { a } {
618618
| _________^
@@ -628,7 +628,7 @@ LL ~ 1;
628628
|
629629

630630
error: this match could be replaced by its scrutinee and body
631-
--> tests/ui/match_single_binding.rs:408:16
631+
--> tests/ui/match_single_binding.rs:407:16
632632
|
633633
LL | if let x = match { a } {
634634
| ________________^
@@ -646,7 +646,7 @@ LL ~ } {}
646646
|
647647

648648
error: this match could be replaced by its scrutinee and body
649-
--> tests/ui/match_single_binding.rs:413:8
649+
--> tests/ui/match_single_binding.rs:412:8
650650
|
651651
LL | if match { a } {
652652
| ________^
@@ -664,7 +664,7 @@ LL ~ } {
664664
|
665665

666666
error: this match could be replaced by its scrutinee and body
667-
--> tests/ui/match_single_binding.rs:420:15
667+
--> tests/ui/match_single_binding.rs:419:15
668668
|
669669
LL | [1, 2, 3][match { a } {
670670
| _______________^

0 commit comments

Comments
 (0)