Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit useless_attribute lint in external macros #3932

Merged
merged 1 commit into from Apr 10, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
@@ -8,7 +8,8 @@ use crate::utils::{
use if_chain::if_chain;
use rustc::hir::*;
use rustc::lint::{
CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
in_external_macro, CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray,
LintContext, LintPass,
};
use rustc::ty::{self, TyCtxt};
use rustc::{declare_tool_lint, lint_array};
@@ -241,6 +242,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name("macro_use"));

for attr in &item.attrs {
if in_external_macro(cx.sess(), attr.span) {
return;
}
if let Some(lint_list) = &attr.meta_item_list() {
if let Some(ident) = attr.ident() {
match &*ident.as_str() {
@@ -0,0 +1,17 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_hygiene, proc_macro_quote)]

extern crate proc_macro;

use proc_macro::{quote, TokenStream};

#[proc_macro_derive(DeriveSomething)]
pub fn derive(_: TokenStream) -> TokenStream {
let output = quote! {
#[allow(dead_code)]
extern crate clippy_lints;
};
output
}
@@ -1,3 +1,5 @@
// aux-build:proc_macro_derive.rs

#![warn(clippy::useless_attribute)]

#[allow(dead_code)]
@@ -10,6 +12,9 @@
#[macro_use]
extern crate clippy_lints;

#[macro_use]
extern crate proc_macro_derive;

// don't lint on unused_import for `use` items
#[allow(unused_imports)]
use std::collections;
@@ -22,4 +27,9 @@ mod foo {
#[allow(deprecated)]
pub use foo::Bar;

// This should not trigger the lint. There's lint level definitions inside the external derive
// that would trigger the useless_attribute lint.
#[derive(DeriveSomething)]
struct Baz;

fn main() {}
@@ -1,13 +1,13 @@
error: useless lint attribute
--> $DIR/useless_attribute.rs:3:1
--> $DIR/useless_attribute.rs:5:1
|
LL | #[allow(dead_code)]
| ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]`
|
= note: `-D clippy::useless-attribute` implied by `-D warnings`

error: useless lint attribute
--> $DIR/useless_attribute.rs:4:1
--> $DIR/useless_attribute.rs:6:1
|
LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)`