Skip to content

Commit 98a2524

Browse files
committed
Auto merge of #4487 - JohnTitor:deref-addrof-external-macro, r=flip1995
Don't check across macro boundary in `deref_addrof` Fixes #4289 changelog: Allow `deref_addrof` in macros
2 parents 9d27722 + 9a5b996 commit 98a2524

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clippy_lints/src/reference.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{snippet_with_applicability, span_lint_and_sugg};
1+
use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -38,6 +38,7 @@ impl EarlyLintPass for DerefAddrOf {
3838
if_chain! {
3939
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
4040
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
41+
if !in_macro(addrof_target.span);
4142
then {
4243
let mut applicability = Applicability::MachineApplicable;
4344
span_lint_and_sugg(

tests/ui/deref_addrof_macro.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
macro_rules! m {
2+
($($x:tt),*) => { &[$(($x, stringify!(x)),)*] };
3+
}
4+
5+
#[warn(clippy::deref_addrof)]
6+
fn f() -> [(i32, &'static str); 3] {
7+
*m![1, 2, 3] // should be fine
8+
}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)