11use crate :: utils:: { in_macro, snippet, span_help_and_lint, SpanlessHash } ;
2+ use rustc:: hir:: * ;
23use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
34use rustc:: { declare_tool_lint, impl_lint_pass} ;
45use rustc_data_structures:: fx:: FxHashMap ;
5- use rustc:: hir:: * ;
66
77#[ derive( Copy , Clone ) ]
88pub struct TraitBounds ;
99
1010declare_clippy_lint ! {
1111 /// **What it does:** This lint warns about unnecessary type repetitions in trait bounds
1212 ///
13- /// **Why is this bad?** Complexity
13+ /// **Why is this bad?** Repeating the type for every bound makes the code
14+ /// less readable than combining the bounds
1415 ///
1516 /// **Example:**
1617 /// ```rust
17- /// pub fn foo<T>(t: T) where T: Copy, T: Clone
18+ /// pub fn foo<T>(t: T) where T: Copy, T: Clone
1819 /// ```
1920 ///
2021 /// Could be written as:
@@ -34,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
3435 if in_macro ( gen. span ) {
3536 return ;
3637 }
37- let hash = | ty | -> u64 {
38+ let hash = |ty | -> u64 {
3839 let mut hasher = SpanlessHash :: new ( cx, cx. tables ) ;
3940 hasher. hash_ty ( ty) ;
4041 hasher. finish ( )
@@ -44,17 +45,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
4445 if let WherePredicate :: BoundPredicate ( ref p) = bound {
4546 let h = hash ( & p. bounded_ty ) ;
4647 if let Some ( ref v) = map. insert ( h, p. bounds . iter ( ) . collect :: < Vec < _ > > ( ) ) {
47- let mut hint_string = format ! ( "consider combining the bounds: `{}: " , snippet( cx, p. bounded_ty. span, "_" ) ) ;
48+ let mut hint_string = format ! (
49+ "consider combining the bounds: `{}:" ,
50+ snippet( cx, p. bounded_ty. span, "_" )
51+ ) ;
4852 for b in v. iter ( ) {
4953 if let GenericBound :: Trait ( ref poly_trait_ref, _) = b {
5054 let path = & poly_trait_ref. trait_ref . path ;
51- hint_string. push_str ( & format ! ( "{}, " , path) ) ;
55+ hint_string. push_str ( & format ! ( " {} + " , path) ) ;
5256 }
5357 }
5458 for b in p. bounds . iter ( ) {
5559 if let GenericBound :: Trait ( ref poly_trait_ref, _) = b {
5660 let path = & poly_trait_ref. trait_ref . path ;
57- hint_string. push_str ( & format ! ( "{}, " , path) ) ;
61+ hint_string. push_str ( & format ! ( " {} + " , path) ) ;
5862 }
5963 }
6064 hint_string. truncate ( hint_string. len ( ) - 2 ) ;
0 commit comments