Use &raw in A|Rc::as_ptr by CAD97 · Pull Request #73845 · rust-lang/rust (original) (raw)

bors added a commit to rust-lang-ci/rust that referenced this pull request

Oct 3, 2020

@bors

Allow Weak::as_ptr and friends for unsized T

Relaxes impl<T> Weak<T> to impl<T: ?Sized> Weak<T> for the methods rc::Weak::as_ptr, into_raw, and from_raw.

Follow-up to rust-lang#73845, which did most of the impl work to make these functions work for T: ?Sized.

We still have to adjust the implementation of Weak::from_raw here, however, because I missed a use of ptr.is_null() previously. This check was necessary when into/from_raw were first implemented, as into_raw returned ptr::null() for dangling weak. However, we now just (wrapping) offset dangling weaks' pointers the same as nondangling weak, so the null check is no longer necessary (or even hit). (I can submit just 17a928f as a separate PR if desired.)

As a nice side effect, moves the fn is_dangling definition closer to Weak::new, which creates the dangling weak.

This technically stabilizes that "something like align_of_val_raw" is possible to do. However, I believe the part of the functionality required by these methods here -- specifically, getting the alignment of a pointee from a pointer where it may be dangling iff the pointee is Sized -- is uncontroversial enough to stabilize these methods without a way to implement them on stable Rust.

r? @RalfJung, who reviewed rust-lang#73845.

ATTN: This changes (relaxes) the (input) generic bounds on stable fn!