Commit Graph

354 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
c34ea91a9d
Rollup merge of #65778 - bdonlan:stable_weak_count, r=dtolnay
Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}`

* Original PR: #56696
* Tracking issue: #57977

Closes: #57977

Supporting comments:

> Although these were added for testing, it is occasionally useful to have a way to probe optimistically for whether a weak pointer has become dangling, without actually taking the overhead of manipulating atomics. Are there any plans to stabilize this?

_Originally posted by @bdonlan in https://github.com/rust-lang/rust/issues/57977#issuecomment-516970921_

> Having this stabilized would help. Currently, the only way to check if a weak pointer has become dangling is to call `upgrade`, which is by far expensive.

_Originally posted by @glebpom in https://github.com/rust-lang/rust/issues/57977#issuecomment-526934709_

Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now.

Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in `src/stdsimd`).
2019-12-16 05:23:26 +01:00
David Tolnay
9778e03665
Bump Weak::strong_count/weak_count stabilizations from 1.40 to 1.41 2019-12-14 19:26:25 -08:00
Mazdak Farrokhzad
bcf992dc6c
Rollup merge of #66710 - vorner:weak-into-raw-null-docs, r=dtolnay
weak-into-raw: Clarify some details in Safety

Clarify it is OK to pass a pointer that never owned a weak count (one
from Weak::new) back into it as it was created from it. Relates to
discussion in #60728.

@CAD97 Do you want to have a look at the new docs?
2019-12-05 19:03:08 +01:00
Michal 'vorner' Vaner
473151070b
weak-into-raw: Clarify some details in Safety
Clarify it is OK to pass a pointer that never owned a weak count (one
from Weak::new) back into it as it was created from it. Relates to
discussion in #60728.
2019-12-05 15:22:11 +01:00
bors
4787e97475 Auto merge of #66256 - CAD97:patch-2, r=RalfJung
Layout::pad_to_align is infallible

As per [this comment](https://github.com/rust-lang/rust/issues/55724#issuecomment-441421651) (cc @glandium).

> Per https://github.com/rust-lang/rust/blob/eb981a1/src/libcore/alloc.rs#L63-L65, `layout.size()` is always <= `usize::MAX - (layout.align() - 1)`.
>
> Which means:
>
> * The maximum value `layout.size()` can have is already aligned for `layout.align()` (`layout.align()` being a power of two, `usize::MAX - (layout.align() - 1)` is a multiple of `layout.align()`)
> * Incidentally, any value smaller than that maximum value will align at most to that maximum value.
>
> IOW, `pad_to_align` can not return `Err(LayoutErr)`, except for the layout not respecting its invariants, but we shouldn't care about that.

This PR makes `pad_to_align` return `Layout` directly, representing the fact that it cannot fail.
2019-12-03 01:50:33 +00:00
Tyler Mandry
941d915942
Rollup merge of #66128 - emilio:new-zeroed, r=SimonSapin
alloc: Add new_zeroed() versions like new_uninit().

MaybeUninit has both uninit() and zeroed(), it seems reasonable to have the same
surface on Box/Rc/Arc.

Needs tests.

cc #63291
2019-11-26 17:56:05 -06:00
Bryan Donlan
0d0b283c2c Make Weak::weak_count() return zero when no strong refs remain 2019-11-21 19:48:39 +00:00
Bryan Donlan
91ee3d1c31 Stabilize std::{rc,sync}::Weak::{weak_count, strong_count}
Closes: #57977
2019-11-21 18:33:03 +00:00
Christopher Durham
b688d480a6
Remove Layout::pad_to_align unwrap 2019-11-09 15:39:24 -05:00
Oleg Nosov
45f281d461
Reverted PhantomData in LinkedList, fixed PhantomData markers in Rc and Arc 2019-11-05 23:36:54 +03:00
Emilio Cobos Álvarez
b12e142bc5
alloc: Add new_zeroed() versions like new_uninit().
MaybeUninit has both uninit() and zeroed(), it seems reasonable to have the same
surface on Box/Rc/Arc.

Needs tests.
2019-11-05 19:27:42 +01:00
Ralf Jung
52a31f7a00 some more Rc tweaks 2019-10-19 13:47:32 +02:00
Ralf Jung
696cba6e25 the exampleis about drop, not (de)allocation 2019-10-19 10:14:10 +02:00
Ralf Jung
868a77263a more consistency and clarification 2019-10-17 19:51:42 +02:00
Ralf Jung
470e9d2789 Rc: value -> allocation 2019-10-17 19:37:05 +02:00
kalabukdima
e67fa776ee
Fix typo in docs for Rc 2019-10-13 15:46:28 +03:00
Lzu Tao
6c1b447f2e Remove unneeded fn main blocks from docs 2019-10-01 11:55:46 +00:00
Mazdak Farrokhzad
dee08ba55a
Rollup merge of #61797 - Thomasdezeeuw:stablise-weak_ptr_eq, r=RalfJung
Stabilise weak_ptr_eq

Implemented in #55987.

Closes #55981.
2019-09-14 22:16:03 +02:00
Alexander Regueiro
b0006dff10 A few cosmetic improvements to code & comments in liballoc and libcore 2019-09-06 16:02:25 +01:00
Thomas de Zeeuw
307804a00d Update {rc, sync}::Weak::ptr_eq doc about comparing Weak::new 2019-08-25 13:07:54 +02:00
Thomas de Zeeuw
d86516d91e Stabilise weak_ptr_eq 2019-08-25 13:06:57 +02:00
Simon Sapin
b79ce1b1b1 Rename private helper method allocate_for_unsized to allocate_for_layout 2019-08-17 17:01:04 +02:00
Simon Sapin
ba0328327c Doc nits
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-08-17 15:42:05 +02:00
Simon Sapin
7a641f7c51 Relax the safety condition for get_mut_unchecked 2019-08-16 17:45:44 +02:00
Simon Sapin
810dfd7cd4 Reuse more internal Rc and Arc methods 2019-08-16 17:45:08 +02:00
Simon Sapin
ae1e201a0c Add a comment on the usage of Layout:🆕:<RcBox<()>>() 2019-08-16 17:11:18 +02:00
Simon Sapin
78264f5e3c Add tracking issue numbers 2019-08-16 17:11:18 +02:00
Simon Sapin
1141136b90 Use ManuallyDrop instead of mem::forget
Per https://github.com/rust-lang/rust/pull/62451#discussion_r303197278
2019-08-16 17:11:18 +02:00
Simon Sapin
4eeb623e9e Fix intra-rustdoc links 2019-08-16 17:11:18 +02:00
Simon Sapin
170d933d2f Move constructors of boxed/rc’ed slices to matching impl blocks 2019-08-16 17:11:18 +02:00
Simon Sapin
bde1924059 Add new_uninit_slice and assume_init on Box, Rc, and Arc of [T] 2019-08-16 17:11:18 +02:00
Simon Sapin
7b02b9f8ec Add new_uninit and assume_init on Box, Rc, and Arc 2019-08-16 17:11:18 +02:00
Simon Sapin
1613fdae37 Add Rc::get_mut_unchecked, Arc::get_mut_unchecked 2019-08-16 17:11:18 +02:00
Jake Goulding
32324d22c3 Add implementations for converting boxed slices into boxed arrays
This mirrors the implementations of reference slices into arrays.
2019-08-05 10:26:53 -04:00
Vadim Petrochenkov
3d0d6ee271 liballoc: Unconfigure tests during normal build
Remove additional libcore-like restrictions from liballoc, turns out the testing works ok if the tests are a part of liballoc itself.
2019-08-02 01:59:01 +03:00
Mateusz Mikuła
f93032c818 Fix clippy::clone_on_copy warnings 2019-07-18 15:14:56 +02:00
bors
4a95e9704d Auto merge of #61953 - Centril:shared-from-iter, r=RalfJung
Add `impl<T> FromIterator<T> for Arc/Rc<[T]>`

Add implementations of `FromIterator<T> for Arc/Rc<[T]>` with symmetrical logic.

This also takes advantage of specialization in the case of iterators with known length (`TrustedLen`) to elide the final allocation/copying from a `Vec<T>` into `Rc<[T]>` because we can allocate the space for the `Rc<[T]>` directly when the size is known. This is the primary motivation and why this is to be preferred over `iter.collect::<Vec<_>>().into(): Rc<[T]>`.

Moreover, this PR does some refactoring in some places.

r? @RalfJung for the code
cc @alexcrichton from T-libs
2019-07-13 06:49:02 +00:00
Mazdak Farrokhzad
296e825afa
Rollup merge of #61862 - vorner:weak-into-raw-methods, r=sfackler
Make the Weak::{into,as}_raw methods

Because Weak doesn't Deref, so there's no reason for them to be only
associated methods.

As kindly pointed out here https://github.com/rust-lang/rust/pull/60766#issuecomment-501706422 by @chpio.
2019-07-06 22:14:35 +02:00
Mazdak Farrokhzad
85def307fc shared_from_iter: Polish internal docs. 2019-06-21 23:01:48 +02:00
Mazdak Farrokhzad
6b8417b55c shared_from_iter: Clarify slice::Iter specialization impl. 2019-06-20 23:20:21 +02:00
Mazdak Farrokhzad
85978d028a data_offset_align: add inline attribute. 2019-06-20 23:13:06 +02:00
Mazdak Farrokhzad
4b44ad9038 deduplicate slice_from_raw_parts_mut. 2019-06-20 09:28:13 +02:00
Mazdak Farrokhzad
353c8eb828 shared_from_iter/Rc: Use specialization to elide allocation. 2019-06-20 09:28:12 +02:00
Mazdak Farrokhzad
bf8f6c399b Rc: reduce duplicate calls. 2019-06-20 09:28:12 +02:00
Mazdak Farrokhzad
2efbc9e5a2 Rc: refactor data_offset{_sized}. 2019-06-20 09:28:12 +02:00
Mazdak Farrokhzad
19982f5653 Rc: refactor away PhantomData noise. 2019-06-20 09:28:12 +02:00
Mazdak Farrokhzad
689c64c469 Add basic 'shared_from_iter' impls. 2019-06-20 09:28:12 +02:00
Thomas Heck
387ac060d2 make Weak::ptr_eqs into methods 2019-06-16 14:05:44 +02:00
Michal 'vorner' Vaner
49fbd76a76
Make the Weak::{into,as}_raw methods
Because Weak doesn't Deref, so there's no reason for them to be only
associated methods.
2019-06-15 08:47:19 +02:00
bors
fc550d4295 Auto merge of #61421 - vorner:string-in-rc-into-raw-docs, r=RalfJung
docs: Use String in Rc::into_raw examples

It is unclear if accessing an integer after `drop_in_place` has been
called on it is undefined behaviour or not, as demonstrated by the
discussion in
https://github.com/rust-lang/rust/pull/60766#pullrequestreview-243414222.

Avoid these uncertainties by using String which frees memory in its
`drop_in_place` to make sure this is undefined behaviour. The message in
the docs should be to watch out and not access the data after that, not
discussing when one maybe could get away with it O:-).
2019-06-14 12:37:28 +00:00