Skip to content

Commit

Permalink
Auto merge of #3966 - flip1995:internal_lints, r=oli-obk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Apr 16, 2019
2 parents 3e8d992 + 118f7d5 commit 29893fe
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 126 deletions.
3 changes: 3 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[alias]
uitest = "test --test compile-test"

[build]
rustflags = ["-Zunstable-options"]
1 change: 0 additions & 1 deletion clippy_dev/rust-toolchain

This file was deleted.

2 changes: 0 additions & 2 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::default_hash_types)]

use itertools::Itertools;
use lazy_static::lazy_static;
use regex::Regex;
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
]);

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::default_hash_types)]
#![allow(default_hash_types)]

use std::borrow::Cow;
use std::cmp::Ordering;
Expand Down
65 changes: 3 additions & 62 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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),
);
}
}
Expand Down
16 changes: 0 additions & 16 deletions tests/ui/fxhash.rs

This file was deleted.

40 changes: 0 additions & 40 deletions tests/ui/fxhash.stderr

This file was deleted.

0 comments on commit 29893fe

Please sign in to comment.