Skip to content

Commit

Permalink
Don't lint deref_addrof when the two operations occur in different …
Browse files Browse the repository at this point in the history
…expansions
  • Loading branch information
Jarcho committed Jan 12, 2022
1 parent 88f5be2 commit d32277d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl EarlyLintPass for DerefAddrOf {
if_chain! {
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind;
if let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind;
if deref_target.span.ctxt() == e.span.ctxt();
if !addrof_target.span.from_expansion();
then {
let mut applicability = Applicability::MachineApplicable;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/deref_addrof.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ fn main() {
let b = &a;

let b = *aref;

let _ = unsafe { *core::ptr::addr_of!(a) };
}

#[rustfmt::skip]
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/deref_addrof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ fn main() {
let b = *&&a;

let b = **&aref;

let _ = unsafe { *core::ptr::addr_of!(a) };
}

#[rustfmt::skip]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/deref_addrof.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ LL | let b = **&aref;
| ^^^^^^ help: try this: `aref`

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

error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:52:9
--> $DIR/deref_addrof.rs:54:9
|
LL | *& mut $visitor
| ^^^^^^^^^^^^^^^ help: try this: `$visitor`
Expand Down

0 comments on commit d32277d

Please sign in to comment.