@@ -1785,7 +1785,8 @@ mod redundant_pattern_match {
1785
1785
use super :: REDUNDANT_PATTERN_MATCHING ;
1786
1786
use clippy_utils:: diagnostics:: span_lint_and_then;
1787
1787
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 ;
1789
1790
use clippy_utils:: ty:: { implements_trait, is_type_diagnostic_item, is_type_lang_item, match_type} ;
1790
1791
use clippy_utils:: { is_lang_ctor, is_qpath_def_path, is_trait_method, paths} ;
1791
1792
use if_chain:: if_chain;
@@ -1795,7 +1796,7 @@ mod redundant_pattern_match {
1795
1796
use rustc_hir:: LangItem :: { OptionNone , OptionSome , PollPending , PollReady , ResultErr , ResultOk } ;
1796
1797
use rustc_hir:: {
1797
1798
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 ,
1799
1800
} ;
1800
1801
use rustc_lint:: LateContext ;
1801
1802
use rustc_middle:: ty:: { self , subst:: GenericArgKind , Ty } ;
@@ -2049,8 +2050,10 @@ mod redundant_pattern_match {
2049
2050
2050
2051
let result_expr = match & let_expr. kind {
2051
2052
ExprKind :: AddrOf ( _, _, borrowed) => borrowed,
2053
+ ExprKind :: Unary ( UnOp :: Deref , deref) => deref,
2052
2054
_ => let_expr,
2053
2055
} ;
2056
+
2054
2057
span_lint_and_then (
2055
2058
cx,
2056
2059
REDUNDANT_PATTERN_MATCHING ,
@@ -2069,12 +2072,15 @@ mod redundant_pattern_match {
2069
2072
// ^^^^^^^^^^^^^^^^^^^
2070
2073
let span = expr_span. until ( op_span. shrink_to_hi ( ) ) ;
2071
2074
2072
- let mut app = if needs_drop {
2075
+ let app = if needs_drop {
2073
2076
Applicability :: MaybeIncorrect
2074
2077
} else {
2075
2078
Applicability :: MachineApplicable
2076
2079
} ;
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 ( ) ;
2078
2084
2079
2085
diag. span_suggestion ( span, "try this" , format ! ( "{} {}.{}" , keyword, sugg, good_method) , app) ;
2080
2086
0 commit comments