mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Auto merge of #3966 - flip1995:internal_lints, r=oli-obk
Enable rustc internal lints Closes #3965 I'm not 100% sure if enabling the `-Zunstable-options` flag in the `.cargo/config` file is the right place.
This commit is contained in:
commit
27d62cf603
9 changed files with 10 additions and 126 deletions
|
@ -1,2 +1,5 @@
|
|||
[alias]
|
||||
uitest = "test --test compile-test"
|
||||
|
||||
[build]
|
||||
rustflags = ["-Zunstable-options"]
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
stable
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(clippy::default_hash_types)]
|
||||
|
||||
use itertools::Itertools;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
|
|
|
@ -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,
|
||||
]);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![allow(clippy::default_hash_types)]
|
||||
#![allow(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 a new issue