@@ -2109,8 +2109,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
2109
2109
let ty_generics = cx. tcx . generics_of ( def_id) ;
2110
2110
2111
2111
let mut bound_count = 0 ;
2112
- let mut lint_spans = Vec :: new ( ) ;
2113
- let mut where_lint_spans = Vec :: new ( ) ;
2112
+ let mut lint_spans = FxHashSet :: default ( ) ;
2113
+ let mut where_lint_spans = FxHashSet :: default ( ) ;
2114
2114
let mut dropped_predicate_count = 0 ;
2115
2115
let num_predicates = hir_generics. predicates . len ( ) ;
2116
2116
for ( i, where_predicate) in hir_generics. predicates . iter ( ) . enumerate ( ) {
@@ -2173,13 +2173,31 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
2173
2173
dropped_predicate_count += 1 ;
2174
2174
}
2175
2175
2176
- if drop_predicate && !in_where_clause {
2177
- lint_spans. push ( predicate_span) ;
2178
- } else if drop_predicate && i + 1 < num_predicates {
2179
- // If all the bounds on a predicate were inferable and there are
2180
- // further predicates, we want to eat the trailing comma.
2181
- let next_predicate_span = hir_generics. predicates [ i + 1 ] . span ( ) ;
2182
- where_lint_spans. push ( predicate_span. to ( next_predicate_span. shrink_to_lo ( ) ) ) ;
2176
+ if drop_predicate {
2177
+ if !in_where_clause {
2178
+ lint_spans. insert ( predicate_span) ;
2179
+ } else if predicate_span. from_expansion ( ) {
2180
+ // Don't try to extend the span if it comes from a macro expansion.
2181
+ where_lint_spans. insert ( predicate_span) ;
2182
+ } else if i + 1 < num_predicates {
2183
+ // If all the bounds on a predicate were inferable and there are
2184
+ // further predicates, we want to eat the trailing comma.
2185
+ let next_predicate_span = hir_generics. predicates [ i + 1 ] . span ( ) ;
2186
+ if next_predicate_span. from_expansion ( ) {
2187
+ where_lint_spans. insert ( predicate_span) ;
2188
+ } else {
2189
+ where_lint_spans
2190
+ . insert ( predicate_span. to ( next_predicate_span. shrink_to_lo ( ) ) ) ;
2191
+ }
2192
+ } else {
2193
+ // Eat the optional trailing comma after the last predicate.
2194
+ let where_span = hir_generics. where_clause_span ;
2195
+ if where_span. from_expansion ( ) {
2196
+ where_lint_spans. insert ( predicate_span) ;
2197
+ } else {
2198
+ where_lint_spans. insert ( predicate_span. to ( where_span. shrink_to_hi ( ) ) ) ;
2199
+ }
2200
+ }
2183
2201
} else {
2184
2202
where_lint_spans. extend ( self . consolidate_outlives_bound_spans (
2185
2203
predicate_span. shrink_to_lo ( ) ,
@@ -2206,7 +2224,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
2206
2224
2207
2225
// Due to macro expansions, the `full_where_span` might not actually contain all predicates.
2208
2226
if where_lint_spans. iter ( ) . all ( |& sp| full_where_span. contains ( sp) ) {
2209
- lint_spans. push ( full_where_span) ;
2227
+ lint_spans. insert ( full_where_span) ;
2210
2228
} else {
2211
2229
lint_spans. extend ( where_lint_spans) ;
2212
2230
}
@@ -2223,6 +2241,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
2223
2241
Applicability :: MaybeIncorrect
2224
2242
} ;
2225
2243
2244
+ let lint_spans = lint_spans. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
2245
+
2226
2246
cx. emit_spanned_lint (
2227
2247
EXPLICIT_OUTLIVES_REQUIREMENTS ,
2228
2248
lint_spans. clone ( ) ,
0 commit comments