Commit Graph

1608 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
e6e27924e1 liballoc: cargo check passes on 2018 2019-02-02 08:36:45 +01:00
Mazdak Farrokhzad
5594b0d5b8 liballoc => edition = 2018. 2019-02-02 08:36:03 +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
Andre Bogus
b062b75559 override VecDeque's Iter::try_fold 2019-01-30 09:11:17 +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
7e0edb39ba Implement a slightly racy sync::Weak::weak_count 2019-01-29 21:07:35 +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
Mazdak Farrokhzad
f21f83d117
Rollup merge of #57045 - RalfJung:kill-more-uninit, r=SimonSapin
Kill remaining uses of mem::uninitialized in libcore, liballoc

Kill remaining uses of mem::uninitialized in libcore and liballoc, and enable a lint that will warn when uses are added again in the future.

To avoid casting raw pointers around (which is always very dangerous because it is not typechecked at all -- it doesn't even get the "same size" sanity check that `transmute` gets), I also added two new functions to `MaybeUninit`:

```rust
    /// Get a pointer to the first contained values.
    pub fn first_ptr(this: &[MaybeUninit<T>]) -> *const T {
        this as *const [MaybeUninit<T>] as *const T
    }

    /// Get a mutable pointer to the first contained values.
    pub fn first_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T {
        this as *mut [MaybeUninit<T>] as *mut T
    }
```

I changed some of the existing code to use array-of-`MaybeUninit` instead of `MaybeUninit`-of-array, successfully removing raw pointer casts there as well.
2019-01-28 22:25:41 +01:00
Ralf Jung
6a52ca3fb4 rename first_mut_ptr -> first_ptr_mut 2019-01-28 12:37:29 +01:00
Ralf Jung
0e8fb93249 Use warn() for extra diagnostics; with -D warnings this leads to errors
This is needed to properly respect "deny_warnings = false" in config.toml
2019-01-28 10:49:11 +01:00
Ralf Jung
22a947f3aa add macro for creating uninitialized array 2019-01-28 10:48:38 +01:00
Ralf Jung
630aaa4e80 avoid some raw ptr casts in BTreeMap 2019-01-28 10:48:38 +01:00
Ralf Jung
ffd73df755 avoid mem::uninitialized in BTreeMap 2019-01-28 10:48:33 +01:00
Ralf Jung
c11e514e9d liballoc: remove unneeded allow(deprecated) 2019-01-28 10:39:49 +01:00
Wim Looman
0c203965e2 impl Generator for Pin<Box<Generator>> 2019-01-27 22:58:59 +01:00
Wim Looman
a3fdee9a75 Change generator trait to use pinning 2019-01-27 22:58:53 +01:00
Mark Rousskov
7a58c6d1de Replace deprecated ATOMIC_INIT consts 2019-01-26 15:27:38 -07:00
Mark Rousskov
b7f030e114 Bump bootstrap compiler to 1.33 beta 2019-01-26 08:02:08 -07:00
Mazdak Farrokhzad
77727feb18
Rollup merge of #57456 - fintelia:patch-4, r=dtolnay
RawVec doesn't always abort on allocation errors
2019-01-15 12:42:07 +01:00
Scott McMurray
1fd971c3b9 Add a debug_assert to Vec::set_len 2019-01-13 22:40:25 -08:00
Mazdak Farrokhzad
e69a5cb2d7
Rollup merge of #56425 - scottmcm:redo-vec-set_len-docs, r=Centril
Redo the docs for Vec::set_len

Inspired by the [recent conversation on IRLO](https://internals.rust-lang.org/t/make-vec-set-len-enforce-the-len-cap-invariant/8927/23?u=scottmcm).

This is just my first stab at this; suggestions welcome.
2019-01-12 10:54:51 +01:00
Mazdak Farrokhzad
5052197e44 explain safety for vec.set_len(0) 2019-01-09 04:17:24 +01:00
Jonathan Behrens
aa9bc68a1e
RawVec doesn't always abort on allocation errors 2019-01-08 17:21:30 -05:00
kennytm
676b0b0cc4
Rollup merge of #57313 - Nemo157:box-to-pin, r=cramertj
Improve Box<T> -> Pin<Box<T>> conversion

I found the `From` trait conversion for this very hard to find, having a named function for it is much more discoverable. Also fixes #56256 as I need that in the place I'm using this.

Has a placeholder tracking issue, will file an issue once I get feedback.
2019-01-05 23:56:58 +08:00
Wim Looman
d1a42ea8d0 Add discoverable function for converting Box<T> -> Pin<Box<T>> 2019-01-03 21:04:35 +01:00
Wim Looman
5e3a560299 Allow converting Box<T: !Sized> -> Pin<Box<T>> 2019-01-03 21:03:29 +01:00
Mazdak Farrokhzad
61fb909559
Update src/liballoc/vec.rs
Add @centril's comment

Co-Authored-By: scottmcm <scottmcm@users.noreply.github.com>
2019-01-02 21:05:37 -08:00
Czipperz
56d6ff0634 Mention ToString in std::fmt docs 2018-12-29 19:17:03 -05:00
bors
ee49bf8964 Auto merge of #55519 - fhartwig:hashmap-index-example, r=Centril
Add example of using the indexing operator to HashMap docs

Fixes #52575
2018-12-28 06:52:15 +00:00
Sunjay Varma
1e82618613 Stabilize duration_as_u128 2018-12-26 12:12:06 -07:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Mazdak Farrokhzad
1eb87869d1
Rollup merge of #55470 - daniellimws:box-from-docs, r=Centril
box: Add documentation for `From` impls

This is a part of #51430. A brief description of the behaviour and examples are added to the documentation.

I am not sure what sort of examples to put for the `From` for `Pin` as my [code](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=97c908f44e41c9faeffec5b61d72a03e) doesn't even manage to compile using the nightly build.

Somehow I feel that I missed out something so do let me know if more information is needed in the documentation or any of the examples require change.
2018-12-24 13:29:26 +01:00
Mazdak Farrokhzad
93bc72f19f
Rollup merge of #57032 - RalfJung:alloc-bench-deprecations, r=Centril
fix deprecation warnings in liballoc benches
2018-12-23 23:09:10 +01: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
5ba6a3438b
Rollup merge of #57002 - scottmcm:stabilize-resize_with, r=rkruppe
Stabilize Vec(Deque)::resize_with

Closes #41758
2018-12-23 02:12:15 +08: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
bors
9689ada838 Auto merge of #56842 - scottmcm:vecdeque-rotate, r=alexcrichton
Add unstable VecDeque::rotate_{left|right}

Like the ones on slices, but more efficient because vecdeque is a circular buffer.

Issue that proposed this: https://github.com/rust-lang/rust/issues/56686

~~💣 Please someone look very carefully at the `unsafe` in this!  The `wrap_copy` seems to be exactly what this method needs, and the `len` passed to it is never more than half the length of the deque, but I haven't managed to prove to myself that it's correct 💣~~ I think I proved that this code meets the requirement of the unsafe code it's calling; please double-check, of course.
2018-12-22 07:16:11 +00: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
Ralf Jung
3414be0b3e fix deprecation warnings in liballoc benches 2018-12-21 11:33:29 +01: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
Scott McMurray
7b6cf6e87b Stabilize Vec(Deque)::resize_with
Closes #41758
2018-12-19 22:00:25 -08:00
bors
74ebf026fe Auto merge of #56550 - chpio:rc-eq, r=alexcrichton
Short-circuit Rc/Arc equality checking on equal pointers where T: Eq

based on #42965

Is the use of the private trait ok this way? Is there anything else needed for this to get pulled?
2018-12-19 10:16:05 +00:00
Scott McMurray
cbe9abb78c Add more VecDeque::rotate_{left|right} tests 2018-12-19 00:53:48 -08:00
Andy Russell
82e55c1bdc
deny intra-doc link resolution failures in libstd 2018-12-17 21:10:24 -05:00
Mazdak Farrokhzad
c69ed5e5e9
Rollup merge of #56672 - ccouzens:master, r=nikic
Document time of back operations of a Linked List

Popping and pushing from the end of a linked list is constant time. This
documentation is already there for popping and pushing from the front.

@bors: r+ 38fe8d2 rollup
2018-12-16 14:08:21 +01:00
Mazdak Farrokhzad
9133798b92
Rollup merge of #56648 - RalfJung:btree, r=sfackler
Fix BTreeMap UB

BTreeMap currently causes UB by created a shared reference to a too-small allocation.  This PR fixes that by introducing a `NodeHeader` type and using that until we really need access to the key/value arrays.  Avoiding run-time checks in `into_key_slice` was somewhat tricky, see the comments embedded in the code.

I also adjusted `as_leaf_mut` to return a raw pointer, because creating a mutable reference asserts that there are no aliases to the pointee, but that's not always correct: We use `as_leaf_mut` twice to create two mutable slices for keys and values; the second call overlaps with the first slice and hence is not a unique pointer.

Fixes https://github.com/rust-lang/rust/issues/54957

Cc @nikomatsakis @Gankro
2018-12-16 14:08:19 +01:00