Skip to content

fix: Prevent panic in Remove Unused Parameter assist #12789

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

Merged

Conversation

DorianListens
Copy link
Contributor

Instead of calling builder.delete for every text range we find with
process_usage, we now ensure that the ranges do not overlap before removing
them. If a range is fully contained by a prior one, it is dropped.

fixes #12784

@lnicola
Copy link
Member

lnicola commented Jul 18, 2022

As a style nit, I'm not really a fan of fold used like this. A for loop might look somewhat cleaner.

More importantly, it's somewhat inefficient for a largish number of ranges. I think there's a more efficient way to implement this by sorting the interval endpoints and keeping a list of the open ones, but I don't know if it's worth the complexity.

On the third hand, I'm pretty sure someone will post a horrible file with thousands of function invocations, not unlike the 13 MB expression in #4500.

@DorianListens
Copy link
Contributor Author

Totally fair on the style front, I can re-implement as a for loop.

Definitely true that it is somewhat inefficient, but I'm not sure I know how to implement the more efficient version you're describing.

Also: Wow! 200K if/else pairs!

@lnicola
Copy link
Member

lnicola commented Jul 18, 2022

Something like https://www.baeldung.com/cs/finding-all-overlapping-intervals#sweep-line-approach. But it's probably not something that should block this.

@DorianListens DorianListens force-pushed the dscheidt/unused-param-overlapping branch from ce33398 to 0d6222e Compare July 18, 2022 16:13
@lnicola
Copy link
Member

lnicola commented Jul 18, 2022

@bors delegate+

@bors
Copy link
Contributor

bors commented Jul 18, 2022

✌️ @DorianListens can now approve this pull request

Instead of calling `builder.delete` for every text range we find with
`process_usage`, we now ensure that the ranges do not overlap before removing
them. If a range is fully contained by a prior one, it is dropped.

fixes rust-lang#12784
@DorianListens DorianListens force-pushed the dscheidt/unused-param-overlapping branch from 0d6222e to ffb6b23 Compare July 18, 2022 21:44
@DorianListens
Copy link
Contributor Author

I looked into implementing the sweep line style of finding the overlaps, and I think it's definitely doable.
I also think this is something we can easily optimize in the future, so I'm going merge this as is.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 19, 2022

📌 Commit ffb6b23 has been approved by DorianListens

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 19, 2022

⌛ Testing commit ffb6b23 with merge 30c4db1...

@bors
Copy link
Contributor

bors commented Jul 19, 2022

☀️ Test successful - checks-actions
Approved by: DorianListens
Pushing 30c4db1 to master...

@bors bors merged commit 30c4db1 into rust-lang:master Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Remove Unused Parameter" panics on nested call
3 participants