Skip to content

Commit 29893fe

Browse files
committed
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.
2 parents 3e8d992 + 118f7d5 commit 29893fe

File tree

9 files changed

+10
-126
lines changed

9 files changed

+10
-126
lines changed

.cargo/config

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[alias]
22
uitest = "test --test compile-test"
3+
4+
[build]
5+
rustflags = ["-Zunstable-options"]

clippy_dev/rust-toolchain

-1
This file was deleted.

clippy_dev/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(clippy::default_hash_types)]
2-
31
use itertools::Itertools;
42
use lazy_static::lazy_static;
53
use regex::Regex;

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![allow(clippy::missing_docs_in_private_items)]
99
#![recursion_limit = "256"]
1010
#![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)]
11+
#![deny(internal)]
1112
#![feature(crate_visibility_modifier)]
1213

1314
// FIXME: switch to something more ergonomic here, once available.
@@ -423,7 +424,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
423424
reg.register_late_lint_pass(box serde_api::Serde);
424425
reg.register_early_lint_pass(box utils::internal_lints::Clippy);
425426
reg.register_late_lint_pass(box utils::internal_lints::CompilerLintFunctions::new());
426-
reg.register_early_lint_pass(box utils::internal_lints::DefaultHashTypes::default());
427427
reg.register_late_lint_pass(box utils::internal_lints::LintWithoutLintPass::default());
428428
reg.register_late_lint_pass(box utils::inspector::Pass);
429429
reg.register_late_lint_pass(box utils::author::Pass);
@@ -647,7 +647,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
647647
reg.register_lint_group("clippy::internal", Some("clippy_internal"), vec![
648648
utils::internal_lints::CLIPPY_LINTS_INTERNAL,
649649
utils::internal_lints::COMPILER_LINT_FUNCTIONS,
650-
utils::internal_lints::DEFAULT_HASH_TYPES,
651650
utils::internal_lints::LINT_WITHOUT_LINT_PASS,
652651
]);
653652

clippy_lints/src/matches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use if_chain::if_chain;
99
use rustc::hir::def::CtorKind;
1010
use rustc::hir::*;
1111
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
12-
use rustc::ty::{self, Ty, TyKind};
12+
use rustc::ty::{self, Ty};
1313
use rustc::{declare_tool_lint, lint_array};
1414
use rustc_errors::Applicability;
1515
use std::cmp::Ordering;
@@ -500,7 +500,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
500500
// already covered.
501501

502502
let mut missing_variants = vec![];
503-
if let TyKind::Adt(def, _) = ty.sty {
503+
if let ty::Adt(def, _) = ty.sty {
504504
for variant in &def.variants {
505505
missing_variants.push(variant);
506506
}

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::default_hash_types)]
1+
#![allow(default_hash_types)]
22

33
use std::borrow::Cow;
44
use std::cmp::Ordering;

clippy_lints/src/utils/internal_lints.rs

+3-62
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::utils::{
2-
match_def_path, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
3-
};
1+
use crate::utils::{match_def_path, match_type, paths, span_help_and_lint, span_lint, walk_ptrs_ty};
42
use if_chain::if_chain;
53
use rustc::hir;
64
use rustc::hir::def::Def;
@@ -9,8 +7,7 @@ use rustc::hir::*;
97
use rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
108
use rustc::{declare_tool_lint, lint_array};
119
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
12-
use rustc_errors::Applicability;
13-
use syntax::ast::{Crate as AstCrate, Ident, ItemKind, Name};
10+
use syntax::ast::{Crate as AstCrate, ItemKind, Name};
1411
use syntax::source_map::Span;
1512
use syntax::symbol::LocalInternedString;
1613

@@ -56,17 +53,6 @@ declare_clippy_lint! {
5653
"declaring a lint without associating it in a LintPass"
5754
}
5855

59-
declare_clippy_lint! {
60-
/// **What it does:** Checks for the presence of the default hash types "HashMap" or "HashSet"
61-
/// and recommends the FxHash* variants.
62-
///
63-
/// **Why is this bad?** The FxHash variants have better performance
64-
/// and we don't need any collision prevention in clippy.
65-
pub DEFAULT_HASH_TYPES,
66-
internal,
67-
"forbid HashMap and HashSet and suggest the FxHash* variants"
68-
}
69-
7056
declare_clippy_lint! {
7157
/// **What it does:** Checks for calls to `cx.span_lint*` and suggests to use the `utils::*`
7258
/// variant of the function.
@@ -238,51 +224,6 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for LintCollector<'a, 'tcx> {
238224
}
239225
}
240226

241-
pub struct DefaultHashTypes {
242-
map: FxHashMap<String, String>,
243-
}
244-
245-
impl DefaultHashTypes {
246-
pub fn default() -> Self {
247-
let mut map = FxHashMap::default();
248-
map.insert("HashMap".to_string(), "FxHashMap".to_string());
249-
map.insert("HashSet".to_string(), "FxHashSet".to_string());
250-
Self { map }
251-
}
252-
}
253-
254-
impl LintPass for DefaultHashTypes {
255-
fn get_lints(&self) -> LintArray {
256-
lint_array!(DEFAULT_HASH_TYPES)
257-
}
258-
259-
fn name(&self) -> &'static str {
260-
"DefaultHashType"
261-
}
262-
}
263-
264-
impl EarlyLintPass for DefaultHashTypes {
265-
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
266-
let ident_string = ident.to_string();
267-
if let Some(replace) = self.map.get(&ident_string) {
268-
let msg = format!(
269-
"Prefer {} over {}, it has better performance \
270-
and we don't need any collision prevention in clippy",
271-
replace, ident_string
272-
);
273-
span_lint_and_sugg(
274-
cx,
275-
DEFAULT_HASH_TYPES,
276-
ident.span,
277-
&msg,
278-
"use",
279-
replace.to_string(),
280-
Applicability::MaybeIncorrect, // FxHashMap, ... needs another import
281-
);
282-
}
283-
}
284-
}
285-
286227
#[derive(Clone, Default)]
287228
pub struct CompilerLintFunctions {
288229
map: FxHashMap<String, String>,
@@ -325,7 +266,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions {
325266
COMPILER_LINT_FUNCTIONS,
326267
path.ident.span,
327268
"usage of a compiler lint function",
328-
&format!("Please use the Clippy variant of this function: `{}`", sugg),
269+
&format!("please use the Clippy variant of this function: `{}`", sugg),
329270
);
330271
}
331272
}

tests/ui/fxhash.rs

-16
This file was deleted.

tests/ui/fxhash.stderr

-40
This file was deleted.

0 commit comments

Comments
 (0)