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
This commit is contained in:
bors 2019-09-04 15:01:06 +00:00
commit 98a25241cc
2 changed files with 12 additions and 1 deletions

View File

@ -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 if_chain::if_chain;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass}; use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint}; use rustc::{declare_lint_pass, declare_tool_lint};
@ -38,6 +38,7 @@ impl EarlyLintPass for DerefAddrOf {
if_chain! { if_chain! {
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node; if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node; if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
if !in_macro(addrof_target.span);
then { then {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg( span_lint_and_sugg(

View File

@ -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() {}