Skip to content

Run internal lints on the Clippy code base #3166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/base-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cp target/debug/cargo-clippy ~/rust/cargo/bin/cargo-clippy
cp target/debug/clippy-driver ~/rust/cargo/bin/clippy-driver
rm ~/.cargo/bin/cargo-clippy
# run clippy on its own codebase...
PATH=$PATH:~/rust/cargo/bin cargo clippy --all-targets --all-features -- -D clippy::all
PATH=$PATH:~/rust/cargo/bin cargo clippy --all-targets --all-features -- -D clippy::all -D clippy::internal
# ... and some test directories
cd clippy_workspace_tests && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ..
cd clippy_workspace_tests/src && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy::all && cd ../..
Expand Down
2 changes: 2 additions & 0 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(tool_lints)]
#![allow(clippy::default_hash_types)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phansch in clippy_dev the feature rustc_private isn't activated, because no use rustc::... is used. That means that also FxHashMap cannot be used.

I think disabling the Lint here is better than adding the #![feature(rustc_private)]. What's your opinion on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea we can just disable the lint there. I don't think we will need any rustc::... in clippy_dev in the near future.

extern crate regex;
#[macro_use]
extern crate lazy_static;
Expand Down
14 changes: 9 additions & 5 deletions clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::ty::Ty;
use rustc::hir::*;
use std::collections::HashMap;
use rustc_data_structures::fx::FxHashMap;
use std::collections::hash_map::Entry;
use std::hash::BuildHasherDefault;
use syntax::symbol::LocalInternedString;
use rustc_data_structures::small_vec::OneVector;
use crate::utils::{SpanlessEq, SpanlessHash};
Expand Down Expand Up @@ -263,8 +264,8 @@ fn if_sequence(mut expr: &Expr) -> (OneVector<&Expr>, OneVector<&Block>) {
}

/// Return the list of bindings in a pattern.
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<LocalInternedString, Ty<'tcx>> {
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut HashMap<LocalInternedString, Ty<'tcx>>) {
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalInternedString, Ty<'tcx>> {
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut FxHashMap<LocalInternedString, Ty<'tcx>>) {
match pat.node {
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
PatKind::TupleStruct(_, ref pats, _) => for pat in pats {
Expand Down Expand Up @@ -299,7 +300,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<LocalInt
}
}

let mut result = HashMap::new();
let mut result = FxHashMap::default();
bindings_impl(cx, pat, &mut result);
result
}
Expand Down Expand Up @@ -333,7 +334,10 @@ where
};
}

let mut map: HashMap<_, Vec<&_>> = HashMap::with_capacity(exprs.len());
let mut map: FxHashMap<_, Vec<&_>> = FxHashMap::with_capacity_and_hasher(
exprs.len(),
BuildHasherDefault::default()
);

for expr in exprs {
match map.entry(hash(expr)) {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::ty;
use rustc::hir::def::Def;
use std::collections::HashSet;
use rustc_data_structures::fx::FxHashSet;
use syntax::ast;
use rustc_target::spec::abi::Abi;
use syntax::source_map::Span;
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'a, 'tcx> Functions {
let raw_ptrs = iter_input_pats(decl, body)
.zip(decl.inputs.iter())
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))
.collect::<HashSet<_>>();
.collect::<FxHashSet<_>>();

if !raw_ptrs.is_empty() {
let tables = cx.tcx.body_tables(body.id());
Expand All @@ -177,7 +177,7 @@ fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<ast::NodeId> {

struct DerefVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
ptrs: HashSet<ast::NodeId>,
ptrs: FxHashSet<ast::NodeId>,
tables: &'a ty::TypeckTables<'tcx>,
}

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/inherent_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use std::collections::HashMap;
use rustc_data_structures::fx::FxHashMap;
use std::default::Default;
use syntax_pos::Span;
use crate::utils::span_lint_and_then;
Expand Down Expand Up @@ -41,12 +41,12 @@ declare_clippy_lint! {
}

pub struct Pass {
impls: HashMap<def_id::DefId, (Span, Generics)>,
impls: FxHashMap<def_id::DefId, (Span, Generics)>,
}

impl Default for Pass {
fn default() -> Self {
Pass { impls: HashMap::new() }
Pass { impls: FxHashMap::default() }
}
}

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::ty;
use std::collections::HashSet;
use rustc_data_structures::fx::FxHashSet;
use syntax::ast::{Lit, LitKind, Name};
use syntax::source_map::{Span, Spanned};
use crate::utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_sugg, walk_ptrs_ty};
Expand Down Expand Up @@ -125,7 +125,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
}

// fill the set with current and super traits
fn fill_trait_set(traitt: DefId, set: &mut HashSet<DefId>, cx: &LateContext<'_, '_>) {
fn fill_trait_set(traitt: DefId, set: &mut FxHashSet<DefId>, cx: &LateContext<'_, '_>) {
if set.insert(traitt) {
for supertrait in ::rustc::traits::supertrait_def_ids(cx.tcx, traitt) {
fill_trait_set(supertrait, set, cx);
Expand All @@ -134,7 +134,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
}

if cx.access_levels.is_exported(visited_trait.id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
let mut current_and_super_traits = HashSet::new();
let mut current_and_super_traits = FxHashSet::default();
let visited_trait_def_id = cx.tcx.hir.local_def_id(visited_trait.id);
fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx);

Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc::{declare_tool_lint, lint_array};
use rustc::hir::def::Def;
use rustc::hir::*;
use rustc::hir::intravisit::*;
use std::collections::{HashMap, HashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use syntax::source_map::Span;
use crate::utils::{last_path_segment, span_lint};
use syntax::symbol::keywords;
Expand Down Expand Up @@ -237,8 +237,8 @@ fn could_use_elision<'a, 'tcx: 'a>(
}
}

fn allowed_lts_from(named_generics: &[GenericParam]) -> HashSet<RefLt> {
let mut allowed_lts = HashSet::new();
fn allowed_lts_from(named_generics: &[GenericParam]) -> FxHashSet<RefLt> {
let mut allowed_lts = FxHashSet::default();
for par in named_generics.iter() {
if let GenericParamKind::Lifetime { .. } = par.kind {
if par.bounds.is_empty() {
Expand All @@ -263,7 +263,7 @@ fn lts_from_bounds<'a, T: Iterator<Item = &'a Lifetime>>(mut vec: Vec<RefLt>, bo

/// Number of unique lifetimes in the given vector.
fn unique_lifetimes(lts: &[RefLt]) -> usize {
lts.iter().collect::<HashSet<_>>().len()
lts.iter().collect::<FxHashSet<_>>().len()
}

/// A visitor usable for `rustc_front::visit::walk_ty()`.
Expand Down Expand Up @@ -424,7 +424,7 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
}

struct LifetimeChecker {
map: HashMap<Name, Span>,
map: FxHashMap<Name, Span>,
}

impl<'tcx> Visitor<'tcx> for LifetimeChecker {
Expand Down
30 changes: 15 additions & 15 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc::middle::mem_categorization::cmt_;
use rustc::ty::{self, Ty};
use rustc::ty::subst::Subst;
use rustc_errors::Applicability;
use std::collections::{HashMap, HashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use std::iter::{once, Iterator};
use syntax::ast;
use syntax::source_map::Span;
Expand Down Expand Up @@ -1030,10 +1030,10 @@ fn check_for_loop_range<'a, 'tcx>(
let mut visitor = VarVisitor {
cx,
var: canonical_id,
indexed_mut: HashSet::new(),
indexed_indirectly: HashMap::new(),
indexed_directly: HashMap::new(),
referenced: HashSet::new(),
indexed_mut: FxHashSet::default(),
indexed_indirectly: FxHashMap::default(),
indexed_directly: FxHashMap::default(),
referenced: FxHashSet::default(),
nonindex: false,
prefer_mutable: false,
};
Expand Down Expand Up @@ -1343,7 +1343,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
// Look for variables that are incremented once per loop iteration.
let mut visitor = IncrementVisitor {
cx,
states: HashMap::new(),
states: FxHashMap::default(),
depth: 0,
done: false,
};
Expand Down Expand Up @@ -1618,15 +1618,15 @@ struct VarVisitor<'a, 'tcx: 'a> {
/// var name to look for as index
var: ast::NodeId,
/// indexed variables that are used mutably
indexed_mut: HashSet<Name>,
indexed_mut: FxHashSet<Name>,
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
indexed_indirectly: HashMap<Name, Option<region::Scope>>,
indexed_indirectly: FxHashMap<Name, Option<region::Scope>>,
/// subset of `indexed` of vars that are indexed directly: `v[i]`
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
indexed_directly: HashMap<Name, Option<region::Scope>>,
indexed_directly: FxHashMap<Name, Option<region::Scope>>,
/// Any names that are used outside an index operation.
/// Used to detect things like `&mut vec` used together with `vec[i]`
referenced: HashSet<Name>,
referenced: FxHashSet<Name>,
/// has the loop variable been used in expressions other than the index of
/// an index op?
nonindex: bool,
Expand Down Expand Up @@ -1906,7 +1906,7 @@ enum VarState {
/// Scan a for loop for variables that are incremented exactly once.
struct IncrementVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>, // context reference
states: HashMap<NodeId, VarState>, // incremented variables
states: FxHashMap<NodeId, VarState>, // incremented variables
depth: u32, // depth of conditional expressions
done: bool,
}
Expand Down Expand Up @@ -2197,8 +2197,8 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, e

let mut var_visitor = VarCollectorVisitor {
cx,
ids: HashSet::new(),
def_ids: HashMap::new(),
ids: FxHashSet::default(),
def_ids: FxHashMap::default(),
skip: false,
};
var_visitor.visit_expr(cond);
Expand Down Expand Up @@ -2228,8 +2228,8 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, e
/// All variables definition IDs are collected
struct VarCollectorVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
ids: HashSet<NodeId>,
def_ids: HashMap<def_id::DefId, bool>,
ids: FxHashSet<NodeId>,
def_ids: FxHashMap<def_id::DefId, bool>,
skip: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/misc_early.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, LintContext, in_external_macro};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashMap;
use if_chain::if_chain;
use std::collections::HashMap;
use std::char;
use syntax::ast::*;
use syntax::source_map::Span;
Expand Down Expand Up @@ -267,7 +267,7 @@ impl EarlyLintPass for MiscEarly {
}

fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, decl: &FnDecl, _: Span, _: NodeId) {
let mut registered_names: HashMap<String, Span> = HashMap::new();
let mut registered_names: FxHashMap<String, Span> = FxHashMap::default();

for arg in &decl.inputs {
if let PatKind::Ident(_, ident, None) = arg.pat.node {
Expand Down
14 changes: 7 additions & 7 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use rustc::traits;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc_target::spec::abi::Abi;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use syntax::ast::NodeId;
use syntax_pos::Span;
use syntax::errors::DiagnosticBuilder;
use crate::utils::{get_trait_def_id, implements_trait, in_macro, is_copy, is_self, match_type, multispan_sugg, paths,
snippet, snippet_opt, span_lint_and_then};
use crate::utils::ptr::get_spans;
use std::collections::{HashMap, HashSet};
use std::borrow::Cow;

/// **What it does:** Checks for functions taking arguments by value, but not
Expand Down Expand Up @@ -301,18 +301,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {

struct MovedVariablesCtxt<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
moved_vars: HashSet<NodeId>,
moved_vars: FxHashSet<NodeId>,
/// Spans which need to be prefixed with `*` for dereferencing the
/// suggested additional reference.
spans_need_deref: HashMap<NodeId, HashSet<Span>>,
spans_need_deref: FxHashMap<NodeId, FxHashSet<Span>>,
}

impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
Self {
cx,
moved_vars: HashSet::new(),
spans_need_deref: HashMap::new(),
moved_vars: FxHashSet::default(),
spans_need_deref: FxHashMap::default(),
}
}

Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
if let ExprKind::Match(ref c, ..) = e.node {
self.spans_need_deref
.entry(vid)
.or_insert_with(HashSet::new)
.or_insert_with(FxHashSet::default)
.insert(c.span);
}
},
Expand All @@ -357,7 +357,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
then {
self.spans_need_deref
.entry(vid)
.or_insert_with(HashSet::new)
.or_insert_with(FxHashSet::default)
.insert(local.init
.as_ref()
.map(|e| e.span)
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use regex_syntax;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet;
use if_chain::if_chain;
use std::collections::HashSet;
use syntax::ast::{LitKind, NodeId, StrStyle};
use syntax::source_map::{BytePos, Span};
use crate::utils::{is_expn_of, match_def_path, match_type, opt_def_id, paths, span_help_and_lint, span_lint};
Expand Down Expand Up @@ -67,7 +67,7 @@ declare_clippy_lint! {

#[derive(Clone, Default)]
pub struct Pass {
spans: HashSet<Span>,
spans: FxHashSet<Span>,
last: Option<NodeId>,
}

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

use crate::reexport::*;
use rustc::hir;
use rustc::hir::*;
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/unused_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc::hir;
use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor};
use std::collections::HashMap;
use rustc_data_structures::fx::FxHashMap;
use syntax::ast;
use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;
Expand Down Expand Up @@ -31,7 +31,7 @@ declare_clippy_lint! {
pub struct UnusedLabel;

struct UnusedLabelVisitor<'a, 'tcx: 'a> {
labels: HashMap<LocalInternedString, Span>,
labels: FxHashMap<LocalInternedString, Span>,
cx: &'a LateContext<'a, 'tcx>,
}

Expand All @@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {

let mut v = UnusedLabelVisitor {
cx,
labels: HashMap::new(),
labels: FxHashMap::default(),
};
walk_fn(&mut v, kind, decl, body.id(), span, fn_id);

Expand Down
Loading