Skip to content

Commit

Permalink
Added doc comment fixed type printout
Browse files Browse the repository at this point in the history
Added a doc comment for the lint and fixed the printout of the type so it prints T not type(T)
  • Loading branch information
xd009642 committed Jul 27, 2019
1 parent cac69ec commit 5e9906b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions 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;
Expand All @@ -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: _`"
Expand All @@ -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;
Expand Down

0 comments on commit 5e9906b

Please sign in to comment.