@@ -27,7 +27,9 @@ mod wild_in_or_pats;
2727use clippy_config:: Conf ;
2828use clippy_utils:: msrvs:: { self , Msrv } ;
2929use clippy_utils:: source:: walk_span_to_context;
30- use clippy_utils:: { higher, is_direct_expn_of, is_in_const_context, is_span_match, span_contains_cfg} ;
30+ use clippy_utils:: {
31+ higher, is_direct_expn_of, is_in_const_context, is_span_match, span_contains_cfg, span_extract_comments,
32+ } ;
3133use rustc_hir:: { Arm , Expr , ExprKind , LetStmt , MatchSource , Pat , PatKind } ;
3234use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
3335use rustc_middle:: lint:: in_external_macro;
@@ -1059,7 +1061,28 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
10591061 }
10601062
10611063 redundant_pattern_match:: check_match ( cx, expr, ex, arms) ;
1062- single_match:: check ( cx, ex, arms, expr) ;
1064+ let source_map = cx. tcx . sess . source_map ( ) ;
1065+ let mut match_comments = span_extract_comments ( source_map, expr. span ) ;
1066+ // We remove comments from inside arms block.
1067+ if !match_comments. is_empty ( ) {
1068+ for arm in arms {
1069+ for comment in span_extract_comments ( source_map, arm. body . span ) {
1070+ if let Some ( index) = match_comments
1071+ . iter ( )
1072+ . enumerate ( )
1073+ . find ( |( _, cm) | * * cm == comment)
1074+ . map ( |( index, _) | index)
1075+ {
1076+ match_comments. remove ( index) ;
1077+ }
1078+ }
1079+ }
1080+ }
1081+ // If there are still comments, it means they are outside of the arms, therefore
1082+ // we should not lint.
1083+ if match_comments. is_empty ( ) {
1084+ single_match:: check ( cx, ex, arms, expr) ;
1085+ }
10631086 match_bool:: check ( cx, ex, arms, expr) ;
10641087 overlapping_arms:: check ( cx, ex, arms) ;
10651088 match_wild_enum:: check ( cx, ex, arms) ;
0 commit comments