rust/library/alloc/src
Matthias Krüger f6fd305282
Rollup merge of #129674 - matthewpipie:rc-arc-new-cyclic-in, r=dtolnay
Add new_cyclic_in for Rc and Arc

Currently, new_cyclic_in does not exist for Rc and Arc. This is an oversight according to https://github.com/rust-lang/wg-allocators/issues/132.

This PR adds new_cyclic_in for Rc and Arc. The implementation is almost the exact same as new_cyclic with some small differences to make it allocator-specific. new_cyclic's implementation has been replaced with a call to `new_cyclic_in(data_fn, Global)`.

Remaining questions:
* ~~Is requiring Allocator to be Clone OK? According to https://github.com/rust-lang/wg-allocators/issues/88, Allocators should be cheap to clone. I'm just hesitant to add unnecessary constraints, though I don't see an obvious workaround for this function since many called functions in new_cyclic_in expect an owned Allocator. I see Allocator.by_ref() as an option, but that doesn't work on when creating Weak { ptr: init_ptr, alloc: alloc.clone() }, because the type of Weak then becomes Weak<T, &A> which is incompatible.~~ Fixed, thank you `@zakarumych!` This PR no longer requires the allocator to be Clone.
* Currently, new_cyclic_in's documentation is almost entirely copy-pasted from new_cyclic, with minor tweaks to make it more accurate (e.g. Rc<T> -> Rc<T, A>). The example section is removed to mitigate redundancy and instead redirects to cyclic_in. Is this appropriate?
* ~~The comments in new_cyclic_in (and much of the implementation) are also copy-pasted from new_cyclic. Would it be better to make a helper method new_cyclic_in_internal that both functions call, with either Global or the custom allocator? I'm not sure if that's even possible, since the internal method would have to return Arc<T, Global> and I don't know if it's possible to "downcast" that to an Arc<T>. Maybe transmute would work here?~~ Done, thanks `@zakarumych`
* Arc::new_cyclic is #[inline], but Rc::new_cyclic is not. Which is preferred?
* nit: does it matter where in the impl block new_cyclic_in is defined?
2024-09-17 20:45:50 +02:00
..
alloc Reformat use declarations. 2024-07-29 08:26:52 +10:00
boxed Reformat use declarations. 2024-07-29 08:26:52 +10:00
collections Rollup merge of #130101 - RalfJung:const-cleanup, r=fee1-dead 2024-09-12 19:03:41 +02:00
ffi Reformat use declarations. 2024-07-29 08:26:52 +10:00
raw_vec Polymorphize RawVec 2024-08-09 20:06:26 -04:00
rc Reformat use declarations. 2024-07-29 08:26:52 +10:00
slice Reformat use declarations. 2024-07-29 08:26:52 +10:00
sync Reformat use declarations. 2024-07-29 08:26:52 +10:00
testing Reformat use declarations. 2024-07-29 08:26:52 +10:00
vec Rollup merge of #130061 - theemathas:box_vec_non_null, r=MarkSimulacrum,workingjubilee 2024-09-15 12:14:55 +10:00
alloc.rs make basic allocation functions track_caller in Miri for nicer backtraces 2024-09-11 22:38:21 +02:00
borrow.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
boxed.rs Rollup merge of #130061 - theemathas:box_vec_non_null, r=MarkSimulacrum,workingjubilee 2024-09-15 12:14:55 +10:00
fmt.rs std::fmt::FormatterFn -> std::fmt::FromFn 2024-08-12 18:33:30 +01:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs also stabilize const_refs_to_cell 2024-09-15 10:20:47 +02:00
macros.rs Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
raw_vec.rs add FIXME(const-hack) 2024-09-08 23:08:40 +02:00
rc.rs Rollup merge of #129674 - matthewpipie:rc-arc-new-cyclic-in, r=dtolnay 2024-09-17 20:45:50 +02:00
slice.rs Add missing #[allow(missing_docs)] on hack functions in alloc 2024-09-09 13:44:09 +02:00
str.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
string.rs Rollup merge of #129439 - okaneco:vec_string_lossy, r=Noratrieb 2024-09-15 16:01:36 +02:00
sync.rs Rollup merge of #129674 - matthewpipie:rc-arc-new-cyclic-in, r=dtolnay 2024-09-17 20:45:50 +02:00
task.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
tests.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00