Commit Graph

320 Commits

Author SHA1 Message Date
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
Michal 'vorner' Vaner
79e5839992
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-13 13:18:59 +02:00
Mazdak Farrokhzad
45cdc6d578
Rollup merge of #61135 - czipperz:rc-make_mut-weak-doc, r=Mark-Simulacrum
Fix documentation of `Rc::make_mut` regarding `rc::Weak`.

Closes #60961
2019-06-04 04:48:03 +02:00
Michal 'vorner' Vaner
4f1dcb34df
rc::Weak::{as,from,into}_raw
Methods on the Weak to access it as a raw pointer to the data.
2019-05-26 08:53:59 +02:00
Chris Gregory
b34b714a89 Remove unused import in doctest 2019-05-24 21:10:17 -05:00
Chris Gregory
fbe9f16bc2
Reword are not other to are no other
Co-Authored-By: Jonas Schievink <jonasschievink@gmail.com>
2019-05-24 21:08:59 -05:00
Chris Gregory
15241a4d41 Fix documentation of Rc::make_mut regarding rc::Weak. 2019-05-24 15:28:55 -05:00
Thomas Heck
740a8dabb4 add comment to Rc/Arc's Eq specialization 2019-05-11 11:03:28 +02:00
Scott McMurray
df4ea90b39 Use lifetime contravariance to elide more lifetimes in core+alloc+std 2019-03-09 19:10:28 -08:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad
2396780cda liballoc: revert nested imports style changes. 2019-02-03 08:27:44 +01:00
Mazdak Farrokhzad
857530cef1 liballoc: fix some idiom lints. 2019-02-02 12:48:12 +01:00
Mazdak Farrokhzad
f09f62f62c liballoc: adjust abolute imports + more import fixes. 2019-02-02 10:34:36 +01:00
Mazdak Farrokhzad
7693e3e666 liballoc: refactor & fix some imports. 2019-02-02 10:14:40 +01:00
Mazdak Farrokhzad
e6e27924e1 liballoc: cargo check passes on 2018 2019-02-02 08:36:45 +01:00
bors
f29b4fbd74 Auto merge of #56696 - jonas-schievink:weak-counts, r=alexcrichton
Implement Weak::{strong_count, weak_count}

The counters are also useful on `Weak`, not just on strong references (`Rc` or `Arc`).

In situations where there are still strong references around, you can also get these counts by temporarily upgrading and adjusting the values accordingly. Using the methods introduced here is simpler to do, less error-prone (since you can't forget to adjust the counts), can also be used when no strong references are around anymore, and might be more efficient due to not having to temporarily create an `Rc`.

This is mainly useful in assertions or tests of complex data structures. Data structures might have internal invariants that make them the sole owner of a `Weak` pointer, and an assertion on the weak count could be used to ensure that this indeed happens as expected. Due to the presence of `Weak::upgrade`, the `strong_count` becomes less useful, but it still seems worthwhile to mirror the API of `Rc`.

TODO:
* [X] Tracking issue - https://github.com/rust-lang/rust/issues/57977

Closes https://github.com/rust-lang/rust/issues/50158
2019-01-31 19:20:14 +00:00
Mazdak Farrokhzad
e8173a654d
Rollup merge of #57934 - dwijnand:from-Arc/Rc-to-NonNull, r=alexcrichton
Introduce into_raw_non_null on Rc and Arc

None
2019-01-31 02:10:44 +01:00
Jonas Schievink
0d314f08af Add tracking issue to unstable attribute 2019-01-29 22:34:35 +01:00
Jonas Schievink
b664341d91 Make weak_count return an Option<usize> 2019-01-29 21:58:17 +01:00
Jonas Schievink
2fe3b3b486 Implement Weak::{strong_count, weak_count} 2019-01-29 21:07:35 +01:00
Dale Wijnand
1e577269da
Introduce into_raw_non_null on Rc and Arc 2019-01-28 22:24:26 +00:00
Ralf Jung
c11e514e9d liballoc: remove unneeded allow(deprecated) 2019-01-28 10:39:49 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Mazdak Farrokhzad
93af1e7369
Rollup merge of #56939 - cramertj:pin-stabilization, r=alexcrichton
Pin stabilization

This implements the changes suggested in https://github.com/rust-lang/rust/issues/55766#issue-378417538 and stabilizes the `pin` feature. @alexcrichton also listed several "blockers" in that issue, but then in [this comment](https://github.com/rust-lang/rust/issues/55766#issuecomment-445074980) mentioned that they're more "TODO items":
>  In that vein I think it's fine for a stabilization PR to be posted at any time now with FCP lapsed for a week or so now. The final points about self/pin/pinned can be briefly discussed there (if even necessary, they could be left as the proposal above).

Let's settle these last bits here and get this thing stabilized! :)

r? @alexcrichton
cc @withoutboats
2018-12-23 23:09:04 +01:00
kennytm
14ebca5c19
Rollup merge of #56941 - euclio:deny-libstd-resolution-failures, r=QuietMisdreavus
deny intra-doc link resolution failures in libstd

Fixes #56693.

Until we land a fix for the underlying issue (#56922), we can at least fix the failures in libstd so they don't propagate to downstream crates.
2018-12-23 02:11:59 +08:00
Taylor Cramer
684fe9a6b2 Rename Box/Arc/Rc::pinned to ::pin 2018-12-21 20:42:50 -08:00
Taylor Cramer
610bcaf6f3 Stabilize Pin 2018-12-21 20:42:50 -08:00
Michael Hewson
153f5a7892 Stabilize Rc, Arc and Pin as method receivers
This lets you write methods using `self: Rc<Self>`, `self: Arc<Self>`, `self: Pin<&mut Self>`, `self: Pin<Box<Self>`, and other combinations involving `Pin` and another stdlib receiver type, without needing the `arbitrary_self_types`. Other user-created receiver types can be used, but they still require the feature flag to use.

This is implemented by introducing a new trait, `Receiver`, which the method receiver's type must implement if the `arbitrary_self_types` feature is not enabled. To keep composed receiver types such as `&Arc<Self>` unstable, the receiver type is also required to implement `Deref<Target=Self>` when the feature flag is not enabled.

This lets you use `self: Rc<Self>` and `self: Arc<Self>` in stable Rust, which was not allowed previously. It was agreed that they would be stabilized in #55786. `self: Pin<&Self>` and other pinned receiver types do not require the `arbitrary_self_types` feature, but they cannot be used on stable because `Pin` still requires the `pin` feature.
2018-12-20 01:14:01 -05:00
Andy Russell
82e55c1bdc
deny intra-doc link resolution failures in libstd 2018-12-17 21:10:24 -05:00
Thomas Heck
40d60a4608 Use private trait for Rc/Arc Eq specialization 2018-12-08 13:30:54 +01:00
Jo Liss
2a916a617f Short-circuit Rc/Arc equality checking on equal pointers where T: Eq
Closes #42655
2018-12-08 13:30:54 +01:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Pietro Albini
1594a4245b
Rollup merge of #55987 - Thomasdezeeuw:weak-ptr_eq, r=sfackler
Add Weak.ptr_eq

I hope the doc tests alone are good enough.

We also might want to discuss the dangling pointer case (from `Weak::new()`).

Updates #55981.
2018-12-05 23:54:24 +01:00
Thomas de Zeeuw
38e21f92f1 Fix link in Weak::new 2018-12-03 10:49:33 +01:00
Thomas de Zeeuw
380dd7d47b Add rc::Weak.ptr_eq 2018-12-03 10:49:27 +01:00