Skip to content

Commit 5e9906b

Browse files
committed
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)
1 parent cac69ec commit 5e9906b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

clippy_lints/src/trait_bounds.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{in_macro, span_help_and_lint, SpanlessHash};
1+
use crate::utils::{in_macro, snippet, span_help_and_lint, SpanlessHash};
22
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
33
use rustc::{declare_tool_lint, impl_lint_pass};
44
use rustc_data_structures::fx::FxHashMap;
@@ -8,6 +8,20 @@ use rustc::hir::*;
88
pub struct TraitBounds;
99

1010
declare_clippy_lint! {
11+
/// **What it does:** This lint warns about unnecessary type repetitions in trait bounds
12+
///
13+
/// **Why is this bad?** Complexity
14+
///
15+
/// **Example:**
16+
/// ```rust
17+
/// pub fn foo<T>(t: T) where T: Copy, T: Clone
18+
/// ```
19+
///
20+
/// Could be written as:
21+
///
22+
/// ```rust
23+
/// pub fn foo<T>(t: T) where T: Copy + Clone
24+
/// ```
1125
pub TYPE_REPETITION_IN_BOUNDS,
1226
complexity,
1327
"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 {
3044
if let WherePredicate::BoundPredicate(ref p) = bound {
3145
let h = hash(&p.bounded_ty);
3246
if let Some(ref v) = map.insert(h, p.bounds.iter().collect::<Vec<_>>()) {
33-
let mut hint_string = format!("consider combining the bounds: `{:?}: ", p.bounded_ty);
47+
let mut hint_string = format!("consider combining the bounds: `{}: ", snippet(cx, p.bounded_ty.span, "_"));
3448
for b in v.iter() {
3549
if let GenericBound::Trait(ref poly_trait_ref, _) = b {
3650
let path = &poly_trait_ref.trait_ref.path;

0 commit comments

Comments
 (0)