Skip to content

Commit 5f4dd1d

Browse files
borsflip1995
authored andcommitted
Auto merge of #13600 - samueltardieu:push-tzuvnutssmrs, r=xFrednet
borrow_deref_ref: do not trigger on `&raw` references changelog: [`borrow_deref_ref`]: do not trigger on `&raw` references Fix #13584
1 parent 7b688e2 commit 5f4dd1d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::source::SpanRangeExt;
44
use clippy_utils::ty::implements_trait;
55
use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed};
66
use rustc_errors::Applicability;
7-
use rustc_hir::{ExprKind, UnOp};
7+
use rustc_hir::{BorrowKind, ExprKind, UnOp};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::mir::Mutability;
1010
use rustc_middle::ty;
@@ -49,7 +49,7 @@ declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]);
4949

5050
impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
5151
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
52-
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind
52+
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, addrof_target) = e.kind
5353
&& let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind
5454
&& !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..))
5555
&& !e.span.from_expansion()

src/tools/clippy/tests/ui/borrow_deref_ref.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ mod false_negative {
7171
assert_ne!(addr_x, addr_y);
7272
}
7373
}
74+
75+
fn issue_13584() {
76+
let s = "Hello, world!\n";
77+
let p = &raw const *s;
78+
let _ = p as *const i8;
79+
}

src/tools/clippy/tests/ui/borrow_deref_ref.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ mod false_negative {
7171
assert_ne!(addr_x, addr_y);
7272
}
7373
}
74+
75+
fn issue_13584() {
76+
let s = "Hello, world!\n";
77+
let p = &raw const *s;
78+
let _ = p as *const i8;
79+
}

0 commit comments

Comments
 (0)