-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Generalize {Rc,Arc}::make_mut()
to unsized types.
#116113
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
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
@rustbot label +T-libs-api |
This comment has been minimized.
This comment has been minimized.
This is insta-stable, so it needs libs-api FCP. r? @rust-lang/libs-api |
Rerolling because @BurntSushi doesn't do libs reviews. r? rust-lang/libs-api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adjusting the trait bound on make_mut
instead? It can be implemented the current way for T: Clone
and separately for [T]
.
impl<T: CanMakeMut, A: Allocator + Clone> Arc<T, A> {
pub fn make_mut(this: &mut Self) -> &mut T { ... }
}
impl<T: Clone> CanMakeMut for T { ... }
impl<T: Clone> CanMakeMut for [T] { ... }
Is it? The current commit only adds unstable inherent methods. There's no trait implementation involved.
I like that idea much better since it doesn't add a new name. (Though it would be insta-stable.) I'm not familiar with how introducing a trait like Actually, the trait could be of more broad use — it seems like it could be a general "clone |
Oh, it's totally not insta-stable, my bad (sorry, been a draining couple of weeks for me). Still, I'll leave the review to the assignee at this point. |
The I would definitely be on board with a trait that allows cloning into a pre-allocated I am not familiar with the |
Observation: The new |
Observation: It's not possible to define these operations in terms of |
This comment has been minimized.
This comment has been minimized.
It was quite an adventure, but I believe I've got it all set now. I had to introduce additional helper types at both the Note that |
{Rc, Arc}::make_mut_slice()
.{Rc,Arc}::make_mut()
to unsized types.
Updated PR description with the new design based on |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (f944afe): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -5.7%, secondary -2.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary 0.1%, secondary 0.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 694.577s -> 694.429s (-0.02%) |
Regressions are mostly in doc benchmarks, seem likely to be just new docs due to extra stuff in the standard library. |
{Rc,Arc}::make_mut()
now accept any type implementing the new unstable traitcore::clone::CloneToUninit
.CloneToUninit
is implemented forT: Clone
and for[T] where T: Clone
.CloneToUninit
is a generalization of the existing internal traitalloc::alloc::WriteCloneIntoRaw
.clone_to_uninit
This allows performing
make_mut()
onRc<[T]>
andArc<[T]>
, which was not previously possible.Previous PR description, now obsolete:
try-job: test-various