Skip to content

Commit

Permalink
Auto merge of #4487 - JohnTitor:deref-addrof-external-macro, r=flip1995
Browse files Browse the repository at this point in the history
Don't check across macro boundary in `deref_addrof`

Fixes #4289

changelog: Allow `deref_addrof` in macros
  • Loading branch information
bors committed Sep 4, 2019
2 parents 9d27722 + 9a5b996 commit 98a2524
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/reference.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{snippet_with_applicability, span_lint_and_sugg};
use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg};
use if_chain::if_chain;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
Expand Down Expand Up @@ -38,6 +38,7 @@ impl EarlyLintPass for DerefAddrOf {
if_chain! {
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
if !in_macro(addrof_target.span);
then {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/deref_addrof_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
macro_rules! m {
($($x:tt),*) => { &[$(($x, stringify!(x)),)*] };
}

#[warn(clippy::deref_addrof)]
fn f() -> [(i32, &'static str); 3] {
*m![1, 2, 3] // should be fine
}

fn main() {}

0 comments on commit 98a2524

Please sign in to comment.