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

Don't panic in Vec::shrink_to_fit #75677

Merged
merged 1 commit into from
Aug 19, 2020
Merged

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Aug 18, 2020

We can help the compiler see that Vec::shrink_to_fit will never reach the panic case in RawVec::shrink_to_fit, just by guarding the call only for cases where the capacity is strictly greater. A capacity less than the length is only possible through an unsafe call to set_len, which would break the Vec invariants, so shrink_to_fit can just ignore that.

This removes the panicking code from the examples in both #71861 and #75636.

@rust-highfive
Copy link
Collaborator

r? @LukasKalbertodt

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 18, 2020
@Mark-Simulacrum
Copy link
Member

Comparison should mostly be the same independent of != vs. > I think perf wise, so @bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Aug 18, 2020

📌 Commit 7551f3f has been approved by Mark-Simulacrum

@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 18, 2020
Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

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

Looks good to me but today I learned that we can do test like this.

@bors
Copy link
Contributor

bors commented Aug 19, 2020

⌛ Testing commit 7551f3f with merge c03c213...

@bors
Copy link
Contributor

bors commented Aug 19, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: Mark-Simulacrum
Pushing c03c213 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 19, 2020
@bors bors merged commit c03c213 into rust-lang:master Aug 19, 2020
@cuviper cuviper deleted the shrink-towel branch August 19, 2020 06:11
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants