mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Remove clippy::default_hash_types internal lint
This commit is contained in:
parent
0973f68fb8
commit
5361b842d1
@ -1,5 +1,3 @@
|
||||
#![allow(clippy::default_hash_types)]
|
||||
|
||||
use itertools::Itertools;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
@ -423,7 +423,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 +646,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,
|
||||
]);
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![allow(clippy::default_hash_types)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::Ordering;
|
||||
|
@ -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<String, String>,
|
||||
}
|
||||
|
||||
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<String, String>,
|
||||
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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<String, String> = HashMap::default();
|
||||
let _set: HashSet<String> = HashSet::default();
|
||||
|
||||
// test that the lint doesn't also match the Fx variants themselves 😂
|
||||
let _fx_map: FxHashMap<String, String> = FxHashMap::default();
|
||||
let _fx_set: FxHashSet<String> = FxHashSet::default();
|
||||
}
|
@ -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<String, String> = 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<String, String> = 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<String> = 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<String> = HashSet::default();
|
||||
| ^^^^^^^ help: use: `FxHashSet`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user