1
- use crate :: utils:: { in_macro, span_help_and_lint, SpanlessHash } ;
1
+ use crate :: utils:: { in_macro, snippet , span_help_and_lint, SpanlessHash } ;
2
2
use rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
3
3
use rustc:: { declare_tool_lint, impl_lint_pass} ;
4
4
use rustc_data_structures:: fx:: FxHashMap ;
@@ -8,6 +8,20 @@ use rustc::hir::*;
8
8
pub struct TraitBounds ;
9
9
10
10
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
+ /// ```
11
25
pub TYPE_REPETITION_IN_BOUNDS ,
12
26
complexity,
13
27
"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 {
30
44
if let WherePredicate :: BoundPredicate ( ref p) = bound {
31
45
let h = hash ( & p. bounded_ty ) ;
32
46
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 , "_" ) ) ;
34
48
for b in v. iter ( ) {
35
49
if let GenericBound :: Trait ( ref poly_trait_ref, _) = b {
36
50
let path = & poly_trait_ref. trait_ref . path ;
0 commit comments