1
1
use crate :: utils:: { in_macro, snippet, snippet_with_applicability, span_lint_and_help, SpanlessHash } ;
2
+ use if_chain:: if_chain;
2
3
use rustc_data_structures:: fx:: FxHashMap ;
3
4
use rustc_errors:: Applicability ;
4
5
use rustc_hir:: { GenericBound , Generics , WherePredicate } ;
@@ -11,6 +12,8 @@ declare_clippy_lint! {
11
12
/// **Why is this bad?** Repeating the type for every bound makes the code
12
13
/// less readable than combining the bounds
13
14
///
15
+ /// **Known problems:** None.
16
+ ///
14
17
/// **Example:**
15
18
/// ```rust
16
19
/// pub fn foo<T>(t: T) where T: Copy, T: Clone {}
@@ -53,12 +56,14 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
53
56
let mut map = FxHashMap :: default ( ) ;
54
57
let mut applicability = Applicability :: MaybeIncorrect ;
55
58
for bound in gen. where_clause . predicates {
56
- if let WherePredicate :: BoundPredicate ( ref p ) = bound {
57
- if p . bounds . len ( ) as u64 > self . max_trait_bounds {
58
- return ;
59
- }
59
+ if_chain ! {
60
+ if let WherePredicate :: BoundPredicate ( ref p ) = bound ;
61
+ if p . bounds . len ( ) as u64 <= self . max_trait_bounds ;
62
+ if !in_macro ( p . span ) ;
60
63
let h = hash( & p. bounded_ty) ;
61
- if let Some ( ref v) = map. insert ( h, p. bounds . iter ( ) . collect :: < Vec < _ > > ( ) ) {
64
+ if let Some ( ref v) = map. insert( h, p. bounds. iter( ) . collect:: <Vec <_>>( ) ) ;
65
+
66
+ then {
62
67
let mut hint_string = format!(
63
68
"consider combining the bounds: `{}:" ,
64
69
snippet( cx, p. bounded_ty. span, "_" )
0 commit comments