Allow deref_addrof in macros

This commit is contained in:
Yuki Okushi 2019-09-02 23:26:04 +09:00
parent a3fcaee562
commit 9a5b996228
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() {}