diff options
| author | xd009642 <danielmckenna93@gmail.com> | 2019-07-27 12:06:25 +0100 |
|---|---|---|
| committer | xd009642 <danielmckenna93@gmail.com> | 2019-07-27 12:06:25 +0100 |
| commit | 5e9906b2c64c07e95252e91a4ce1534cfa4cf10b (patch) | |
| tree | 83636e64a3a2861d8464dde095604977d57f2719 | |
| parent | cac69ec063e9fcb26e0f3102c82b9cb2d56350fe (diff) | |
| download | rust-5e9906b2c64c07e95252e91a4ce1534cfa4cf10b.tar.gz rust-5e9906b2c64c07e95252e91a4ce1534cfa4cf10b.zip | |
Added doc comment fixed type printout
Added a doc comment for the lint and fixed the printout of the type so it prints T not type(T)
| -rw-r--r-- | clippy_lints/src/trait_bounds.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 3ef353a978f..f5ca3793dbc 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -1,4 +1,4 @@ -use crate::utils::{in_macro, span_help_and_lint, SpanlessHash}; +use crate::utils::{in_macro, snippet, span_help_and_lint, SpanlessHash}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_tool_lint, impl_lint_pass}; use rustc_data_structures::fx::FxHashMap; @@ -8,6 +8,20 @@ use rustc::hir::*; pub struct TraitBounds; declare_clippy_lint! { + /// **What it does:** This lint warns about unnecessary type repetitions in trait bounds + /// + /// **Why is this bad?** Complexity + /// + /// **Example:** + /// ```rust + /// pub fn foo<T>(t: T) where T: Copy, T: Clone + /// ``` + /// + /// Could be written as: + /// + /// ```rust + /// pub fn foo<T>(t: T) where T: Copy + Clone + /// ``` pub TYPE_REPETITION_IN_BOUNDS, complexity, "Types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`" @@ -30,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds { if let WherePredicate::BoundPredicate(ref p) = bound { let h = hash(&p.bounded_ty); if let Some(ref v) = map.insert(h, p.bounds.iter().collect::<Vec<_>>()) { - let mut hint_string = format!("consider combining the bounds: `{:?}: ", p.bounded_ty); + let mut hint_string = format!("consider combining the bounds: `{}: ", snippet(cx, p.bounded_ty.span, "_")); for b in v.iter() { if let GenericBound::Trait(ref poly_trait_ref, _) = b { let path = &poly_trait_ref.trait_ref.path; |
