Skip to content

Commit 8398eaa

Browse files
committed
temp commit
1 parent 66847ec commit 8398eaa

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

clippy_lints/src/borrow_deref_ref.rs

Lines changed: 15 additions & 5 deletions
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;
@@ -43,6 +45,7 @@ declare_clippy_lint! {
4345
///
4446
/// fn foo(_: &str){ }
4547
/// ```
48+
#[clippy::version = "1.59.0"]
4649
pub BORROW_DEREF_REF,
4750
complexity,
4851
"deref on an immutable reference returns the same type as itself"
@@ -55,19 +58,26 @@ impl LateLintPass<'_> for BorrowDerefRef {
5558
if_chain! {
5659
if !e.span.from_expansion();
5760
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind;
61+
if !addrof_target.span.from_expansion();
5862
if let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind;
5963
if !deref_target.span.from_expansion();
64+
let mut app = Applicability::MachineApplicable;
65+
if let (_, false) =snippet_with_context(cx, deref_target.span , e.span.ctxt() , "..", &mut app);
66+
if let (_, false) =snippet_with_context(cx, deref_target.span , addrof_target.span.ctxt() , "..", &mut app);
67+
if let (_, false) =snippet_with_context(cx, addrof_target.span , e.span.ctxt() , "..", &mut app);
6068
if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) );
6169
let ref_ty = cx.typeck_results().expr_ty(deref_target);
6270
if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind();
6371
then{
6472

6573
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-
}
74+
75+
// let map = cx.tcx.hir();
76+
// let span = map.span(parent_expr.hir_id);
77+
// if span.from_expansion() {
78+
// return;
79+
// }
80+
7181
if matches!(deref_target.kind, ExprKind::Path(..) | ExprKind::Field(..)) {
7282
if matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) {
7383
return;

clippy_lints/src/lib.register_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
208208
LintId::of(needless_bool::NEEDLESS_BOOL),
209209
LintId::of(needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE),
210210
LintId::of(needless_late_init::NEEDLESS_LATE_INIT),
211-
LintId::of(needless_deref::NEEDLESS_DEREF),
211+
LintId::of(borrow_deref_ref::BORROW_DEREF_REF),
212212
LintId::of(needless_option_as_deref::NEEDLESS_OPTION_AS_DEREF),
213213
LintId::of(needless_question_mark::NEEDLESS_QUESTION_MARK),
214214
LintId::of(needless_update::NEEDLESS_UPDATE),

0 commit comments

Comments
 (0)