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