//! lint on inherent implementations
+use crate::utils::span_lint_and_then;
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;
-/// **What it does:** Checks for multiple inherent implementations of a struct
-///
-/// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// struct X;
-/// impl X {
-/// fn one() {}
-/// }
-/// impl X {
-/// fn other() {}
-/// }
-/// ```
-///
-/// Could be written:
-///
-/// ```rust
-/// struct X;
-/// impl X {
-/// fn one() {}
-/// fn other() {}
-/// }
-/// ```
declare_clippy_lint! {
+ /// **What it does:** Checks for multiple inherent implementations of a struct
+ ///
+ /// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate.
+ ///
+ /// **Known problems:** None.
+ ///
+ /// **Example:**
+ /// ```rust
+ /// struct X;
+ /// impl X {
+ /// fn one() {}
+ /// }
+ /// impl X {
+ /// fn other() {}
+ /// }
+ /// ```
+ ///
+ /// Could be written:
+ ///
+ /// ```rust
+ /// struct X;
+ /// impl X {
+ /// fn one() {}
+ /// fn other() {}
+ /// }
+ /// ```
pub MULTIPLE_INHERENT_IMPL,
restriction,
"Multiple inherent impl that could be grouped"
}
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() }
+ Self {
+ impls: FxHashMap::default(),
+ }
}
}
fn get_lints(&self) -> LintArray {
lint_array!(MULTIPLE_INHERENT_IMPL)
}
+
+ fn name(&self) -> &'static str {
+ "MultipleInherientImpl"
+ }
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
let mut impl_spans = impls
.iter()
.filter_map(|impl_def| self.impls.get(impl_def))
- .filter(|(_, generics)| generics.params.len() == 0)
- .map(|(span, _)| span);
+ .filter_map(|(span, generics)| if generics.params.len() == 0 { Some(span) } else { None });
if let Some(initial_span) = impl_spans.nth(0) {
impl_spans.for_each(|additional_span| {
span_lint_and_then(
*additional_span,
"Multiple implementations of this structure",
|db| {
- db.span_note(
- *initial_span,
- "First implementation here",
- );
+ db.span_note(*initial_span, "First implementation here");
},
)
})