Commit graph

325 commits

Author SHA1 Message Date
blitzerr
219003bd2e replaced cell::update with cell::[g|s]et 2020-09-21 16:55:07 -07:00
blitzerr
7e443a1ffc Added feature flag to use cell_update 2020-09-21 16:43:36 -07:00
blitzerr
d9d02fa168 Changing the alloc() to accept &self instead of &mut self 2020-09-21 16:43:36 -07:00
Ralf Jung
4547ebb3fb
Rollup merge of #76983 - ssomers:btree_extra_test, r=Mark-Simulacrum
BTreeMap: extra testing & fixed comments

r? @Mark-Simulacrum
2020-09-21 15:30:46 +02:00
Ralf Jung
4b362bbbb6
Rollup merge of #76981 - pickfire:patch-5, r=Mark-Simulacrum
liballoc bench use imported path Bencher

test is already in scope, no need to use the full path
2020-09-21 15:30:44 +02:00
bors
a409a233e0 Auto merge of #75974 - SkiFire13:peekmut-opt-sift, r=LukasKalbertodt
Avoid useless sift_down when std::collections::binary_heap::PeekMut is never mutably dereferenced

If `deref_mut` is never called then it's not possible for the element to be mutated without internal mutability, meaning there's no need to call `sift_down`.

This could be a little improvement in cases where you want to mutate the biggest element of the heap only if it satisfies a certain predicate that needs only read access to the element.
2020-09-21 05:31:01 +00:00
Stein Somers
37ec045850 BTreeMap: extra testing unveiling mistakes in future PR 2020-09-20 20:07:05 +02:00
Ivan Tham
d99bb9d31c
liballoc bench use imported path Bencher
test is already in scope, no need to use the full path
2020-09-21 00:46:40 +08:00
Ralf Jung
0a4eb2c31d
Rollup merge of #76926 - ssomers:btree_cleanup_1, r=Mark-Simulacrum
BTreeMap: code readability tweaks

Gathered over the past months

r? @Mark-Simulacrum
2020-09-20 15:52:07 +02:00
Ralf Jung
ad9ea71e7f
Rollup merge of #76877 - denisvasilik:intra-doc-links-alloc-vec-deque, r=jyn514
Move to intra-doc links in collections/vec_deque.rs and collections/vec_deque/drain.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 15:51:54 +02:00
Ralf Jung
39412011a1
Rollup merge of #76876 - denisvasilik:intra-doc-links-alloc, r=jyn514
Move to intra-doc links in collections/btree/map.rs and collections/linked_list.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 15:51:53 +02:00
Ralf Jung
61a754832e
Rollup merge of #76875 - denisvasilik:intra-doc-links-alloc-binary-heap, r=jyn514
Move to intra-doc links in library/alloc/src/collections/binary_heap.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 15:51:51 +02:00
Ralf Jung
bea0ae700e
Rollup merge of #76866 - est31:master, r=lcnr
Remove unused feature gates from library/ crates

Removes some unused feature gates from library crates. It's likely not a complete list as I only tested a subset for which it's more likely that it is unused.
2020-09-20 15:51:50 +02:00
Ralf Jung
f5e19a355a
Rollup merge of #76722 - ssomers:btree_send_sync, r=Mark-Simulacrum
Test and fix Send and Sync traits of BTreeMap artefacts

Fixes #76686.

I'm not quite sure what all this implies. E.g. comparing with the definitions for `NodeRef` in node.rs,  maybe an extra bound `T: 'a` is useful for something. The test compiles on stable/beta (apart from `drain_filter`) so I bet `Sync` is equally desirable.

r? @Mark-Simulacrum
2020-09-20 12:08:12 +02:00
est31
562422ecf7 Remove some unused features from alloc core and std 2020-09-20 04:29:11 +02:00
Giacomo Stevanato
ca15e9d8a1 Fix time complexity in BinaryHeap::peek_mut docs 2020-09-20 01:12:02 +02:00
Giacomo Stevanato
af1e3633f7 Set sift=true only when PeekMut yields a mutable reference 2020-09-20 01:12:02 +02:00
Giacomo Stevanato
924cd135b6 Added benchmarks for BinaryHeap 2020-09-20 01:12:02 +02:00
Denis Vasilik
f9fa649545 Use intra-doc links 2020-09-19 23:30:52 +02:00
bors
f68e08933d Auto merge of #76929 - ssomers:btree_cleanup_2, r=Mark-Simulacrum
BTreeMap: wrap node's raw parent pointer in NonNull

Now that the other `*const` (root) is gone, seemed like a small step forward.

r? `@Mark-Simulacrum`
2020-09-19 19:15:06 +00:00
Stein Somers
0661b0a36d BTreeMap: wrap node's raw parent pointer in NonNull 2020-09-19 19:02:42 +02:00
Stein Somers
c6a8cfbde8 BTreeMap: code readability tweaks 2020-09-19 17:08:43 +02:00
Ralf Jung
46bb884cf3
Rollup merge of #76525 - fusion-engineering-forks:string-drain, r=dtolnay
Add as_str() to string::Drain.

Vec's Drain recently [had its `.as_slice()` stabilized](https://github.com/rust-lang/rust/pull/72584), but String's Drain was still missing the analogous `.as_str()`. This adds that.

Also improves the Debug implementation, which now shows the remaining data instead of just `"Drain { .. }"`.
2020-09-19 11:47:47 +02:00
Ralf Jung
fef3324043
Rollup merge of #76492 - fusion-engineering-forks:int-bits, r=dtolnay
Add associated constant `BITS` to all integer types

Recently I've regularly come across this snippet (in a few different crates, including `core` and `std`):
```rust
std::mem::size_of<usize>() * 8
```

I think it's time for a `usize::BITS`.
2020-09-19 11:47:45 +02:00
Ralf Jung
67fa7b78a4
Rollup merge of #76400 - pickfire:patch-5, r=dtolnay
Clean up vec benches bench_in_place style
2020-09-19 11:47:41 +02:00
Ralf Jung
bac2f39350
Rollup merge of #76310 - scottmcm:array-try_from-vec, r=dtolnay
Add `[T; N]: TryFrom<Vec<T>>` (insta-stable)

This is very similar to the [existing](https://doc.rust-lang.org/nightly/std/convert/trait.TryFrom.html#impl-TryFrom%3CBox%3C%5BT%5D%3E%3E) `Box<[T; N]>: TryFrom<Box<[T]>>`, but allows avoiding the `shrink_to_fit` if you have a vector and not a boxed slice.

Like the slice equivalents of this, it fails if the length of the vector is not exactly `N`.
This uses `Vec<T>` as the `Error` type to return the input, like how the `Rc<[T]> -> Rc<[T; N]>` (and Arc) ones also reflect the input directly in the error type.

```rust
#[stable(feature = "array_try_from_vec", since = "1.47.0")]
impl<T, const N: usize> TryFrom<Vec<T>> for [T; N] {
    type Error = Vec<T>;
    fn try_from(mut vec: Vec<T>) -> Result<[T; N], Vec<T>>;
}
```

Inspired by this zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/APIs.20for.20getting.20stuff.20from.20a.20Vec.20by.20owned/near/209048103
2020-09-19 11:47:39 +02:00
Mara Bos
15eb638dc9 Add tracking issue number for string_drain_as_str. 2020-09-19 08:23:23 +02:00
Mara Bos
1e2dba1e7c Use T::BITS instead of size_of::<T> * 8. 2020-09-19 06:54:42 +02:00
Denis Vasilik
719c40cb5a
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:44 +02:00
Denis Vasilik
62e0ee1ba0
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:35 +02:00
Denis Vasilik
ec7225feac
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:23 +02:00
Denis Vasilik
2230d8d14c
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:13 +02:00
Denis Vasilik
49c8fcb47e Use intra-doc links 2020-09-18 12:38:37 +02:00
Denis Vasilik
4af1b90b41 Move to intra-doc links 2020-09-18 12:38:25 +02:00
Denis Vasilik
bdb039d10b Use intra-doc links 2020-09-18 10:50:04 +02:00
est31
baafc71f1f Remove unused libc feature gate
Libc isn't used by alloc.
And std and panic_* use libc from crates.io now,
which isn't feature gated.
2020-09-18 08:59:43 +02:00
bors
a0925fba74 Auto merge of #76790 - ssomers:btree_slice_slasher_returns, r=Mark-Simulacrum
BTreeMap: avoid slices even more

Epilogue to #73971: it seems the compiler is unable to realize that creating a slice and `get_unchecked`-ing one element is a simple fetch. So try to spell it out for the only remaining but often invoked case.

Also, the previous code doesn't seem fair game to me, using `get_unchecked` to reach beyond the end of a slice. Although the local function `slice_insert` also does that.

r? `@Mark-Simulacrum`
2020-09-18 05:47:00 +00:00
Tyler Mandry
23a677787e
Rollup merge of #75026 - JulianKnodt:array_windows, r=Amanieu
Add array_windows fn

This mimicks the functionality added by array_chunks, and implements a const-generic form of
`windows`. It makes egregious use of `unsafe`, but by necessity because the array must be
re-interpreted as a slice of arrays, and unlike array_chunks this cannot be done by casting the
original array once, since each time the index is advanced it needs to move one element, not
`N`.

I'm planning on adding more tests, but this should be good enough as a premise for the functionality.
Notably: should there be more functions overwritten for the iterator implementation/in general?

~~I've marked the issue as #74985 as there is no corresponding exact issue for `array_windows`, but it's based of off `array_chunks`.~~

Edit: See Issue #75027 created by @lcnr for tracking issue

~~Do not merge until I add more tests, please.~~

r? @lcnr
2020-09-16 12:24:03 -07:00
kadmin
f240abc1dc Add array window fn
Updated issue to #75027

Update to rm oob access

And hopefully fix docs as well

Fixed naming conflict in test

Fix test which used 1-indexing

Nth starts from 0, woops

Fix a bunch of off by 1 errors

See https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=757b311987e3fae1ca47122969acda5a

Add even more off by 1 errors

And also write `next` and `next_back` in terms of `nth` and `nth_back`.

Run fmt

Fix forgetting to change fn name in test

add nth_back test & document unsafe

Remove as_ref().unwrap()
Documented occurrences of unsafe, noting what invariants are maintained
2020-09-16 14:52:20 +00:00
Ralf Jung
9d0a265b6c
Rollup merge of #76662 - RalfJung:lib-test-miri, r=Mark-Simulacrum
Fix liballoc test suite for Miri

Mostly, fix the regression introduced by https://github.com/rust-lang/rust/pull/75207 that caused slices (i.e., references) to be created to invalid memory or memory that has aliasing pointers that we want to keep valid. @dylni  this changes the type of `check_range` to only require the length, not the full reference to the slice, which indeed is all the information this function requires.

Also reduce the size of a test introduced in https://github.com/rust-lang/rust/pull/70793 to make it not take 3 minutes in Miri.

This makes https://github.com/RalfJung/miri-test-libstd work again.
2020-09-16 08:25:02 +02:00
Ralf Jung
17015cd5af
Rollup merge of #76534 - notriddle:doc-comments, r=jyn514
Add doc comments for From impls

https://github.com/rust-lang/rust/issues/51430
2020-09-16 08:24:56 +02:00
Ralf Jung
3a4de42a8d
Rollup merge of #76369 - ayushmishra2005:move_various_str_tests_library, r=jyn514
Move Various str tests in library

Moved various string ui  tests in library  as a part of #76268

r? @matklad
2020-09-16 08:24:54 +02:00
Ralf Jung
fd86705a20
Rollup merge of #76062 - pickfire:patch-13, r=jyn514
Vec slice example fix style and show type elision
2020-09-16 08:24:46 +02:00
Ralf Jung
73858d01c3
Rollup merge of #76056 - pickfire:patch-10, r=jyn514
Add more info for Vec Drain doc

See its documentation for more
2020-09-16 08:24:40 +02:00
Dylan DPC
c9105185de
Rollup merge of #75882 - pickfire:patch-6, r=jyn514
Use translated variable for test string

Test should be educative, added english translation and pronounciation.
2020-09-16 01:30:36 +02:00
Dylan DPC
fb9bb2b5ca
Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-Simulacrum
Detect overflow in proc_macro_server subspan

* Detect overflow in proc_macro_server subspan
* Add tests for overflow in Vec::drain
* Add tests for overflow in String / VecDeque operations using ranges
2020-09-16 01:30:30 +02:00
Stein Somers
378b64392f BTreeMap: avoid slices even more 2020-09-16 01:10:44 +02:00
Ralf Jung
c528d24196 fix slice::check_range aliasing problems 2020-09-15 23:14:41 +02:00
Ralf Jung
d888725fba reduce size of test_from_iter_specialization_with_iterator_adapters test in Miri 2020-09-15 23:03:07 +02:00
Stein Somers
176956c115 Test and fix Sync & Send traits of BTreeMap artefacts 2020-09-15 13:46:35 +02:00