From 3f43996aa5b9163195039b45fa74a3c4635a90cd Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 28 Aug 2016 17:54:32 +0200 Subject: [PATCH 1/5] Rustup to *1.13.0-nightly (eac41469d 2016-08-30)* --- clippy_lints/src/attrs.rs | 37 ++++++++++++-------- clippy_lints/src/missing_doc.rs | 5 +-- clippy_lints/src/unsafe_removed_from_name.rs | 4 +-- clippy_lints/src/utils/conf.rs | 6 ++-- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 086716c1f464..7a36049178b0 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -4,7 +4,7 @@ use reexport::*; use rustc::lint::*; use rustc::hir::*; use semver::Version; -use syntax::ast::{Attribute, Lit, LitKind, MetaItemKind}; +use syntax::ast::{Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; use syntax::codemap::Span; use utils::{in_macro, match_path, span_lint, span_lint_and_then, snippet_opt}; use utils::paths; @@ -89,11 +89,13 @@ impl LateLintPass for AttrPass { return; } for item in items { - if let MetaItemKind::NameValue(ref name, ref lit) = item.node { - if name == &"since" { - check_semver(cx, item.span, lit); - } - } + if_let_chain! {[ + let NestedMetaItemKind::MetaItem(ref mi) = item.node, + let MetaItemKind::NameValue(ref name, ref lit) = mi.node, + name == &"since", + ], { + check_semver(cx, item.span, lit); + }} } } } @@ -111,11 +113,9 @@ impl LateLintPass for AttrPass { "allow" | "warn" | "deny" | "forbid" => { // whitelist `unused_imports` for lint in lint_list { - if let MetaItemKind::Word(ref word) = lint.node { - if word == "unused_imports" { - if let ItemUse(_) = item.node { - return; - } + if is_word(lint, "unused_imports") { + if let ItemUse(_) = item.node { + return; } } } @@ -214,10 +214,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) { if values.len() != 1 || inline != &"inline" { continue; } - if let MetaItemKind::Word(ref always) = values[0].node { - if always != &"always" { - continue; - } + if is_word(&values[0], "always") { span_lint(cx, INLINE_ALWAYS, attr.span, @@ -239,3 +236,13 @@ fn check_semver(cx: &LateContext, span: Span, lit: &Lit) { span, "the since field must contain a semver-compliant version"); } + +fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool { + if let NestedMetaItemKind::MetaItem(ref mi) = nmi.node { + if let MetaItemKind::Word(ref word) = mi.node { + return word == expected; + } + } + + false +} diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 0871f5ab5755..454f591756bb 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -21,7 +21,7 @@ use rustc::hir; use rustc::lint::*; use rustc::ty; use syntax::ast; -use syntax::attr::{self, AttrMetaMethods}; +use syntax::attr; use syntax::codemap::Span; use utils::in_macro; @@ -99,7 +99,7 @@ impl LateLintPass for MissingDoc { let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| { attr.check_name("doc") && match attr.meta_item_list() { None => false, - Some(l) => attr::contains_name(&l[..], "hidden"), + Some(l) => attr::list_contains_name(&l[..], "hidden"), } }); self.doc_hidden_stack.push(doc_hidden); @@ -123,6 +123,7 @@ impl LateLintPass for MissingDoc { hir::ItemStruct(..) => "a struct", hir::ItemTrait(..) => "a trait", hir::ItemTy(..) => "a type alias", + hir::ItemUnion(..) => "a union", hir::ItemDefaultImpl(..) | hir::ItemExternCrate(..) | hir::ItemForeignMod(..) | diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 8d5e01db570f..488ca5c8a62b 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -51,8 +51,8 @@ impl LateLintPass for UnsafeNameRemoval { ViewPath_::ViewPathList(_, ref path_list_items) => { for path_list_item in path_list_items.iter() { let plid = path_list_item.node; - if let (Some(name), Some(rename)) = (plid.name(), plid.rename()) { - unsafe_to_safe_check(name, rename, cx, &item.span); + if let Some(rename) = plid.rename { + unsafe_to_safe_check(plid.name, rename, cx, &item.span); }; } } diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 748d144daa0d..f9a93ed3f6ee 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -4,13 +4,13 @@ use std::{fmt, fs, io}; use std::io::Read; -use syntax::{ast, codemap, ptr}; +use syntax::{ast, codemap}; use syntax::parse::token; use toml; /// Get the configuration file from arguments. -pub fn file(args: &[ptr::P]) -> Result, (&'static str, codemap::Span)> { - for arg in args { +pub fn file(args: &[codemap::Spanned]) -> Result, (&'static str, codemap::Span)> { + for arg in args.iter().filter_map(|a| a.meta_item()) { match arg.node { ast::MetaItemKind::Word(ref name) | ast::MetaItemKind::List(ref name, _) => { From ee3f3bf2603bc0161db779c0ddf528af2f7ed14c Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 28 Aug 2016 19:15:14 +0200 Subject: [PATCH 2/5] Remove temporary fix now unneeded --- tests/compile-fail/derive.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/compile-fail/derive.rs b/tests/compile-fail/derive.rs index 775669dcbd50..06f1388dc056 100644 --- a/tests/compile-fail/derive.rs +++ b/tests/compile-fail/derive.rs @@ -3,7 +3,6 @@ #![deny(warnings)] #![allow(dead_code)] -#![allow(unused_variables)] // Temporary fix for rustc false positive. To be removed. use std::hash::{Hash, Hasher}; From 01424f5622cff4f823a7b797f679bee349e54d8e Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 28 Aug 2016 19:43:55 +0200 Subject: [PATCH 3/5] Support unions here and there --- clippy_lints/src/derive.rs | 4 +++- clippy_lints/src/len_zero.rs | 3 ++- tests/compile-fail/derive.rs | 16 ++++++++++++++++ tests/compile-fail/no_effect.rs | 7 +++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index a5f3b1c12f6c..17d17a445afd 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -140,8 +140,10 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref return; // ty is not Copy } - // Some types are not Clone by default but could be cloned `by hand` if necessary match ty.sty { + TypeVariants::TyUnion(..) => return, + + // Some types are not Clone by default but could be cloned “by hand” if necessary TypeVariants::TyEnum(def, substs) | TypeVariants::TyStruct(def, substs) => { for variant in &def.variants { diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index e8ca113fab1f..d43e31c6a3db 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -209,7 +209,8 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool { } ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)), ty::TyEnum(id, _) | - ty::TyStruct(id, _) => has_is_empty_impl(cx, &id.did), + ty::TyStruct(id, _) | + ty::TyUnion(id, _) => has_is_empty_impl(cx, &id.did), ty::TyArray(..) | ty::TyStr => true, _ => false, } diff --git a/tests/compile-fail/derive.rs b/tests/compile-fail/derive.rs index 06f1388dc056..cf4467f30a59 100644 --- a/tests/compile-fail/derive.rs +++ b/tests/compile-fail/derive.rs @@ -1,6 +1,8 @@ #![feature(plugin)] #![plugin(clippy)] +#![feature(untagged_unions)] + #![deny(warnings)] #![allow(dead_code)] @@ -45,6 +47,20 @@ impl Clone for Qux { fn clone(&self) -> Self { Qux } } +// looks like unions don't support deriving Clone for now +#[derive(Copy)] +union Union { + a: u8, +} + +impl Clone for Union { + fn clone(&self) -> Self { + Union { + a: 42, + } + } +} + // See #666 #[derive(Copy)] struct Lt<'a> { diff --git a/tests/compile-fail/no_effect.rs b/tests/compile-fail/no_effect.rs index 76c7fa54c019..6616f7bdc86c 100644 --- a/tests/compile-fail/no_effect.rs +++ b/tests/compile-fail/no_effect.rs @@ -4,6 +4,7 @@ #![deny(no_effect, unnecessary_operation)] #![allow(dead_code)] #![allow(path_statements)] +#![feature(untagged_unions)] struct Unit; struct Tuple(i32); @@ -15,6 +16,11 @@ enum Enum { Struct { field: i32 }, } +union Union { + a: u8, + b: f64, +} + fn get_number() -> i32 { 0 } fn get_struct() -> Struct { Struct { field: 0 } } @@ -30,6 +36,7 @@ fn main() { Tuple(0); //~ERROR statement with no effect Struct { field: 0 }; //~ERROR statement with no effect Struct { ..s }; //~ERROR statement with no effect + Union { a: 0 }; //~ERROR statement with no effect Enum::Tuple(0); //~ERROR statement with no effect Enum::Struct { field: 0 }; //~ERROR statement with no effect 5 + 6; //~ERROR statement with no effect From 888c34ad70e9f4491a404c4f0cb5a6241e4a12c1 Mon Sep 17 00:00:00 2001 From: mcarton Date: Tue, 30 Aug 2016 17:26:57 +0200 Subject: [PATCH 4/5] Remove all `union` stuffs The rustc's PR wasn't merged. Hopefully this commit can simply be reverted when it's time. --- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/missing_doc.rs | 2 +- tests/compile-fail/derive.rs | 4 +++- tests/compile-fail/no_effect.rs | 6 ++++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 17d17a445afd..2311df424562 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -141,7 +141,7 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref } match ty.sty { - TypeVariants::TyUnion(..) => return, + //FIXME:unions: TypeVariants::TyUnion(..) => return, // Some types are not Clone by default but could be cloned “by hand” if necessary TypeVariants::TyEnum(def, substs) | diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index d43e31c6a3db..9b18eed93ee9 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -209,8 +209,8 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool { } ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)), ty::TyEnum(id, _) | - ty::TyStruct(id, _) | - ty::TyUnion(id, _) => has_is_empty_impl(cx, &id.did), + ty::TyStruct(id, _) /*FIXME:unions: | + ty::TyUnion(id, _)*/ => has_is_empty_impl(cx, &id.did), ty::TyArray(..) | ty::TyStr => true, _ => false, } diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 454f591756bb..bd6354ad9323 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -123,7 +123,7 @@ impl LateLintPass for MissingDoc { hir::ItemStruct(..) => "a struct", hir::ItemTrait(..) => "a trait", hir::ItemTy(..) => "a type alias", - hir::ItemUnion(..) => "a union", + //FIXME:unions: hir::ItemUnion(..) => "a union", hir::ItemDefaultImpl(..) | hir::ItemExternCrate(..) | hir::ItemForeignMod(..) | diff --git a/tests/compile-fail/derive.rs b/tests/compile-fail/derive.rs index cf4467f30a59..39d9dde28819 100644 --- a/tests/compile-fail/derive.rs +++ b/tests/compile-fail/derive.rs @@ -1,7 +1,7 @@ #![feature(plugin)] #![plugin(clippy)] -#![feature(untagged_unions)] +//FIXME:unions: #![feature(untagged_unions)] #![deny(warnings)] #![allow(dead_code)] @@ -47,6 +47,7 @@ impl Clone for Qux { fn clone(&self) -> Self { Qux } } +/* FIXME:unions // looks like unions don't support deriving Clone for now #[derive(Copy)] union Union { @@ -60,6 +61,7 @@ impl Clone for Union { } } } +*/ // See #666 #[derive(Copy)] diff --git a/tests/compile-fail/no_effect.rs b/tests/compile-fail/no_effect.rs index 6616f7bdc86c..39b59a599073 100644 --- a/tests/compile-fail/no_effect.rs +++ b/tests/compile-fail/no_effect.rs @@ -4,7 +4,7 @@ #![deny(no_effect, unnecessary_operation)] #![allow(dead_code)] #![allow(path_statements)] -#![feature(untagged_unions)] +//FIXME:unions #![feature(untagged_unions)] struct Unit; struct Tuple(i32); @@ -16,10 +16,12 @@ enum Enum { Struct { field: i32 }, } +/*FIXME:unions: union Union { a: u8, b: f64, } +*/ fn get_number() -> i32 { 0 } fn get_struct() -> Struct { Struct { field: 0 } } @@ -36,7 +38,7 @@ fn main() { Tuple(0); //~ERROR statement with no effect Struct { field: 0 }; //~ERROR statement with no effect Struct { ..s }; //~ERROR statement with no effect - Union { a: 0 }; //~ERROR statement with no effect + //FIXME:unions: Union { a: 0 }; // /**FIXME*~***/ ERROR statement with no effect Enum::Tuple(0); //~ERROR statement with no effect Enum::Struct { field: 0 }; //~ERROR statement with no effect 5 + 6; //~ERROR statement with no effect From 377fec7c9abc51f43d1378d9eece6e9b2f9aab3e Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 31 Aug 2016 18:19:00 +0200 Subject: [PATCH 5/5] Bump to 0.0.87 --- CHANGELOG.md | 3 ++- Cargo.toml | 4 ++-- clippy_lints/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ef4e596a08c..4c36d5426eda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Change Log All notable changes to this project will be documented in this file. -## 0.0.87 — ?? +## 0.0.87 — 2016-08-31 +* Rustup to *rustc 1.13.0-nightly (eac41469d 2016-08-30)* * New lints: [`builtin_type_shadow`] * Fix FP in [`zero_prefixed_literal`] and `0b`/`Oo` diff --git a/Cargo.toml b/Cargo.toml index 78c4b285f70c..973f6b29c1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy" -version = "0.0.86" +version = "0.0.87" authors = [ "Manish Goregaokar ", "Andre Bogus ", @@ -25,7 +25,7 @@ test = false [dependencies] # begin automatic update -clippy_lints = { version = "0.0.86", path = "clippy_lints" } +clippy_lints = { version = "0.0.87", path = "clippy_lints" } # end automatic update [dev-dependencies] diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index f629e1deb894..9089b6c1ba52 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippy_lints" # begin automatic update -version = "0.0.86" +version = "0.0.87" # end automatic update authors = [ "Manish Goregaokar ",