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
This commit is contained in:
bors 2024-10-27 12:37:40 +00:00 committed by Philipp Krones
parent 7b688e21d6
commit 5f4dd1deeb
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
3 changed files with 14 additions and 2 deletions

View file

@ -4,7 +4,7 @@ use clippy_utils::source::SpanRangeExt;
use clippy_utils::ty::implements_trait;
use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed};
use rustc_errors::Applicability;
use rustc_hir::{ExprKind, UnOp};
use rustc_hir::{BorrowKind, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::Mutability;
use rustc_middle::ty;
@ -49,7 +49,7 @@ declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]);
impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, addrof_target) = e.kind
&& let ExprKind::Unary(UnOp::Deref, deref_target) = addrof_target.kind
&& !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..))
&& !e.span.from_expansion()

View file

@ -71,3 +71,9 @@ mod false_negative {
assert_ne!(addr_x, addr_y);
}
}
fn issue_13584() {
let s = "Hello, world!\n";
let p = &raw const *s;
let _ = p as *const i8;
}

View file

@ -71,3 +71,9 @@ mod false_negative {
assert_ne!(addr_x, addr_y);
}
}
fn issue_13584() {
let s = "Hello, world!\n";
let p = &raw const *s;
let _ = p as *const i8;
}