Skip to content

Commit c5d8828

Browse files
committed
temp commit
1 parent f3f9075 commit c5d8828

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

clippy_lints/src/borrow_deref_ref.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::reference::DEREF_ADDROF;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::source::snippet_opt;
4+
use clippy_utils::source::snippet_with_context;
45
use clippy_utils::ty::implements_trait;
56
use clippy_utils::{get_parent_expr, is_lint_allowed};
7+
use rustc_errors::Applicability;
68
use rustc_hir::{ExprKind, UnOp};
79
use rustc_lint::{LateContext, LateLintPass};
810
use 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

Comments
 (0)