about summary refs log tree commit diff
path: root/clippy_lints/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2024-12-29 23:07:33 +0100
committerSamuel Tardieu <sam@rfc1149.net>2024-12-29 23:25:59 +0100
commite4b11a72665732989fc01f8f140b25469790608b (patch)
tree69beebd295a388f83afb3c1afe309995bc876e1f /clippy_lints/src
parentb57d98b00ec53db774cf18e3d9d6fb28e8f60d0f (diff)
downloadrust-e4b11a72665732989fc01f8f140b25469790608b.tar.gz
rust-e4b11a72665732989fc01f8f140b25469790608b.zip
Fix parentheses when replacing `matches!(…, None)` with `.is_none()`
Diffstat (limited to 'clippy_lints/src')
-rw-r--r--clippy_lints/src/matches/redundant_pattern_match.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs
index 264458a86ef..897e3f5f7f2 100644
--- a/clippy_lints/src/matches/redundant_pattern_match.rs
+++ b/clippy_lints/src/matches/redundant_pattern_match.rs
@@ -1,6 +1,6 @@
 use super::REDUNDANT_PATTERN_MATCHING;
 use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
-use clippy_utils::source::{snippet, walk_span_to_context};
+use clippy_utils::source::walk_span_to_context;
 use clippy_utils::sugg::{Sugg, make_unop};
 use clippy_utils::ty::{is_type_diagnostic_item, needs_ordered_drop};
 use clippy_utils::visitors::{any_temporaries_need_ordered_drop, for_each_expr_without_closures};
@@ -274,7 +274,9 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
                 ExprKind::AddrOf(_, _, borrowed) => borrowed,
                 _ => op,
             };
-            let mut sugg = format!("{}.{good_method}", snippet(cx, result_expr.span, "_"));
+            let mut app = Applicability::MachineApplicable;
+            let receiver_sugg = Sugg::hir_with_applicability(cx, result_expr, "_", &mut app).maybe_par();
+            let mut sugg = format!("{receiver_sugg}.{good_method}");
 
             if let Some(guard) = maybe_guard {
                 // wow, the HIR for match guards in `PAT if let PAT = expr && expr => ...` is annoying!
@@ -307,7 +309,7 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
                 format!("redundant pattern matching, consider using `{good_method}`"),
                 "try",
                 sugg,
-                Applicability::MachineApplicable,
+                app,
             );
         }
     }