1- use crate :: utils:: { in_macro, span_help_and_lint, SpanlessHash } ;
1+ use crate :: utils:: { in_macro, snippet , span_help_and_lint, SpanlessHash } ;
22use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
33use rustc:: { declare_tool_lint, impl_lint_pass} ;
44use rustc_data_structures:: fx:: FxHashMap ;
@@ -8,6 +8,20 @@ use rustc::hir::*;
88pub struct TraitBounds ;
99
1010declare_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