Skip to content

Commit 37e9985

Browse files
committed
Auto merge of #8268 - Jarcho:deref_addrof_8247, r=flip1995
Fix `deref_addrof` fixes #8247 This would supersede #8259 changelog: Don't lint `deref_addrof` when the dereference and the borrow occur in different contexts
2 parents 88f5be2 + d32277d commit 37e9985

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

clippy_lints/src/reference.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl EarlyLintPass for DerefAddrOf {
5050
if_chain! {
5151
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind;
5252
if let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind;
53+
if deref_target.span.ctxt() == e.span.ctxt();
5354
if !addrof_target.span.from_expansion();
5455
then {
5556
let mut applicability = Applicability::MachineApplicable;

tests/ui/deref_addrof.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ fn main() {
3737
let b = &a;
3838

3939
let b = *aref;
40+
41+
let _ = unsafe { *core::ptr::addr_of!(a) };
4042
}
4143

4244
#[rustfmt::skip]

tests/ui/deref_addrof.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ fn main() {
3737
let b = *&&a;
3838

3939
let b = **&aref;
40+
41+
let _ = unsafe { *core::ptr::addr_of!(a) };
4042
}
4143

4244
#[rustfmt::skip]

tests/ui/deref_addrof.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ LL | let b = **&aref;
4949
| ^^^^^^ help: try this: `aref`
5050

5151
error: immediately dereferencing a reference
52-
--> $DIR/deref_addrof.rs:45:9
52+
--> $DIR/deref_addrof.rs:47:9
5353
|
5454
LL | *& $visitor
5555
| ^^^^^^^^^^^ help: try this: `$visitor`
@@ -60,7 +60,7 @@ LL | m!(self)
6060
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
6161

6262
error: immediately dereferencing a reference
63-
--> $DIR/deref_addrof.rs:52:9
63+
--> $DIR/deref_addrof.rs:54:9
6464
|
6565
LL | *& mut $visitor
6666
| ^^^^^^^^^^^^^^^ help: try this: `$visitor`

0 commit comments

Comments
 (0)