@@ -1782,7 +1782,8 @@ mod redundant_pattern_match {
17821782 use super :: REDUNDANT_PATTERN_MATCHING ;
17831783 use clippy_utils:: diagnostics:: span_lint_and_then;
17841784 use clippy_utils:: higher;
1785- use clippy_utils:: source:: { snippet, snippet_with_applicability} ;
1785+ use clippy_utils:: source:: snippet;
1786+ use clippy_utils:: sugg:: Sugg ;
17861787 use clippy_utils:: ty:: { implements_trait, is_type_diagnostic_item, is_type_lang_item, match_type} ;
17871788 use clippy_utils:: { is_lang_ctor, is_qpath_def_path, is_trait_method, paths} ;
17881789 use if_chain:: if_chain;
@@ -1792,7 +1793,7 @@ mod redundant_pattern_match {
17921793 use rustc_hir:: LangItem :: { OptionNone , OptionSome , PollPending , PollReady , ResultErr , ResultOk } ;
17931794 use rustc_hir:: {
17941795 intravisit:: { walk_expr, ErasedMap , NestedVisitorMap , Visitor } ,
1795- Arm , Block , Expr , ExprKind , LangItem , MatchSource , Node , Pat , PatKind , QPath ,
1796+ Arm , Block , Expr , ExprKind , LangItem , MatchSource , Node , Pat , PatKind , QPath , UnOp ,
17961797 } ;
17971798 use rustc_lint:: LateContext ;
17981799 use rustc_middle:: ty:: { self , subst:: GenericArgKind , Ty } ;
@@ -2046,8 +2047,10 @@ mod redundant_pattern_match {
20462047
20472048 let result_expr = match & let_expr. kind {
20482049 ExprKind :: AddrOf ( _, _, borrowed) => borrowed,
2050+ ExprKind :: Unary ( UnOp :: Deref , deref) => deref,
20492051 _ => let_expr,
20502052 } ;
2053+
20512054 span_lint_and_then (
20522055 cx,
20532056 REDUNDANT_PATTERN_MATCHING ,
@@ -2066,12 +2069,15 @@ mod redundant_pattern_match {
20662069 // ^^^^^^^^^^^^^^^^^^^
20672070 let span = expr_span. until ( op_span. shrink_to_hi ( ) ) ;
20682071
2069- let mut app = if needs_drop {
2072+ let app = if needs_drop {
20702073 Applicability :: MaybeIncorrect
20712074 } else {
20722075 Applicability :: MachineApplicable
20732076 } ;
2074- let sugg = snippet_with_applicability ( cx, op_span, "_" , & mut app) ;
2077+
2078+ let sugg = Sugg :: hir_with_macro_callsite ( cx, result_expr, "_" )
2079+ . maybe_par ( )
2080+ . to_string ( ) ;
20752081
20762082 diag. span_suggestion ( span, "try this" , format ! ( "{} {}.{}" , keyword, sugg, good_method) , app) ;
20772083
0 commit comments