- if let Some(ref lint_list) = attr.meta_item_list() {
- match &*attr.name().as_str() {
- "allow" | "warn" | "deny" | "forbid" => {
- // whitelist `unused_imports` and `deprecated` for `use` items
- // and `unused_imports` for `extern crate` items with `macro_use`
- for lint in lint_list {
- match item.node {
- ItemKind::Use(..) => {
- if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
- return;
- }
- },
- ItemKind::ExternCrate(..) => {
- if is_word(lint, "unused_imports") && skip_unused_imports {
- return;
- }
- if is_word(lint, "unused_extern_crates") {
- return;
- }
- },
- _ => {},
- }
- }
- let line_span = last_line_of_span(cx, attr.span);
-
- if let Some(mut sugg) = snippet_opt(cx, line_span) {
- if sugg.contains("#[") {
- span_lint_and_then(
- cx,
- USELESS_ATTRIBUTE,
- line_span,
- "useless lint attribute",
- |db| {
- sugg = sugg.replacen("#[", "#![", 1);
- db.span_suggestion_with_applicability(
- line_span,
- "if you just forgot a `!`, use",
- sugg,
- Applicability::MachineApplicable,
- );
+ 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() {
+ "allow" | "warn" | "deny" | "forbid" => {
+ // whitelist `unused_imports` and `deprecated` for `use` items
+ // and `unused_imports` for `extern crate` items with `macro_use`
+ for lint in lint_list {
+ match item.node {
+ ItemKind::Use(..) => {
+ if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
+ return;
+ }
+ },
+ ItemKind::ExternCrate(..) => {
+ if is_word(lint, "unused_imports") && skip_unused_imports {
+ return;
+ }
+ if is_word(lint, "unused_extern_crates") {
+ return;
+ }