Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lengyijun committed Nov 18, 2021
1 parent 9846136 commit e64f4cb
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions clippy_lints/src/borrow_deref_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::implements_trait;
use clippy_utils::{get_parent_expr, is_lint_allowed};
use rustc_errors::Applicability;
use clippy_utils::source::snippet_with_context;
use rustc_hir::{ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::Mutability;
Expand Down Expand Up @@ -55,19 +57,26 @@ impl LateLintPass<'_> for BorrowDerefRef {
if_chain! {
if !e.span.from_expansion();
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind;
if !addrof_target.span.from_expansion();
if let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind;
if !deref_target.span.from_expansion();
let mut app = Applicability::MachineApplicable;
if let (_, false) =snippet_with_context(cx, deref_target.span , e.span.ctxt() , "..", &mut app);
if let (_, false) =snippet_with_context(cx, deref_target.span , addrof_target.span.ctxt() , "..", &mut app);
if let (_, false) =snippet_with_context(cx, addrof_target.span , e.span.ctxt() , "..", &mut app);
if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) );
let ref_ty = cx.typeck_results().expr_ty(deref_target);
if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind();
then{

if let Some(parent_expr) = get_parent_expr(cx, e){
let map = cx.tcx.hir();
let span = map.span(parent_expr.hir_id);
if span.from_expansion() {
return;
}

// let map = cx.tcx.hir();
// let span = map.span(parent_expr.hir_id);
// if span.from_expansion() {
// return;
// }

if matches!(deref_target.kind, ExprKind::Path(..) | ExprKind::Field(..)) {
if matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) {
return;
Expand Down

0 comments on commit e64f4cb

Please sign in to comment.