rust/src/liballoc
Mazdak Farrokhzad cb012a0430
Rollup merge of #60766 - vorner:weak-into-raw, r=sfackler
Weak::into_raw

Hello

This is my first shot at #60728. I'd like to consult it a bit before moving further.

The biggest question I have is if this API makes sense. My motivation for it is to be able to store the `Weak` in `AtomicPtr`. For that I don't actually need for the pointer to point to the `T`, any pointer (maybe casted to `usize`) would be good enough, but this mirrors what `Arc` does and could be useful for other things too (like comparing if Arc and Weak point to the same thing without playing with the counts), while some opaque pointer wouldn't.

Some secondary questions, if this is deemed desirable are:
* The weak pointer may be dangling if it is created by `Weak::new()`. It would make sense to treat this as NULL, but that is incompatible with `T: ?Sized` ‒ both `new()` and `ptr::null()` are available only for sized types. The current implementation is therefore also available only for sized `T`s. It would be possible to allow `?Sized` if the API would be `fn into_raw(self) -> Option<NonNull<T>>` and `fn from_raw(NonNull<T>)`, but that's different API than `Arc` has. What would be preferred?
* There's a FIXME in my code about what I suspect could be UB. Is it really UB & how to get the pointer correctly? Is manual offsetting of the pointer the only way?
* Am I missing some other necessary thing around the feature gates and such?
* Is the documentation understandable? I know writing docs is not my strongest skill :-|.

Thinks I'd like to do as part of the PR, but are not yet done:
* Turn the referenced issue into tracking issue for the feature flag.
* Once the `sync::Weak` is considered reasonable, I'd do the equivalent for `rc::Weak`.
* This might call for few more tests than what is currently part of the documentation.
2019-05-29 08:15:53 +02:00
..
benches improve worst-case performance of BTreeSet difference and intersection 2019-03-29 12:18:20 +01:00
collections Revert "Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators." 2019-05-22 14:09:34 -07:00
prelude Stabilize the alloc crate. 2019-04-12 20:07:30 +02:00
tests add test checking that Vec push/pop does not invalidate pointers 2019-05-25 10:11:00 +02:00
alloc.rs Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
borrow.rs warn(missing_docs) in liballoc, and add missing docs 2019-04-15 16:35:50 +02:00
boxed.rs Update src/liballoc/boxed.rs 2019-05-27 22:42:50 +03:00
boxed_test.rs liballoc: revert nested imports style changes. 2019-02-03 08:27:44 +01:00
Cargo.toml Update the compiler_builtins crate 2019-05-17 07:17:15 -07:00
fmt.rs Make clear that format padding doesn't work for Debug 2019-04-13 15:39:49 +10:00
lib.rs stabilize core parts of MaybeUninit and deprecate mem::uninitialized in the future 2019-05-20 10:44:02 +02:00
macros.rs Bootstrap compiler update for 1.35 release 2019-03-02 09:05:34 -07:00
raw_vec.rs avoid materializing unintialized Boxes in RawVec 2019-05-27 11:15:31 +03:00
rc.rs rc::Weak::{as,from,into}_raw 2019-05-26 08:53:59 +02:00
slice.rs Ban multi-trait objects via trait aliases. 2019-05-20 16:12:49 +01:00
str.rs Implement BorrowMut<str> for String 2019-04-30 17:50:38 +09:00
string.rs Revert "Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators." 2019-05-22 14:09:34 -07:00
sync.rs sync::Weak::{as,from,into}_raw 2019-05-26 08:53:59 +02:00
vec.rs shadow as_ptr as as_mut_ptr in Vec to avoid going through Deref 2019-05-25 10:36:07 +02:00