|
1 | 1 | use crate::reference::DEREF_ADDROF; |
2 | 2 | use clippy_utils::diagnostics::span_lint_and_then; |
3 | 3 | use clippy_utils::source::snippet_opt; |
| 4 | +use clippy_utils::source::snippet_with_context; |
4 | 5 | use clippy_utils::ty::implements_trait; |
5 | 6 | use clippy_utils::{get_parent_expr, is_lint_allowed}; |
| 7 | +use rustc_errors::Applicability; |
6 | 8 | use rustc_hir::{ExprKind, UnOp}; |
7 | 9 | use rustc_lint::{LateContext, LateLintPass}; |
8 | 10 | use rustc_middle::mir::Mutability; |
@@ -55,19 +57,26 @@ impl LateLintPass<'_> for BorrowDerefRef { |
55 | 57 | if_chain! { |
56 | 58 | if !e.span.from_expansion(); |
57 | 59 | if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind; |
| 60 | + if !addrof_target.span.from_expansion(); |
58 | 61 | if let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind; |
59 | 62 | 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); |
60 | 67 | if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) ); |
61 | 68 | let ref_ty = cx.typeck_results().expr_ty(deref_target); |
62 | 69 | if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind(); |
63 | 70 | then{ |
64 | 71 |
|
65 | 72 | 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 | + |
71 | 80 | if matches!(deref_target.kind, ExprKind::Path(..) | ExprKind::Field(..)) { |
72 | 81 | if matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) { |
73 | 82 | return; |
|
0 commit comments