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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override Box::<[T]>::clone_from #72499

Merged
merged 3 commits into from May 30, 2020
Merged

Override Box::<[T]>::clone_from #72499

merged 3 commits into from May 30, 2020

Conversation

mendess
Copy link
Contributor

@mendess mendess commented May 23, 2020

Avoid dropping and reallocating when cloning to an existing box if the lengths are the same.

It would be nice if this could also be specialized for Copy but I don't know how that works since it's not on stable. Will gladly look into it if it's deemed as a good idea.

This is my first PR with code, hope I did everything right 馃槃

@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 May 23, 2020
@dtolnay dtolnay added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 28, 2020
let mut copy = vec![Dummy { _data: 84 }; size + 1].into_boxed_slice();
let copy_raw = copy.as_ptr() as usize;
copy.clone_from(&control);
assert_ne!(copy.as_ptr() as usize, copy_raw);
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this would be flaky. The allocator can put these at the same address if the compiler decides to drop the old one before allocating the new one.

What sort of regression is this test hoping to catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, I made this test while I was trying to write them without UB or unsafe. It doesn't make much sense now that you point that out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other test on the other hand might not catch a regression for the same reason 馃 but I can't think of a another way to test this. Basically it might give a false positive but never a false negative

@dtolnay dtolnay assigned dtolnay and unassigned LukasKalbertodt May 28, 2020
@dtolnay
Copy link
Member

dtolnay commented May 29, 2020

@bors r+

@bors
Copy link
Contributor

bors commented May 29, 2020

馃搶 Commit dbf32e2 has been approved by dtolnay

@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 May 29, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 30, 2020
Rollup of 9 pull requests

Successful merges:

 - rust-lang#72299 (more `LocalDefId`s)
 - rust-lang#72368 (Resolve overflow behavior for RangeFrom)
 - rust-lang#72441 (Fix ICE with explicit late-bound lifetimes)
 - rust-lang#72499 (Override Box::<[T]>::clone_from)
 - rust-lang#72521 (Properly handle InlineAsmOperand::SymFn when collecting monomorphized items)
 - rust-lang#72540 (mir: adjust conditional in recursion limit check)
 - rust-lang#72563 (multiple Return terminators are possible)
 - rust-lang#72585 (Only capture tokens for items with outer attributes)
 - rust-lang#72607 (Eagerly lower asm sub-expressions to HIR even if there is an error)

Failed merges:

r? @ghost
@bors bors merged commit 8d64fd8 into rust-lang:master May 30, 2020
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-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants