diff --git a/.cargo/config b/.cargo/config index 7cb41d979..b4bc4418f 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,2 +1,5 @@ [alias] uitest = "test --test compile-test" + +[build] +rustflags = ["-Zunstable-options"] diff --git a/clippy_dev/rust-toolchain b/clippy_dev/rust-toolchain deleted file mode 100644 index 2bf5ad044..000000000 --- a/clippy_dev/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -stable diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 31b0a98c1..392388ffd 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -1,5 +1,3 @@ -#![allow(clippy::default_hash_types)] - use itertools::Itertools; use lazy_static::lazy_static; use regex::Regex; diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d547e0a99..824058a08 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -8,6 +8,7 @@ #![allow(clippy::missing_docs_in_private_items)] #![recursion_limit = "256"] #![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)] +#![deny(internal)] #![feature(crate_visibility_modifier)] // FIXME: switch to something more ergonomic here, once available. @@ -423,7 +424,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box serde_api::Serde); reg.register_early_lint_pass(box utils::internal_lints::Clippy); reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new()); - reg.register_early_lint_pass(box utils::internal_lints::DefaultHashTypes::default()); reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default()); reg.register_late_lint_pass(box utils::inspector::Pass); reg.register_late_lint_pass(box utils::author::Pass); @@ -647,7 +647,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![ utils::internal_lints::CLIPPY_LINTS_INTERNAL, utils::internal_lints::COMPILER_LINT_FUNCTIONS, - utils::internal_lints::DEFAULT_HASH_TYPES, utils::internal_lints::LINT_WITHOUT_LINT_PASS, ]); diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 34cb2422e..97f69f874 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -9,7 +9,7 @@ use if_chain::if_chain; use rustc::hir::def::CtorKind; use rustc::hir::*; use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass}; -use rustc::ty::{self, Ty, TyKind}; +use rustc::ty::{self, Ty}; use rustc::{declare_tool_lint, lint_array}; use rustc_errors::Applicability; use std::cmp::Ordering; @@ -500,7 +500,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) { // already covered. let mut missing_variants = vec![]; - if let TyKind::Adt(def, _) = ty.sty { + if let ty::Adt(def, _) = ty.sty { for variant in &def.variants { missing_variants.push(variant); } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 95609d3f3..380eefff7 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1,4 +1,4 @@ -#![allow(clippy::default_hash_types)] +#![allow(default_hash_types)] use std::borrow::Cow; use std::cmp::Ordering; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 343098cee..0ebb19376 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,6 +1,4 @@ -use crate::utils::{ - match_def_path, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty, -}; +use crate::utils::{match_def_path, match_type, paths, span_help_and_lint, span_lint, walk_ptrs_ty}; use if_chain::if_chain; use rustc::hir; use rustc::hir::def::Def; @@ -9,8 +7,7 @@ use rustc::hir::*; use rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_tool_lint, lint_array}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::Applicability; -use syntax::ast::{Crate as AstCrate, Ident, ItemKind, Name}; +use syntax::ast::{Crate as AstCrate, ItemKind, Name}; use syntax::source_map::Span; use syntax::symbol::LocalInternedString; @@ -56,17 +53,6 @@ declare_clippy_lint! { "declaring a lint without associating it in a LintPass" } -declare_clippy_lint! { - /// **What it does:** Checks for the presence of the default hash types "HashMap" or "HashSet" - /// and recommends the FxHash* variants. - /// - /// **Why is this bad?** The FxHash variants have better performance - /// and we don't need any collision prevention in clippy. - pub DEFAULT_HASH_TYPES, - internal, - "forbid HashMap and HashSet and suggest the FxHash* variants" -} - declare_clippy_lint! { /// **What it does:** Checks for calls to `cx.span_lint*` and suggests to use the `utils::*` /// variant of the function. @@ -238,51 +224,6 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for LintCollector<'a, 'tcx> { } } -pub struct DefaultHashTypes { - map: FxHashMap, -} - -impl DefaultHashTypes { - pub fn default() -> Self { - let mut map = FxHashMap::default(); - map.insert("HashMap".to_string(), "FxHashMap".to_string()); - map.insert("HashSet".to_string(), "FxHashSet".to_string()); - Self { map } - } -} - -impl LintPass for DefaultHashTypes { - fn get_lints(&self) -> LintArray { - lint_array!(DEFAULT_HASH_TYPES) - } - - fn name(&self) -> &'static str { - "DefaultHashType" - } -} - -impl EarlyLintPass for DefaultHashTypes { - fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) { - let ident_string = ident.to_string(); - if let Some(replace) = self.map.get(&ident_string) { - let msg = format!( - "Prefer {} over {}, it has better performance \ - and we don't need any collision prevention in clippy", - replace, ident_string - ); - span_lint_and_sugg( - cx, - DEFAULT_HASH_TYPES, - ident.span, - &msg, - "use", - replace.to_string(), - Applicability::MaybeIncorrect, // FxHashMap, ... needs another import - ); - } - } -} - #[derive(Clone, Default)] pub struct CompilerLintFunctions { map: FxHashMap, @@ -325,7 +266,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { COMPILER_LINT_FUNCTIONS, path.ident.span, "usage of a compiler lint function", - &format!("Please use the Clippy variant of this function: `{}`", sugg), + &format!("please use the Clippy variant of this function: `{}`", sugg), ); } } diff --git a/tests/ui/fxhash.rs b/tests/ui/fxhash.rs deleted file mode 100644 index 7d6cb4e11..000000000 --- a/tests/ui/fxhash.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![warn(clippy::default_hash_types)] -#![feature(rustc_private)] - -extern crate rustc_data_structures; - -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use std::collections::{HashMap, HashSet}; - -fn main() { - let _map: HashMap = HashMap::default(); - let _set: HashSet = HashSet::default(); - - // test that the lint doesn't also match the Fx variants themselves 😂 - let _fx_map: FxHashMap = FxHashMap::default(); - let _fx_set: FxHashSet = FxHashSet::default(); -} diff --git a/tests/ui/fxhash.stderr b/tests/ui/fxhash.stderr deleted file mode 100644 index a2dac6700..000000000 --- a/tests/ui/fxhash.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: Prefer FxHashMap over HashMap, it has better performance and we don't need any collision prevention in clippy - --> $DIR/fxhash.rs:7:24 - | -LL | use std::collections::{HashMap, HashSet}; - | ^^^^^^^ help: use: `FxHashMap` - | - = note: `-D clippy::default-hash-types` implied by `-D warnings` - -error: Prefer FxHashSet over HashSet, it has better performance and we don't need any collision prevention in clippy - --> $DIR/fxhash.rs:7:33 - | -LL | use std::collections::{HashMap, HashSet}; - | ^^^^^^^ help: use: `FxHashSet` - -error: Prefer FxHashMap over HashMap, it has better performance and we don't need any collision prevention in clippy - --> $DIR/fxhash.rs:10:15 - | -LL | let _map: HashMap = HashMap::default(); - | ^^^^^^^ help: use: `FxHashMap` - -error: Prefer FxHashMap over HashMap, it has better performance and we don't need any collision prevention in clippy - --> $DIR/fxhash.rs:10:41 - | -LL | let _map: HashMap = HashMap::default(); - | ^^^^^^^ help: use: `FxHashMap` - -error: Prefer FxHashSet over HashSet, it has better performance and we don't need any collision prevention in clippy - --> $DIR/fxhash.rs:11:15 - | -LL | let _set: HashSet = HashSet::default(); - | ^^^^^^^ help: use: `FxHashSet` - -error: Prefer FxHashSet over HashSet, it has better performance and we don't need any collision prevention in clippy - --> $DIR/fxhash.rs:11:33 - | -LL | let _set: HashSet = HashSet::default(); - | ^^^^^^^ help: use: `FxHashSet` - -error: aborting due to 6 previous errors -