From 63041d070b72b37c07fe3c0764f82ae3c3606028 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sun, 1 Jul 2018 13:36:14 +0200 Subject: [PATCH 1/6] Rustup --- clippy_lints/src/consts.rs | 5 ++--- clippy_lints/src/utils/paths.rs | 16 ++++++++-------- tests/ui/dlist.rs | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 36417cd0877..6fc6637900d 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -13,7 +13,6 @@ use std::mem; use std::rc::Rc; use syntax::ast::{FloatTy, LitKind}; use syntax::ptr::P; -use rustc::middle::const_val::ConstVal; use crate::utils::{sext, unsext, clip}; #[derive(Debug, Copy, Clone)] @@ -428,7 +427,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'tcx>) -> Option { use rustc::mir::interpret::{Scalar, ConstValue}; match result.val { - ConstVal::Value(ConstValue::Scalar(Scalar::Bits{ bits: b, ..})) => match result.ty.sty { + ConstValue::Scalar(Scalar::Bits{ bits: b, ..}) => match result.ty.sty { ty::TyBool => Some(Constant::Bool(b == 1)), ty::TyUint(_) | ty::TyInt(_) => Some(Constant::Int(b)), ty::TyFloat(FloatTy::F32) => Some(Constant::F32(f32::from_bits(b as u32))), @@ -436,7 +435,7 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<' // FIXME: implement other conversion _ => None, }, - ConstVal::Value(ConstValue::ScalarPair(Scalar::Ptr(ptr), Scalar::Bits { bits: n, .. })) => match result.ty.sty { + ConstValue::ScalarPair(Scalar::Ptr(ptr), Scalar::Bits { bits: n, .. }) => match result.ty.sty { ty::TyRef(_, tam, _) => match tam.sty { ty::TyStr => { let alloc = tcx diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 7606f4f8471..4d89f8ddffb 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -2,18 +2,18 @@ //! about. pub const ANY_TRAIT: [&str; 3] = ["std", "any", "Any"]; -pub const ARC: [&str; 3] = ["alloc", "arc", "Arc"]; +pub const ARC: [&str; 3] = ["alloc", "sync", "Arc"]; pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"]; pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"]; pub const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"]; pub const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"]; -pub const BINARY_HEAP: [&str; 3] = ["alloc", "binary_heap", "BinaryHeap"]; +pub const BINARY_HEAP: [&str; 4] = ["alloc", "collections", "binary_heap", "BinaryHeap"]; pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"]; pub const BOX: [&str; 3] = ["std", "boxed", "Box"]; pub const BOX_NEW: [&str; 4] = ["std", "boxed", "Box", "new"]; -pub const BTREEMAP: [&str; 4] = ["alloc", "btree", "map", "BTreeMap"]; -pub const BTREEMAP_ENTRY: [&str; 4] = ["alloc", "btree", "map", "Entry"]; -pub const BTREESET: [&str; 4] = ["alloc", "btree", "set", "BTreeSet"]; +pub const BTREEMAP: [&str; 5] = ["alloc", "collections", "btree", "map", "BTreeMap"]; +pub const BTREEMAP_ENTRY: [&str; 5] = ["alloc", "collections", "btree", "map", "Entry"]; +pub const BTREESET: [&str; 5] = ["alloc", "collections", "btree", "set", "BTreeSet"]; pub const CLONE: [&str; 4] = ["core", "clone", "Clone", "clone"]; pub const CLONE_TRAIT: [&str; 3] = ["core", "clone", "Clone"]; pub const CMP_MAX: [&str; 3] = ["core", "cmp", "max"]; @@ -47,7 +47,7 @@ pub const IO_PRINT: [&str; 4] = ["std", "io", "stdio", "_print"]; pub const IO_READ: [&str; 3] = ["std", "io", "Read"]; pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"]; pub const ITERATOR: [&str; 4] = ["core", "iter", "iterator", "Iterator"]; -pub const LINKED_LIST: [&str; 3] = ["alloc", "linked_list", "LinkedList"]; +pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"]; pub const LINT: [&str; 2] = ["lint", "Lint"]; pub const LINT_ARRAY: [&str; 2] = ["lint", "LintArray"]; pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"]; @@ -101,7 +101,7 @@ pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"]; pub const TRY_INTO_RESULT: [&str; 4] = ["std", "ops", "Try", "into_result"]; pub const UNINIT: [&str; 4] = ["core", "intrinsics", "", "uninit"]; pub const VEC: [&str; 3] = ["alloc", "vec", "Vec"]; -pub const VEC_DEQUE: [&str; 3] = ["alloc", "vec_deque", "VecDeque"]; +pub const VEC_DEQUE: [&str; 4] = ["alloc", "collections", "vec_deque", "VecDeque"]; pub const VEC_FROM_ELEM: [&str; 3] = ["alloc", "vec", "from_elem"]; -pub const WEAK_ARC: [&str; 3] = ["alloc", "arc", "Weak"]; +pub const WEAK_ARC: [&str; 3] = ["alloc", "sync", "Weak"]; pub const WEAK_RC: [&str; 3] = ["alloc", "rc", "Weak"]; diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs index a4fab5735e2..1318ed78717 100644 --- a/tests/ui/dlist.rs +++ b/tests/ui/dlist.rs @@ -6,7 +6,7 @@ #![allow(dead_code, needless_pass_by_value)] extern crate alloc; -use alloc::linked_list::LinkedList; +use alloc::collections::linked_list::LinkedList; trait Foo { type Baz = LinkedList; From 41972f89dcb99819191ffbf2381430e63e9d916d Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 2 Jul 2018 10:16:55 +0200 Subject: [PATCH 2/6] HACK: make sure clippy builds the same deps as cargo and rls --- Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 72d2d8cc6ba..dea7f3644c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,12 @@ clippy_lints = { version = "0.0.211", path = "clippy_lints" } regex = "1" semver = "0.9" +# Not actually needed right now but required to make sure that clippy/ and cargo build +# with the same set of features in rust-lang/rust +num-traits = "0.2" # enable the default feature +winapi = "0.3" +backtrace = "0.3" + [dev-dependencies] cargo_metadata = "0.5" compiletest_rs = "0.3.7" From 141f79f8440229f705f47f06c47b46a44d65584b Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 2 Jul 2018 19:07:12 +0200 Subject: [PATCH 3/6] Rustup --- clippy_lints/src/enum_glob_use.rs | 2 +- clippy_lints/src/methods.rs | 2 +- clippy_lints/src/utils/inspector.rs | 20 ++++++++++---------- clippy_lints/src/utils/internal_lints.rs | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/enum_glob_use.rs b/clippy_lints/src/enum_glob_use.rs index 943a5406b54..9a0263f2f68 100644 --- a/clippy_lints/src/enum_glob_use.rs +++ b/clippy_lints/src/enum_glob_use.rs @@ -44,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse { impl EnumGlobUse { fn lint_item(&self, cx: &LateContext, item: &Item) { - if item.vis == Visibility::Public { + if item.vis.node == VisibilityKind::Public { return; // re-exports are fine } if let ItemUse(ref path, UseKind::Glob) = item.node { diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 71f9dc8e03f..1d1d0ef8faa 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -840,7 +840,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { .iter() .any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics)); then { - let lint = if item.vis == hir::Visibility::Public { + let lint = if item.vis.node == hir::VisibilityKind::Public { WRONG_PUB_SELF_CONVENTION } else { WRONG_SELF_CONVENTION diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index b23464c80de..ccc4c9df6e7 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -51,14 +51,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { return; } println!("impl item `{}`", item.ident.name); - match item.vis { - hir::Visibility::Public => println!("public"), - hir::Visibility::Crate(_) => println!("visible crate wide"), - hir::Visibility::Restricted { ref path, .. } => println!( + match item.vis.node { + hir::VisibilityKind::Public => println!("public"), + hir::VisibilityKind::Crate(_) => println!("visible crate wide"), + hir::VisibilityKind::Restricted { ref path, .. } => println!( "visible in module `{}`", print::to_string(print::NO_ANN, |s| s.print_path(path, false)) ), - hir::Visibility::Inherited => println!("visibility inherited from outer item"), + hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"), } if item.defaultness.is_default() { println!("default"); @@ -343,14 +343,14 @@ fn print_expr(cx: &LateContext, expr: &hir::Expr, indent: usize) { fn print_item(cx: &LateContext, item: &hir::Item) { let did = cx.tcx.hir.local_def_id(item.id); println!("item `{}`", item.name); - match item.vis { - hir::Visibility::Public => println!("public"), - hir::Visibility::Crate(_) => println!("visible crate wide"), - hir::Visibility::Restricted { ref path, .. } => println!( + match item.vis.node { + hir::VisibilityKind::Public => println!("public"), + hir::VisibilityKind::Crate(_) => println!("visible crate wide"), + hir::VisibilityKind::Restricted { ref path, .. } => println!( "visible in module `{}`", print::to_string(print::NO_ANN, |s| s.print_path(path, false)) ), - hir::Visibility::Inherited => println!("visibility inherited from outer item"), + hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"), } match item.node { hir::ItemExternCrate(ref _renamed_from) => { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index b1b65698eb9..f0e3961600c 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { if let ItemStatic(ref ty, MutImmutable, body_id) = item.node { if is_lint_ref_type(ty) { self.declared_lints.insert(item.name, item.span); - } else if is_lint_array_type(ty) && item.vis == Visibility::Inherited && item.name == "ARRAY" { + } else if is_lint_array_type(ty) && item.vis.node == VisibilityKind::Inherited && item.name == "ARRAY" { let mut collector = LintCollector { output: &mut self.registered_lints, cx, From 547d9ca120a29a546453319cad2c87f0f924703a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 3 Jul 2018 10:52:59 +0200 Subject: [PATCH 4/6] Rustup --- clippy_lints/src/escape.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 9482c3782d4..c718e1f417c 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -108,7 +108,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { return; } if let Categorization::Rvalue(..) = cmt.cat { - if let Some(NodeStmt(st)) = map.find(map.get_parent_node(cmt.id)) { + let id = map.hir_to_node_id(cmt.hir_id); + if let Some(NodeStmt(st)) = map.find(map.get_parent_node(id)) { if let StmtDecl(ref decl, _) = st.node { if let DeclLocal(ref loc) = decl.node { if let Some(ref ex) = loc.init { From 28daee4c919dd88772847ec5240eb850bb0dcbf3 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 3 Jul 2018 18:23:21 +0200 Subject: [PATCH 5/6] Rustup --- Cargo.toml | 34 +++++++++++++++++++++++++++++++++- clippy_lints/src/lifetimes.rs | 21 ++++++++++++++------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dea7f3644c7..2dd71828136 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,9 +48,41 @@ semver = "0.9" # Not actually needed right now but required to make sure that clippy/ and cargo build # with the same set of features in rust-lang/rust num-traits = "0.2" # enable the default feature -winapi = "0.3" backtrace = "0.3" +# keep in sync with `cargo`'s `Cargo.toml' +[target.'cfg(windows)'.dependencies.winapi] +version = "0.3" +features = [ + # keep in sync with `cargo`'s `Cargo.toml' + "handleapi", + "jobapi", + "jobapi2", + "minwindef", + "ntdef", + "ntstatus", + "processenv", + "processthreadsapi", + "psapi", + "synchapi", + "winerror", + "winbase", + "wincon", + "winnt", + # no idea where these come from + "lmcons", + "minschannel", + "minwinbase", + "ntsecapi", + "profileapi", + "schannel", + "securitybaseapi", + "synchapi", + "sysinfoapi", + "timezoneapi", + "wincrypt", +] + [dev-dependencies] cargo_metadata = "0.5" compiletest_rs = "0.3.7" diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index efa50a8f743..605182c007a 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -342,16 +342,23 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { self.record(&None); }, TyPath(ref path) => { - self.collect_anonymous_lifetimes(path, ty); - }, - TyImplTraitExistential(exist_ty_id, _, _) => { - if let ItemExistential(ref exist_ty) = self.cx.tcx.hir.expect_item(exist_ty_id.id).node { - for bound in &exist_ty.bounds { - if let GenericBound::Outlives(_) = *bound { - self.record(&None); + if let QPath::Resolved(_, ref path) = *path { + if let Def::Existential(def_id) = path.def { + let node_id = self.cx.tcx.hir.as_local_node_id(def_id).unwrap(); + if let ItemExistential(ref exist_ty) = self.cx.tcx.hir.expect_item(node_id).node { + for bound in &exist_ty.bounds { + if let GenericBound::Outlives(_) = *bound { + self.record(&None); + } + } + } else { + unreachable!() } + walk_ty(self, ty); + return; } } + self.collect_anonymous_lifetimes(path, ty); } TyTraitObject(ref bounds, ref lt) => { if !lt.is_elided() { From 6d9d3bac1dd73641a145534b32d5454815a573c0 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 6 Jul 2018 11:16:36 +1200 Subject: [PATCH 6/6] Add some more winapi features --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 2dd71828136..d0f1ebdd1da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,9 @@ features = [ "wincon", "winnt", # no idea where these come from + "basetsd", "lmcons", + "memoryapi", "minschannel", "minwinbase", "ntsecapi",