diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 30115c60572..8945e4f6c26 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -86,8 +86,8 @@ impl LintPass for AttrPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) { - if let MetaItemKind::List(ref items) = attr.value.node { - if items.is_empty() || attr.name() != "deprecated" { + if let Some(ref items) = attr.meta_item_list() { + if items.is_empty() || attr.name().map_or(true, |n| n != "deprecated") { return; } for item in items { @@ -110,31 +110,33 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass { ItemExternCrate(_) | ItemUse(_, _) => { for attr in &item.attrs { - if let MetaItemKind::List(ref lint_list) = attr.value.node { - match &*attr.name().as_str() { - "allow" | "warn" | "deny" | "forbid" => { - // whitelist `unused_imports` and `deprecated` - for lint in lint_list { - if is_word(lint, "unused_imports") || is_word(lint, "deprecated") { - if let ItemUse(_, _) = item.node { - return; + if let Some(ref lint_list) = attr.meta_item_list() { + if let Some(name) = attr.name() { + match &*name.as_str() { + "allow" | "warn" | "deny" | "forbid" => { + // whitelist `unused_imports` and `deprecated` + for lint in lint_list { + if is_word(lint, "unused_imports") || is_word(lint, "deprecated") { + if let ItemUse(_, _) = item.node { + return; + } } } - } - if let Some(mut sugg) = snippet_opt(cx, attr.span) { - if sugg.len() > 1 { - span_lint_and_then(cx, - USELESS_ATTRIBUTE, - attr.span, - "useless lint attribute", - |db| { - sugg.insert(1, '!'); - db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg); - }); + if let Some(mut sugg) = snippet_opt(cx, attr.span) { + if sugg.len() > 1 { + span_lint_and_then(cx, + USELESS_ATTRIBUTE, + attr.span, + "useless lint attribute", + |db| { + sugg.insert(1, '!'); + db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg); + }); + } } - } - }, - _ => {}, + }, + _ => {}, + } } } } @@ -218,8 +220,8 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) { } for attr in attrs { - if let MetaItemKind::List(ref values) = attr.value.node { - if values.len() != 1 || attr.name() != "inline" { + if let Some(ref values) = attr.meta_item_list() { + if values.len() != 1 || attr.name().map_or(true, |n| n != "inline") { continue; } if is_word(&values[0], "always") { diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 72a4b3458fb..816ec8b6b17 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -89,11 +89,9 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a for attr in attrs { if attr.is_sugared_doc { - if let ast::MetaItemKind::NameValue(ref doc) = attr.value.node { - if let ast::LitKind::Str(ref doc, _) = doc.node { + if let Some(ref doc) = attr.value_str() { let doc = (*doc.as_str()).to_owned(); docs.extend_from_slice(&strip_doc_comment_decoration((doc, attr.span))); - } } } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 881d210a28d..c78804240ee 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -9,7 +9,6 @@ #![feature(slice_patterns)] #![feature(stmt_expr_attributes)] #![feature(conservative_impl_trait)] -#![feature(collections_bound)] #![allow(indexing_slicing, shadow_reuse, unknown_lints, missing_docs_in_private_items)] #![allow(needless_lifetimes)] diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 348e66a679e..75cc588119f 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -77,7 +77,7 @@ impl MissingDoc { return; } - let has_doc = attrs.iter().any(|a| a.is_value_str() && a.name() == "doc"); + let has_doc = attrs.iter().any(|a| a.is_value_str() && a.name().map_or(false, |n| n == "doc")); if !has_doc { cx.span_lint(MISSING_DOCS_IN_PRIVATE_ITEMS, sp, diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 403ab64f440..a2639d35526 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -150,8 +150,8 @@ impl EarlyLintPass for ReturnPass { } fn attr_is_cfg(attr: &ast::Attribute) -> bool { - if let ast::MetaItemKind::List(_) = attr.value.node { - attr.name() == "cfg" + if attr.meta_item_list().is_some() { + attr.name().map_or(false, |n| n == "cfg") } else { false } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 58b416b8325..992fdab80b0 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -678,17 +678,13 @@ fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &' if attr.is_sugared_doc { continue; } - if let ast::MetaItemKind::NameValue(ref value) = attr.value.node { - if attr.name() == name { - if let LitKind::Str(ref s, _) = value.node { - if let Ok(value) = FromStr::from_str(&*s.as_str()) { - attr::mark_used(attr); - f(value) - } else { - sess.span_err(value.span, "not a number"); - } + if let Some(ref value) = attr.value_str() { + if attr.name().map_or(false, |n| n == name) { + if let Ok(value) = FromStr::from_str(&*value.as_str()) { + attr::mark_used(attr); + f(value) } else { - unreachable!() + sess.span_err(attr.span, "not a number"); } } } diff --git a/tests/matches.rs b/tests/matches.rs index fade73aad03..506926501a2 100644 --- a/tests/matches.rs +++ b/tests/matches.rs @@ -1,5 +1,4 @@ #![feature(rustc_private)] -#![feature(collections_bound)] extern crate clippy_lints; extern crate syntax;