1
Fork 0

Auto merge of #106916 - lukas-code:overlapping-substs, r=estebank

Remove overlapping parts of multipart suggestions

This PR adds a debug assertion that the parts of a single substitution cannot overlap, fixes a overlapping substitution from the testsuite, and fixes https://github.com/rust-lang/rust/issues/106870.

Note that a single suggestion can still have multiple overlapping substitutions / possible edits, we just don't suggest overlapping replacements in a single edit anymore.

I've also included a fix for an unrelated bug where rustfix for `explicit_outlives_requirements` would produce multiple trailing commas for a where clause.
This commit is contained in:
bors 2023-01-28 10:00:56 +00:00
commit d8da513668
13 changed files with 214 additions and 62 deletions

View file

@ -2175,13 +2175,31 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
dropped_predicate_count += 1;
}
if drop_predicate && !in_where_clause {
lint_spans.push(predicate_span);
} else if drop_predicate && i + 1 < num_predicates {
// If all the bounds on a predicate were inferable and there are
// further predicates, we want to eat the trailing comma.
let next_predicate_span = hir_generics.predicates[i + 1].span();
where_lint_spans.push(predicate_span.to(next_predicate_span.shrink_to_lo()));
if drop_predicate {
if !in_where_clause {
lint_spans.push(predicate_span);
} else if predicate_span.from_expansion() {
// Don't try to extend the span if it comes from a macro expansion.
where_lint_spans.push(predicate_span);
} else if i + 1 < num_predicates {
// If all the bounds on a predicate were inferable and there are
// further predicates, we want to eat the trailing comma.
let next_predicate_span = hir_generics.predicates[i + 1].span();
if next_predicate_span.from_expansion() {
where_lint_spans.push(predicate_span);
} else {
where_lint_spans
.push(predicate_span.to(next_predicate_span.shrink_to_lo()));
}
} else {
// Eat the optional trailing comma after the last predicate.
let where_span = hir_generics.where_clause_span;
if where_span.from_expansion() {
where_lint_spans.push(predicate_span);
} else {
where_lint_spans.push(predicate_span.to(where_span.shrink_to_hi()));
}
}
} else {
where_lint_spans.extend(self.consolidate_outlives_bound_spans(
predicate_span.shrink_to_lo(),
@ -2225,6 +2243,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
Applicability::MaybeIncorrect
};
// Due to macros, there might be several predicates with the same span
// and we only want to suggest removing them once.
lint_spans.sort_unstable();
lint_spans.dedup();
cx.emit_spanned_lint(
EXPLICIT_OUTLIVES_REQUIREMENTS,
lint_spans.clone(),