@@ -3,6 +3,8 @@ use clippy_utils::diagnostics::span_lint_and_then;
33use clippy_utils:: source:: snippet_opt;
44use clippy_utils:: ty:: implements_trait;
55use clippy_utils:: { get_parent_expr, is_lint_allowed} ;
6+ use rustc_errors:: Applicability ;
7+ use clippy_utils:: source:: snippet_with_context;
68use rustc_hir:: { ExprKind , UnOp } ;
79use rustc_lint:: { LateContext , LateLintPass } ;
810use rustc_middle:: mir:: Mutability ;
@@ -55,19 +57,26 @@ impl LateLintPass<'_> for BorrowDerefRef {
5557 if_chain ! {
5658 if !e. span. from_expansion( ) ;
5759 if let ExprKind :: AddrOf ( _, Mutability :: Not , addrof_target) = e. kind;
60+ if !addrof_target. span. from_expansion( ) ;
5861 if let ExprKind :: Unary ( UnOp :: Deref , deref_target) = addrof_target. kind;
5962 if !deref_target. span. from_expansion( ) ;
63+ let mut app = Applicability :: MachineApplicable ;
64+ if let ( _, false ) =snippet_with_context( cx, deref_target. span , e. span. ctxt( ) , ".." , & mut app) ;
65+ if let ( _, false ) =snippet_with_context( cx, deref_target. span , addrof_target. span. ctxt( ) , ".." , & mut app) ;
66+ if let ( _, false ) =snippet_with_context( cx, addrof_target. span , e. span. ctxt( ) , ".." , & mut app) ;
6067 if !matches!( deref_target. kind, ExprKind :: Unary ( UnOp :: Deref , ..) ) ;
6168 let ref_ty = cx. typeck_results( ) . expr_ty( deref_target) ;
6269 if let ty:: Ref ( _, inner_ty, Mutability :: Not ) = ref_ty. kind( ) ;
6370 then{
6471
6572 if let Some ( parent_expr) = get_parent_expr( cx, e) {
66- let map = cx. tcx. hir( ) ;
67- let span = map. span( parent_expr. hir_id) ;
68- if span. from_expansion( ) {
69- return ;
70- }
73+
74+ // let map = cx.tcx.hir();
75+ // let span = map.span(parent_expr.hir_id);
76+ // if span.from_expansion() {
77+ // return;
78+ // }
79+
7180 if matches!( deref_target. kind, ExprKind :: Path ( ..) | ExprKind :: Field ( ..) ) {
7281 if matches!( parent_expr. kind, ExprKind :: AddrOf ( _, Mutability :: Mut , _) ) {
7382 return ;
0 commit comments