Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not emit invalid suggestion in E0191 when spans overlap #115077

Merged
merged 2 commits into from
Aug 22, 2023

Conversation

estebank
Copy link
Contributor

Fix #115019.

@rustbot
Copy link
Collaborator

rustbot commented Aug 21, 2023

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 21, 2023
@@ -597,7 +597,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
}
}
if !suggestions.is_empty() {
suggestions.sort_by_key(|&(span, _)| span);
Copy link
Member

@compiler-errors compiler-errors Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you certain that the suggestion spans will end up sorted in such a way that two non-adjacent keys never overlap? If not, then since this is the error path, I feel like it may just be easier to do the O(N^2) full pairwise comparison here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpanData manually implements Ord on (lo, hi, ctxt). That means that by sorting any two adjacent spans that don't overlap imply that the spans further apart from each other also don't overlap.

Copy link
Member

@compiler-errors compiler-errors Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about spans that overlap only at their end? Like spans that look like: [(1, 5), (2, 3), (4, 5)], where the first and last elements overlap?

Copy link
Member

@compiler-errors compiler-errors Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, maybe it doesn't matter, since by construction that would imply any intermediate spans overlap. Idk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your last comment is exactly right.

Comment on lines 613 to 620
let mut overlaps = false;
let mut sugg = suggestions.iter().peekable();
while let Some((span, _)) = sugg.next() {
let Some((next, _)) = sugg.peek() else {
break;
};
overlaps |= span.overlaps(*next);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this loop can be simplified? Will need to be tweaked if the above assumption is not true, though.

Suggested change
let mut overlaps = false;
let mut sugg = suggestions.iter().peekable();
while let Some((span, _)) = sugg.next() {
let Some((next, _)) = sugg.peek() else {
break;
};
overlaps |= span.overlaps(*next);
}
let overlaps = suggestions.windows(2).any(|pair| pair[0].0.overlaps(pair[1].0));

@compiler-errors
Copy link
Member

Please squash this ideally if you apply any of my suggestions.

@compiler-errors
Copy link
Member

compiler-errors commented Aug 21, 2023

r=me after confirming whether the assumption about overlapping spans being always sorted adjacently is true or false, then either applying the simplification suggested above or just changing it to an O(N^2) overlap check like:

let overlaps = suggestions.iter().any(|(span, _)| suggestions.iter().any(|(other_span, _)| span != other_span && span.overlaps(other_span)));

or something like that.

@estebank
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Aug 22, 2023

📌 Commit b86285a has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 22, 2023
…mpiler-errors

Rollup of 6 pull requests

Successful merges:

 - rust-lang#114959 (fix rust-lang#113702 emit a proper diagnostic message for unstable lints passed from CLI)
 - rust-lang#115011 (Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`))
 - rust-lang#115077 (Do not emit invalid suggestion in E0191 when spans overlap)
 - rust-lang#115087 (Add disclaimer on size assertion macro)
 - rust-lang#115090 (Always use `os-release` rather than `/lib` to detect `NixOS` (bootstrap))
 - rust-lang#115101 (triagebot: add dependency licensing pings)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0e84d42 into rust-lang:master Aug 22, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: debug assertions: E0191 overlapping spans
4 participants