From f8df4aed0f73aff51a5ab7eb9c6e8d8d57012bf9 Mon Sep 17 00:00:00 2001 From: Enrico Schmitz Date: Mon, 20 Mar 2017 23:51:14 +0100 Subject: [PATCH 1/3] Fix for rustc 1.17.0-nightly (6eb9960d3 2017-03-19) --- clippy_lints/src/attrs.rs | 54 +++++++++++++++++---------------- clippy_lints/src/doc.rs | 4 +-- clippy_lints/src/lib.rs | 1 - clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/returns.rs | 4 +-- clippy_lints/src/utils/mod.rs | 16 ++++------ tests/matches.rs | 1 - 7 files changed, 38 insertions(+), 44 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 30115c605..8945e4f6c 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 72a4b3458..816ec8b6b 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 881d210a2..c78804240 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 348e66a67..75cc58811 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 403ab64f4..a2639d355 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 58b416b83..992fdab80 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 fade73aad..506926501 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; From fa0a6702010e9717bfbe7b8cfa8f26979b6266fc Mon Sep 17 00:00:00 2001 From: Enrico Schmitz Date: Tue, 21 Mar 2017 00:34:05 +0100 Subject: [PATCH 2/3] Simplify attr_is_cfg in returns.rs --- clippy_lints/src/returns.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index a2639d355..031e3f8cf 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -150,9 +150,5 @@ impl EarlyLintPass for ReturnPass { } fn attr_is_cfg(attr: &ast::Attribute) -> bool { - if attr.meta_item_list().is_some() { - attr.name().map_or(false, |n| n == "cfg") - } else { - false - } + attr.meta_item_list().is_some() && attr.name().map_or(false, |n| n == "cfg") } From b409356a04d1cb89ac47e4aa6353441750dacdd9 Mon Sep 17 00:00:00 2001 From: Enrico Schmitz Date: Tue, 21 Mar 2017 00:52:52 +0100 Subject: [PATCH 3/3] Fix appveyor curl path --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index d83d3478c..c17b12a33 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,6 +12,7 @@ environment: MSYS2_BITS: 64 install: + - set PATH=C:\Program Files\Git\mingw64\bin;%PATH% - curl -sSf -o rustup-init.exe https://win.rustup.rs/ - rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin;C:\Users\appveyor\.rustup\toolchains\nightly-%TARGET%\bin