@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22use clippy_utils:: source:: snippet_with_applicability;
33use clippy_utils:: { path_to_local_id, peel_blocks, strip_pat_refs} ;
44use rustc_errors:: Applicability ;
5- use rustc_hir:: { ExprKind , Local , MatchSource , PatKind , QPath } ;
5+ use rustc_hir:: { ByRef , ExprKind , Local , MatchSource , PatKind , QPath } ;
66use rustc_lint:: LateContext ;
77
88use super :: INFALLIBLE_DESTRUCTURING_MATCH ;
@@ -16,7 +16,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
1616 if let PatKind :: TupleStruct (
1717 QPath :: Resolved ( None , variant_name) , args, _) = arms[ 0 ] . pat. kind;
1818 if args. len( ) == 1 ;
19- if let PatKind :: Binding ( _ , arg, ..) = strip_pat_refs( & args[ 0 ] ) . kind;
19+ if let PatKind :: Binding ( binding , arg, ..) = strip_pat_refs( & args[ 0 ] ) . kind;
2020 let body = peel_blocks( arms[ 0 ] . body) ;
2121 if path_to_local_id( body, arg) ;
2222
@@ -30,8 +30,9 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
3030 Consider using `let`",
3131 "try this" ,
3232 format!(
33- "let {}({}) = {};" ,
33+ "let {}({}{} ) = {};" ,
3434 snippet_with_applicability( cx, variant_name. span, ".." , & mut applicability) ,
35+ if binding. 0 == ByRef :: Yes { "ref " } else { "" } ,
3536 snippet_with_applicability( cx, local. pat. span, ".." , & mut applicability) ,
3637 snippet_with_applicability( cx, target. span, ".." , & mut applicability) ,
3738 ) ,
0 commit comments