@@ -2124,12 +2124,16 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
21242124 }
21252125
21262126 let ty_generics = cx. tcx . generics_of ( def_id) ;
2127+ let num_where_predicates = hir_generics
2128+ . predicates
2129+ . iter ( )
2130+ . filter ( |predicate| predicate. in_where_clause ( ) )
2131+ . count ( ) ;
21272132
21282133 let mut bound_count = 0 ;
21292134 let mut lint_spans = Vec :: new ( ) ;
21302135 let mut where_lint_spans = Vec :: new ( ) ;
2131- let mut dropped_predicate_count = 0 ;
2132- let num_predicates = hir_generics. predicates . len ( ) ;
2136+ let mut dropped_where_predicate_count = 0 ;
21332137 for ( i, where_predicate) in hir_generics. predicates . iter ( ) . enumerate ( ) {
21342138 let ( relevant_lifetimes, bounds, predicate_span, in_where_clause) =
21352139 match where_predicate {
@@ -2186,8 +2190,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
21862190 bound_count += bound_spans. len ( ) ;
21872191
21882192 let drop_predicate = bound_spans. len ( ) == bounds. len ( ) ;
2189- if drop_predicate {
2190- dropped_predicate_count += 1 ;
2193+ if drop_predicate && in_where_clause {
2194+ dropped_where_predicate_count += 1 ;
21912195 }
21922196
21932197 if drop_predicate {
@@ -2196,7 +2200,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
21962200 } else if predicate_span. from_expansion ( ) {
21972201 // Don't try to extend the span if it comes from a macro expansion.
21982202 where_lint_spans. push ( predicate_span) ;
2199- } else if i + 1 < num_predicates {
2203+ } else if i + 1 < num_where_predicates {
22002204 // If all the bounds on a predicate were inferable and there are
22012205 // further predicates, we want to eat the trailing comma.
22022206 let next_predicate_span = hir_generics. predicates [ i + 1 ] . span ( ) ;
@@ -2224,9 +2228,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
22242228 }
22252229 }
22262230
2227- // If all predicates are inferable, drop the entire clause
2231+ // If all predicates in where clause are inferable, drop the entire clause
22282232 // (including the `where`)
2229- if hir_generics. has_where_clause_predicates && dropped_predicate_count == num_predicates
2233+ if hir_generics. has_where_clause_predicates
2234+ && dropped_where_predicate_count == num_where_predicates
22302235 {
22312236 let where_span = hir_generics. where_clause_span ;
22322237 // Extend the where clause back to the closing `>` of the
0 commit comments