]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Auto merge of #74160 - CAD97:weak-as-unsized-ptr, r=RalfJung
authorbors <bors@rust-lang.org>
Sat, 3 Oct 2020 14:18:26 +0000 (14:18 +0000)
committerbors <bors@rust-lang.org>
Sat, 3 Oct 2020 14:18:26 +0000 (14:18 +0000)
commit738d4a7a368b4da8bfa31915f06bb1ddce9e9980
treeaef9e5ebc6fe00349b58ec4667b6726d6365720b
parent6f56fbdc1c58992a9db630f5cd2ba9882d32e84b
parente27ef130c1d1cc7d8c3779a4e66e413a7a943ad4
Auto merge of #74160 - CAD97:weak-as-unsized-ptr, r=RalfJung

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 #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 #73845.

ATTN: This changes (relaxes) the (input) generic bounds on stable fn!
library/alloc/src/rc.rs
library/alloc/src/sync.rs