@@ -1785,7 +1785,8 @@ mod redundant_pattern_match {
17851785 use super :: REDUNDANT_PATTERN_MATCHING ;
17861786 use clippy_utils:: diagnostics:: span_lint_and_then;
17871787 use clippy_utils:: higher;
1788- use clippy_utils:: source:: { snippet, snippet_with_applicability} ;
1788+ use clippy_utils:: source:: snippet;
1789+ use clippy_utils:: sugg:: Sugg ;
17891790 use clippy_utils:: ty:: { implements_trait, is_type_diagnostic_item, is_type_lang_item, match_type} ;
17901791 use clippy_utils:: { is_lang_ctor, is_qpath_def_path, is_trait_method, paths} ;
17911792 use if_chain:: if_chain;
@@ -1795,7 +1796,7 @@ mod redundant_pattern_match {
17951796 use rustc_hir:: LangItem :: { OptionNone , OptionSome , PollPending , PollReady , ResultErr , ResultOk } ;
17961797 use rustc_hir:: {
17971798 intravisit:: { walk_expr, ErasedMap , NestedVisitorMap , Visitor } ,
1798- Arm , Block , Expr , ExprKind , LangItem , MatchSource , Node , Pat , PatKind , QPath ,
1799+ Arm , Block , Expr , ExprKind , LangItem , MatchSource , Node , Pat , PatKind , QPath , UnOp ,
17991800 } ;
18001801 use rustc_lint:: LateContext ;
18011802 use rustc_middle:: ty:: { self , subst:: GenericArgKind , Ty } ;
@@ -2049,8 +2050,10 @@ mod redundant_pattern_match {
20492050
20502051 let result_expr = match & let_expr. kind {
20512052 ExprKind :: AddrOf ( _, _, borrowed) => borrowed,
2053+ ExprKind :: Unary ( UnOp :: Deref , deref) => deref,
20522054 _ => let_expr,
20532055 } ;
2056+
20542057 span_lint_and_then (
20552058 cx,
20562059 REDUNDANT_PATTERN_MATCHING ,
@@ -2069,12 +2072,15 @@ mod redundant_pattern_match {
20692072 // ^^^^^^^^^^^^^^^^^^^
20702073 let span = expr_span. until ( op_span. shrink_to_hi ( ) ) ;
20712074
2072- let mut app = if needs_drop {
2075+ let app = if needs_drop {
20732076 Applicability :: MaybeIncorrect
20742077 } else {
20752078 Applicability :: MachineApplicable
20762079 } ;
2077- let sugg = snippet_with_applicability ( cx, op_span, "_" , & mut app) ;
2080+
2081+ let sugg = Sugg :: hir_with_macro_callsite ( cx, result_expr, "_" )
2082+ . maybe_par ( )
2083+ . to_string ( ) ;
20782084
20792085 diag. span_suggestion ( span, "try this" , format ! ( "{} {}.{}" , keyword, sugg, good_method) , app) ;
20802086
0 commit comments