Commit graph

606 commits

Author SHA1 Message Date
Jonas Schievink
738a41b363
Rollup merge of #77449 - ssomers:btree_drain_filter_size_hint, r=Mark-Simulacrum
BTreeMap: comment why drain_filter's size_hint is somewhat pessimistic

The `size_hint` of the `DrainFilter` iterator doesn't adjust as you iterate. This hardly seems important to me, but there has been a comparable PR #64383 in the past. I guess a scenario is that you first iterate half the map manually and keep most of the key/value pairs in the map, and then tell the predicate to drain most of the key/value pairs and `.collect` the iterator over the remaining half of the map.

I am totally ambivalent whether this is better or not.

r? @Mark-Simulacrum
2020-10-08 23:23:08 +02:00
Ivan Tham
176b96516f
Link Vec leak doc to Box 2020-10-08 23:39:31 +08:00
Jacob Hughes
bf0adc3c36 Rename LayoutErr to LayoutError outside of core 2020-10-08 00:40:10 -04:00
bors
5779815f89 Auto merge of #74194 - mbrubeck:slice-eq, r=sfackler
Add PartialEq impls for Vec <-> slice

This is a follow-up to #71660 and rust-lang/rfcs#2917 to add two more missing vec/slice PartialEq impls:

```
impl<A, B> PartialEq<[B]> for Vec<A> where A: PartialEq<B> { .. }
impl<A, B> PartialEq<Vec<B>> for [A] where A: PartialEq<B> { .. }
```

Since this is insta-stable, it should go through the `@rust-lang/libs` FCP process.  Note that I used version 1.47.0 for the `stable` attribute because I assume this will not merge before the 1.46.0 branch is cut next week.
2020-10-07 01:20:11 +00:00
Tim Diekmann
f288cd2e17 Support custom allocators in Box
Remove `Box::leak_with_alloc`


Add leak-test for box with allocator


Rename `AllocErr` to `AllocError` in leak-test


Add `Box::alloc` and adjust examples to use the new API
2020-10-07 03:07:02 +02:00
Ralf Jung
fa6a4f7d37 avoid unnecessary intermediate reference and improve safety comments 2020-10-06 10:54:43 +02:00
Stein Somers
97beb074af BTreeMap: derive type-specific variants of node_as_mut and cast_unchecked 2020-10-05 13:23:38 +02:00
Ralf Jung
69669cbdb2 make IterMut Send/Sync again 2020-10-05 09:12:56 +02:00
Ralf Jung
e4c1a3867f VecDeque: avoid more aliasing issues by working with raw pointers instead of references 2020-10-05 09:12:56 +02:00
Ralf Jung
f251dc446f VecDeque: fix incorrect &mut aliasing in IterMut::next/next_back 2020-10-05 09:12:54 +02:00
Dylan DPC
9dbc9ed870
Rollup merge of #77514 - scottmcm:less-once-chain-once, r=estebank
Replace some once(x).chain(once(y)) with [x, y] IntoIter

Now that we have by-value array iterators that are [already used](25c8c53dd9/compiler/rustc_hir/src/def.rs (L305-L307))...

For example,
```diff
-        once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
+        IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
```
2020-10-05 02:29:42 +02:00
Dylan DPC
23b1e3d772
Rollup merge of #77471 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BTreeMap: refactoring around edges, missed spots

Tweaks from #77244 (and more) that are really inconsistencies in #77005.

r? @Mark-Simulacrum
2020-10-05 02:29:38 +02:00
Dylan DPC
fe087ece94
Rollup merge of #77395 - ssomers:btree_love_the_leaf_edge_comments, r=Mark-Simulacrum
BTreeMap: admit the existence of leaf edges in comments

The btree code is ambiguous about leaf edges (i.e., edges within leaf nodes). Iteration relies on them heavily, but some of the comments suggest there are no leaf edges (extracted from #77025)

r? @Mark-Simulacrum
2020-10-05 02:29:31 +02:00
Jonas Schievink
80953177ed
Rollup merge of #77445 - ssomers:btree_cleanup_7, r=Mark-Simulacrum
BTreeMap: complete the compile-time test_variance test case

Some of the items added to the new `test_sync` belonged in the old `test_variance` as well. And fixed inconsistent paths to nearby modules.
r? @Mark-Simulacrum
2020-10-04 15:45:41 +02:00
bors
0d37dca25a Auto merge of #76448 - haraldh:default_alloc_error_handler_reduced, r=Amanieu
Implement Make `handle_alloc_error` default to panic (for no_std + liballoc)

Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.
2020-10-04 08:56:05 +00:00
Yuki Okushi
25d0650d0f
Rollup merge of #77447 - ssomers:btree_cleanup_8, r=Mark-Simulacrum
BTreeMap: document DrainFilterInner better

r? @Mark-Simulacrum
2020-10-04 11:45:04 +09:00
Scott McMurray
d74b8e0505 Replace some once(x).chain(once(y)) with [x, y] IntoIter
Now that we have by-value array iterators...
2020-10-03 16:51:43 -07:00
Stein Somers
a58089e097 BTreeMap/Set: complete the compile-time test cases 2020-10-04 01:04:29 +02:00
Stein Somers
3b051d0171 BTreeMap: comment why drain_filter's size_hint is somewhat pessimistictid 2020-10-03 21:18:18 +02:00
bors
738d4a7a36 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!
2020-10-03 14:18:26 +00:00
Ralf Jung
e27ef130c1
grammar nit 2020-10-03 12:15:26 +02:00
Stein Somers
d71d13e82d BTreeMap: refactoring around edges, missed spots 2020-10-03 01:06:55 +02:00
Jonas Schievink
1118ab9930
Rollup merge of #75377 - canova:map_debug_impl, r=dtolnay
Fix Debug implementations of some of the HashMap and BTreeMap iterator types

HashMap's `ValuesMut`, BTreeMaps `ValuesMut`, IntoValues and `IntoKeys` structs were printing both keys and values on their Debug implementations. But they are iterators over either keys or values. Irrelevant values should not be visible. With this PR, they only show relevant fields.
This fixes #75297.

[Here's an example code.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0c79356ed860e347a0c1a205616f93b7) This prints this on nightly:
```
ValuesMut { inner: IterMut { range: [(1, "hello"), (2, "goodbye")], length: 2 } }
IntoKeys { inner: [(1, "hello"), (2, "goodbye")] }
IntoValues { inner: [(1, "hello"), (2, "goodbye")] }
[(2, "goodbye"), (1, "hello")]
```

After the patch this example prints these instead:
```
["hello", "goodbye"]
["hello", "goodbye"]
[1, 2]
["hello", "goodbye"]
```

I didn't add test cases for them, since I couldn't see any tests for Debug implementations anywhere. But please let me know if I should add it to a specific place.

r? @dtolnay
2020-10-03 00:31:04 +02:00
Stein Somers
90c8b43bc3 BTreeMap: document DrainFilterInner better 2020-10-02 13:13:28 +02:00
Harald Hoyer
cadd12b5f0 Implement Make handle_alloc_error default to panic (for no_std + liballoc)
Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.

The panic message does not contain the size anymore, because it would
pull in the fmt machinery, which would blow up the code size
significantly.
2020-10-02 09:00:29 +02:00
Stein Somers
424347527d BTreeMap: use Unique::from to avoid a cast where type information exists 2020-10-01 15:03:51 +02:00
Stein Somers
df76cf89ad BTreeMap: admit the existence of leaf edges in comments 2020-10-01 13:20:39 +02:00
bors
00730fd0f1 Auto merge of #77383 - pickfire:patch-6, r=Mark-Simulacrum
Fix typo in vec doc "tries to reserves"

Superseeds #77192
2020-10-01 05:35:48 +00:00
Ivan Tham
86e30b605c
Fix typo in vec doc "tries to reserves" 2020-10-01 10:08:51 +08:00
Dylan DPC
70740b1b82
Rollup merge of #77315 - exrook:rename-allocerror, r=joshtriplett
Rename AllocErr to AllocError

Implements rust-lang/wg-allocators#57
2020-10-01 02:13:39 +02:00
Jonas Schievink
fea2ad8a0a
Rollup merge of #77340 - pickfire:patch-9, r=kennytm
Alloc vec use imported path

mem::ManuallyDrop::new -> ManuallyDrop::new

cc @the8472
2020-09-30 20:56:21 +02:00
Jonas Schievink
054ba3db2d
Rollup merge of #77338 - pickfire:patch-7, r=jyn514
Fix typo in alloc vec comment

cc @the8472
2020-09-30 20:56:19 +02:00
Jonas Schievink
7ad03dd91d
Rollup merge of #77233 - ssomers:btree_size_matters, r=Mark-Simulacrum
BTreeMap: keep an eye out on the size of the main components

r? @Mark-Simulacrum
2020-09-30 20:56:07 +02:00
Ivan Tham
f9b625f8e0
Alloc vec use imported path
mem::ManuallyDrop::new -> ManuallyDrop::new
2020-09-29 23:00:02 +08:00
Ivan Tham
b141e49d87
Fix typo in alloc vec comment 2020-09-29 22:33:57 +08:00
Ivan Tham
55ba9e4755
Reorder benches const variable
Move LEN so it is is read in order.
2020-09-29 21:39:24 +08:00
bors
9e34b72964 Auto merge of #77253 - jyn514:crate-link, r=Manishearth
Resolve `crate` in intra-doc links properly across crates

Closes https://github.com/rust-lang/rust/issues/77193; see https://github.com/rust-lang/rust/issues/77193#issuecomment-699065946 for an explanation of what's going on here.
~~This also fixes the BTreeMap docs that have been broken for a while; see the description on the second commit for why and how.~~ Nope, see the second commit for why the link had to be changed.

r? `@Manishearth`
cc `@dylni`

`@dylni` note that this doesn't solve your original problem - now _both_ `with_code` and `crate::with_code` will be broken links. However this will fix a lot of other broken links (in particular I think https://docs.rs/sqlx/0.4.0-beta.1/sqlx/query/struct.Query.html is because of this bug). I'll open another issue for resolving additional docs in the new scope.
2020-09-29 12:11:17 +00:00
Jacob Hughes
5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
Ralf Jung
734c57d45c
Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad
UI to unit test for those using Cell/RefCell/UnsafeCell

Helps with #76268.

I'm working on all files using `Cell` and moving them to unit tests when possible.

r? @matklad
2020-09-28 18:39:39 +02:00
Joshua Nelson
406584621a Use relative links instead of intra-doc links
Previously, `BTreeMap` tried to link to `crate::collections`, intending
for the link to go to `std/collections/index.html`. But `BTreeMap` is
defined in `alloc`, so after the fix in the previous commit, the links
instead went to `alloc/collections/index.html`, which has almost no
information.

This changes it to link to `index.html`, which only works when viewing
from `std::collections::BTreeMap`, the most common place to visit the
docs. Fixing it to work from anywhere would require the docs for
`std::collections` to be duplicated in `alloc::collections`, which in
turn would require HashMap to be `alloc` for intra-doc links to work
(https://github.com/rust-lang/rust/issues/74481).
2020-09-27 11:28:13 -04:00
Jonas Schievink
bb416f3a59
Rollup merge of #77184 - pickfire:patch-4, r=kennytm
Rust vec bench import specific rand::RngCore

Using `RngCore` import for side effects is clearer than `*` which may bring it unnecessary more stuff than needed, it is also more explicit doing so.

@pickfire change `LEN = 16384` (and pos) and `once` instead of `[0].iter()` after this.

@rustbot modify labels: +C-cleanup +A-testsuite
2020-09-27 01:53:22 +02:00
Stein Somers
3e485d7cf5 BTreeMap: keep an eye out on the size of the main components 2020-09-26 20:07:48 +02:00
bors
043f6d747c Auto merge of #77201 - matthewjasper:rename-get-unchecked, r=spastorino
Rename Iterator::get_unchecked

Closes #76479

r? `@pnkfelix`
2020-09-25 21:44:26 +00:00
Alexis Bourget
a61b9638bb review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
Matthew Jasper
04a0b1d087 Rename Iterator::get_unchecked
It's possible for method resolution to pick this method over a lower
priority stable method,  causing compilation errors. Since this method
is permanently unstable, give it a name that is very unlikely to be used
in user code.
2020-09-25 19:52:01 +01:00
Matthew Jasper
323a27967a Improve <vec::IntoIter>::get_unchecked` safety comment 2020-09-25 19:46:06 +01:00
Jonas Schievink
d72b7cc329
Rollup merge of #77189 - pickfire:patch-5, r=Mark-Simulacrum
Remove extra space from vec drawing
2020-09-25 19:42:54 +02:00
Jonas Schievink
e8dc07c242
Rollup merge of #77005 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BtreeMap: refactoring around edges

Parts chipped off a more daring effort, that the btree benchmarks judge to be performance-neutral.

r? @Mark-Simulacrum
2020-09-25 19:42:31 +02:00
Ivan Tham
606ed2a076
Remove extra space from vec drawing 2020-09-25 23:20:22 +08:00
Ivan Tham
939fd37643
Rust vec bench import specific rand::RngCore 2020-09-25 22:19:28 +08:00
Stein Somers
55fa8afe94 BTreeMap: various tweaks 2020-09-25 11:29:39 +02:00
Stein Somers
3965524570 BTreeMap: introduce edge methods similar to those of keys and values 2020-09-25 11:29:38 +02:00
Stein Somers
1e64d98761 BTreeMap: refactor correct_childrens_parent_links 2020-09-25 11:29:38 +02:00
Jonas Schievink
dc4f39c43f
Rollup merge of #77079 - poliorcetics:more-self-in-docs, r=jyn514
Use `Self` in docs when possible

Fixes #76542.

I used `rg '\s*//[!/]\s+fn [\w_]+\(&?self, ' .` in `library/` to find instances, I found some with that and some by manually checking.

@rustbot modify labels: C-enhancement T-doc
2020-09-25 02:29:42 +02:00
Jonas Schievink
862faea4be
Rollup merge of #77050 - follower:patch-1, r=oli-obk
Typo fix: "satsify" -> "satisfy"
2020-09-25 02:29:37 +02:00
Jonas Schievink
67bcf04bdb
Rollup merge of #77044 - pickfire:patch-4, r=jyn514
Liballoc bench vec use mem take not replace
2020-09-25 02:29:35 +02:00
Dylan DPC
b76343643d
Rollup merge of #77017 - GuillaumeGomez:vec-missing-examples-iter, r=Dylan-DPC
Add missing examples on Vec iter types

r? @Dylan-DPC
2020-09-23 14:54:10 +02:00
Dylan DPC
a40d79c9fb
Rollup merge of #76993 - blitzerr:alloc-ref, r=Amanieu
Changing the alloc() to accept &self instead of &mut self

Fixes: [#55](https://github.com/rust-lang/wg-allocators/issues/55)

This is the first cut. It only makes the change for `alloc` method.
2020-09-23 14:54:06 +02:00
blitzerr
2b19b14cec a few more &mut self -> self changes 2020-09-22 21:04:31 -07:00
Alexis Bourget
ec4e9cd12a Use Self in alloc 2020-09-23 00:31:37 +02:00
Dylan MacKenzie
110e59e70e Update library functions with stability attributes
This may not be strictly minimal, but all unstable functions also need a
`rustc_const_unstable` attribute.
2020-09-22 10:05:58 -07:00
blitzerr
3ffd403c6b removing &mut self for other methods of AllocRef 2020-09-22 06:22:02 -07:00
Guillaume Gomez
143557ec56 Add missing examples on Vec iter types 2020-09-22 13:47:06 +02:00
follower
0082d201f1
Typo fix: "satsify" -> "satisfy" 2020-09-22 20:54:07 +12:00
Ivan Tham
4a6bc77a01
Liballoc bench vec use mem take not replace 2020-09-22 14:26:15 +08:00
ecstatic-morse
11f7bfab91
Rollup merge of #72734 - pickfire:liballoc, r=KodrAus
Reduce duplicate in liballoc reserve error handling

Not sure if it affects compilation time.
2020-09-21 20:40:37 -07:00
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
Alexis Bourget
f6a4189d05 Move vec-cycle-wrapped test 2020-09-21 21:50:27 +02:00
Alexis Bourget
6bc0357dad Move vec-cycle test 2020-09-21 21:50:27 +02:00
Alexis Bourget
ed52c7bb75 Move deref-lval test 2020-09-21 21:50:26 +02:00
Alexis Bourget
949c96660c move format! interface tests 2020-09-21 21:50:26 +02: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
dylni
f055b0bb08 Rename method to assert_len 2020-09-18 13:55:03 -04:00
dylni
1ff7da6551 Move slice::check_range to RangeBounds 2020-09-18 12:17:51 -04: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
Ivan Tham
1f572b0349
Vec doc use elision as code rather than comment 2020-09-15 14:41:43 +08:00
bors
6cae28165f Auto merge of #76682 - richkadel:vec-take, r=Mark-Simulacrum
Optimize behavior of vec.split_off(0) (take all)

Optimization improvement to `split_off()` so the performance meets the
intuitively expected behavior when `at == 0`, avoiding the current behavior
of copying the entire vector.

The change honors documented behavior that the original vector's
"previous capacity unchanged".

This improvement better supports the pattern for building and flushing a
buffer of elements, such as the following:

```rust
    let mut vec = Vec::new();
    loop {
        vec.push(something);
        if condition_is_met {
            process(vec.split_off(0));
        }
    }
```

`Option` wrapping is the first alternative I thought of, but is much
less obvious and more verbose:

```rust
    let mut capacity = 1;
    let mut vec: Option<Vec<Stuff>> = None;
    loop {
        vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something);
        if condition_is_met {
            capacity = vec.capacity();
            process(vec.take().unwrap());
        }
    }
```

Directly using `mem::replace()` (instead of  calling`split_off()`) could work,
but `mem::replace()` is a more advanced tool for Rust developers, and in
this case, I believe developers would assume the standard library should
be sufficient for the purpose described here.

The benefit of the approach to this change is it does not change the
existing API contract, but improves the peformance of `split_off(0)` for
`Vec`, `String` (which delegates `split_off()` to `Vec`), and any other
existing use cases.

This change adds tests to validate the behavior of `split_off()` with
regard to capacity, as originally documented, and confirm that behavior
still holds, when `at == 0`.

The change is an implementation detail, and does not require a
documentation change, but documenting the new behavior as part of its
API contract may benefit future users.

(Let me know if I should make that documentation update.)

Note, for future consideration:

I think it would be helpful to introduce an additional method to `Vec`
(if not also to `String`):

```
    pub fn take_all(&mut self) -> Self {
        self.split_off(0)
    }
```

This would make it more clear how `Vec` supports the pattern, and make
it easier to find, since the behavior is similar to other `take()`
methods in the Rust standard library.

r? `@wesleywiser`
FYI: `@tmandry`
2020-09-15 05:01:17 +00:00
Rich Kadel
79aa9b15d7 Optimize behavior of vec.split_off(0) (take all)
Optimization improvement to `split_off()` so the performance meets the
intuitively expected behavior when `at == 0`, avoiding the current
behavior of copying the entire vector.

The change honors documented behavior that the method leaves the
original vector's "previous capacity unchanged".

This improvement better supports the pattern for building and flushing a
buffer of elements, such as the following:

```rust
    let mut vec = Vec::new();
    loop {
        vec.push(something);
        if condition_is_met {
            process(vec.split_off(0));
        }
    }
```

`Option` wrapping is the first alternative I thought of, but is much
less obvious and more verbose:

```rust
    let mut capacity = 1;
    let mut vec: Option<Vec<Stuff>> = None;
    loop {
        vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something);
        if condition_is_met {
            capacity = vec.capacity();
            process(vec.take().unwrap());
        }
    }
```

Directly applying `mem::replace()` could work, but `mem::` functions are
typically a last resort, when a developer is actively seeking better
performance than the standard library provides, for example.

The benefit of the approach to this change is it does not change the
existing API contract, but improves the peformance of `split_off(0)` for
`Vec`, `String` (which delegates `split_off()` to `Vec`), and any other
existing use cases.

This change adds tests to validate the behavior of `split_off()` with
regard to capacity, as originally documented, and confirm that behavior
still holds, when `at == 0`.

The change is an implementation detail, and does not require a
documentation change, but documenting the new behavior as part of its
API contract may benefit future users.

(Let me know if I should make that documentation update.)

Note, for future consideration:

I think it would be helpful to introduce an additional method to `Vec`
(if not also to `String`):

```
    pub fn take_all(&mut self) -> Self {
        self.split_off(0)
    }
```

This would make it more clear how `Vec` supports the pattern, and make
it easier to find, since the behavior is similar to other `take()`
methods in the Rust standard library.
2020-09-13 14:32:29 -07:00
Jonas Schievink
fe716d0447
Rollup merge of #76677 - RalfJung:stable-pointers, r=jonas-schievink
note that test_stable_pointers does not reflect a stable guarantee

Just to be sure...
2020-09-13 20:21:24 +02:00
Jonas Schievink
e5389a4a34
Rollup merge of #76527 - fusion-engineering-forks:cleanup-uninit, r=jonas-schievink
Remove internal and unstable MaybeUninit::UNINIT.

Looks like it is no longer necessary, as `uninit_array()` can be used instead in the few cases where it was needed.

(I wanted to just add `#[doc(hidden)]` to remove clutter from the documentation, but looks like it can just be removed entirely.)
2020-09-13 20:21:09 +02:00
Ralf Jung
71a5c464d1 note that test_stable_pointers does not reflect a stable guarantee 2020-09-13 18:55:08 +02:00
bors
989190874f Auto merge of #76538 - fusion-engineering-forks:check-useless-unstable-trait-impl, r=lcnr
Warn for #[unstable] on trait impls when it has no effect.

Earlier today I sent a PR with an `#[unstable]` attribute on a trait `impl`, but was informed that this attribute has no effect there. (comment: https://github.com/rust-lang/rust/pull/76525#issuecomment-689678895, issue: https://github.com/rust-lang/rust/issues/55436)

This PR adds a warning for this situation. Trait `impl` blocks with `#[unstable]` where both the type and the trait are stable will result in a warning:

```
warning: An `#[unstable]` annotation here has no effect. See issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information.
   --> library/std/src/panic.rs:235:1
    |
235 | #[unstable(feature = "integer_atomics", issue = "32976")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

---

It detects three problems in the existing code:

1. A few `RefUnwindSafe` implementations for the atomic integer types in `library/std/src/panic.rs`. Example:
d92155bf6a/library/std/src/panic.rs (L235-L236)
2. An implementation of `Error` for `LayoutErr` in `library/std/srd/error.rs`:
d92155bf6a/library/std/src/error.rs (L392-L397)
3. `From` implementations for `Waker` and `RawWaker` in `library/alloc/src/task.rs`. Example:
d92155bf6a/library/alloc/src/task.rs (L36-L37)

Case 3 interesting: It has a bound with an `#[unstable]` trait (`W: Wake`), so appears to have much effect on stable code. It does however break similar blanket implementations. It would also have immediate effect if `Wake` was implemented for any stable type. (Which is not the case right now, but there are no warnings in place to prevent it.) Whether this case is a problem or not is not clear to me. If it isn't, adding a simple `c.visit_generics(..);` to this PR will stop the warning for this case.
2020-09-12 18:01:33 +00:00
CAD97
3d07108d36 Add tests for weak into/from raw 2020-09-12 10:38:33 -05:00
CAD97
9d9903c5a5 Allow Weak::as_ptr and friends for unsized T 2020-09-12 10:38:33 -05:00
CAD97
5e7406c956 Adjust sync::Weak::from_raw to support unsized T 2020-09-12 10:38:32 -05:00
CAD97
0c61ce2cf0 ?Sized bounds for rc::Weak::as_ptr and friends 2020-09-12 10:38:22 -05:00
CAD97
728938346b Adjust rc::Weak::from_raw to support unsized T 2020-09-12 10:27:43 -05:00
Ralf Jung
a49451c805
Rollup merge of #76530 - carbotaniuman:fix-rc, r=RalfJung
Eliminate mut reference UB in Drop impl for Rc<T>

This changes `self.ptr.as_mut()` with `get_mut_unchecked` which
does not use an intermediate reference.  Arc<T> already handled this
case properly.

Fixes #76509
2020-09-12 10:43:18 +02:00
bors
8b6838b6e1 Auto merge of #75021 - cuviper:array_chunks_mut, r=scottmcm
Add `slice::array_chunks_mut`

This follows `array_chunks` from #74373 with a mutable version, `array_chunks_mut`. The implementation is identical apart from mutability. The new tests are adaptations of the `chunks_exact_mut` tests, plus an inference test like the one for `array_chunks`.

I reused the unstable feature `array_chunks` and tracking issue #74985, but I can separate that if desired.

r? `@withoutboats`
cc `@lcnr`
2020-09-12 03:59:46 +00:00
bors
12c10e34a4 Auto merge of #73951 - pickfire:liballoc-intoiter, r=Mark-Simulacrum
Liballoc intoiter refactor
2020-09-11 23:52:03 +00:00
carbotaniuman
b729368d4e Address review comments 2020-09-11 07:25:28 -05:00
Mara Bos
471fb622aa Allow unstable From impl for [Raw]Waker. 2020-09-11 13:36:45 +02:00
bors
ee04f9a4da Auto merge of #74437 - ssomers:btree_no_root_in_noderef, r=Mark-Simulacrum
BTreeMap: move up reference to map's root from NodeRef

Since the introduction of `NodeRef` years ago, it also contained a mutable reference to the owner of the root node of the tree (somewhat disguised as *const). Its intent is to be used only when the rest of the `NodeRef` is no longer needed. Moving this to where it's actually used, thought me 2 things:
- Some sort of "postponed mutable reference" is required in most places that it is/was used, and that's exactly where we also need to store a reference to the length (number of elements) of the tree, for the same reason. The length reference can be a normal reference, because the tree code does not care about tree length (just length per node).
- It's downright obfuscation in `from_sorted_iter` (transplanted to #75329)
- It's one of the reasons for the scary notice on `reborrow_mut`, the other one being addressed in #73971.

This does repeat the raw pointer code in a few places, but it could be bundled up with the length reference.

r? `@Mark-Simulacrum`
2020-09-10 23:29:57 +00:00
Tyler Mandry
8bf03c3f62
Rollup merge of #76543 - ssomers:btree_cleanup_4, r=Mark-Simulacrum
Document btree's unwrap_unchecked

#74693's second wind
2020-09-09 21:02:36 -07:00
Stein Somers
f42dac0ce0 Document btree's unwrap_unchecked 2020-09-10 00:25:59 +02:00
Tyler Mandry
c18fa460a4
Rollup merge of #76504 - Flying-Toast:master, r=lcnr
Capitalize safety comments
2020-09-09 15:06:00 -07:00
Tyler Mandry
0d20cf8568
Rollup merge of #76481 - moonheart08:vec_deque_constify, r=sfackler
Convert repetitive target_pointer_width checks to const solution.

Simply a quick code tidying change. Not sure if more needs to be said.
2020-09-09 15:05:56 -07:00
Stein Somers
2b54ab880c BTreeMap: pull the map's root out of NodeRef 2020-09-10 00:02:54 +02:00
Michael Howell
8b0d0a0cad Add documentation for impl<T> From<BinaryHeap<T>> for Vec<T> 2020-09-09 11:53:24 -07:00
carbotaniuman
bb57c9f91c Format 2020-09-09 13:44:22 -05:00
carbotaniuman
8f43fa0989 Add WeakInner<'_> and have Weak::inner() return it
This avoids overlapping a reference covering the data field,
which may be changed due in concurrent conditions. This fully
fixed the UB mainfested with `new_cyclic`.
2020-09-09 13:39:48 -05:00
Mara Bos
829019d404 Disable AsRef implementations for String's Drain.
Since trait implementations cannot be unstable, we should only add them
when the as_str feature gets stabilized. Until then, only `.as_str()` is
available (behind a feature gate).
2020-09-09 19:57:57 +02:00
carbotaniuman
493c037699 Eliminate mut reference UB in Drop impl for Rc<T>
This changes `self.ptr.as_mut()` with `get_mut_unchecked` which
does not use an intermediate reference.  Arc<T> already handled this
case properly.
2020-09-09 12:14:18 -05:00
Mara Bos
f2a32909e0 Mark AsRef impls for String's Drain as stable.
Trait implementations effectively can't be #[unstable].
2020-09-09 19:10:06 +02:00
Mara Bos
4506d26cf3 Remove internal and unstable MaybeUninit::UNINIT.
Looks like it is no longer necessary, as uninit_array() can be used
instead in the few cases where it was needed.
2020-09-09 18:38:10 +02:00
Mara Bos
f5bb523e94 Add AsRef<[u8]> for String's Drain. 2020-09-09 18:07:27 +02:00
Mara Bos
673284058b Show remaining data in string::Drain's Debug impl. 2020-09-09 17:50:55 +02:00
Mara Bos
daa62d9081 Add as_str() and AsRef to string::Drain. 2020-09-09 17:50:55 +02:00
Stein Somers
8158d5623e BTreeMap: avoid aliasing by avoiding slices 2020-09-09 08:58:02 -04:00
Ralf Jung
7889373730 make as_leaf return a raw pointer, to reduce aliasing assumptions 2020-09-09 08:38:34 -04:00
Flying-Toast
2799aec6ab Capitalize safety comments 2020-09-08 22:37:18 -04:00
Braden Nelson
e02952c0cc
Update library/alloc/src/collections/vec_deque.rs
Replace lshift with multiply

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-09-08 13:11:08 -05:00
moonheart08
c3c84ad027 Convert MAXIMUM_ZST_CAPACITY to be calculated in a
const instead of multiple target_pointer_width checks.
2020-09-08 10:35:35 -05:00
bors
e114d6228b Auto merge of #76368 - ayushmishra2005:move_str_contact_library, r=jyn514
Added str tests in library

Added str tests in library  as a part of #76268

r? @matklad
2020-09-07 05:20:46 +00:00
scottmcm
3d89ee9586
Typo fix
Thanks, Amanieu

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2020-09-07 02:30:42 +00:00
Dylan DPC
1b24f1401d
Rollup merge of #76324 - ayushmishra2005:move_vec_tests_in_library, r=matklad
Move Vec slice UI tests in library

Moved some of Vec slice UI tests in Library as a part of #76268

r? @matklad
2020-09-07 01:18:07 +02:00
Dylan DPC
52d9162645
Rollup merge of #76305 - CDirkx:const-tests, r=matklad
Move various ui const tests to `library`

Move:
 - `src\test\ui\consts\const-nonzero.rs` to `library\core`
 - `src\test\ui\consts\ascii.rs` to `library\core`
 - `src\test\ui\consts\cow-is-borrowed` to `library\alloc`

Part of #76268

r? @matklad
2020-09-07 01:17:59 +02:00
Dylan DPC
5b8f76d564
Rollup merge of #76303 - jyn514:vec-assert-doc, r=Dylan-DPC
Link to `#capacity-and-reallocation` when using with_capacity

Follow up to https://github.com/rust-lang/rust/pull/76058#discussion_r479655750.
r? @pickfire
2020-09-07 01:17:56 +02:00
Dylan DPC
e488c4f187
Rollup merge of #76273 - CraftSpider:master, r=matklad
Move some Vec UI tests into alloc unit tests

A bit of work towards #76268, makes a number of the Vec UI tests that are simply running code into unit tests. Ensured that they are being run when testing liballoc locally.
2020-09-07 01:17:45 +02:00
Ivan Tham
685f04220e
Clean up vec benches bench_in_place style 2020-09-06 12:00:22 +08:00
Ayush Kumar Mishra
05d22c8519 Move test-cases in string.rs 2020-09-06 09:23:40 +05:30
bors
cdc8f0606d Auto merge of #76217 - RalfJung:maybe-uninit-slice, r=KodrAus
rename MaybeUninit slice methods

The `first` methods conceptually point to the whole slice, not just its first element, so rename them to be consistent with the raw ptr methods on ref-slices.

Also, do the equivalent of https://github.com/rust-lang/rust/pull/76047 for the slice reference getters, and make them part of https://github.com/rust-lang/rust/issues/63569 (so far they somehow had no tracking issue).

* first_ptr -> slice_as_ptr
* first_ptr_mut -> slice_as_mut_ptr
* slice_get_ref -> slice_assume_init_ref
* slice_get_mut -> slice_assume_init_mut
2020-09-05 21:02:18 +00:00
scottmcm
2c8a4c8f73
Nightly is currently 1.48 2020-09-05 19:02:21 +00:00
Ralf Jung
cff5f56886 rename MaybeUninit slice methods
first_ptr -> slice_as_ptr
first_ptr_mut -> slice_as_mut_ptr
slice_get_ref -> slice_assume_init_ref
slice_get_mut -> slice_assume_init_mut
2020-09-05 17:24:22 +02:00
Dylan DPC
86cf7976e2
Rollup merge of #76060 - pickfire:patch-12, r=jyn514
Link vec doc to & reference

It is not always obvious that people could see the docs for `&`
especially for beginners, it also helps learnability.
2020-09-05 16:28:24 +02:00
Dylan DPC
4bd3f266b0
Rollup merge of #75994 - mental32:impl-rc-new-cyclic, r=KodrAus
`impl Rc::new_cyclic`

References #75861

r? @Dylan-DPC
2020-09-05 16:28:22 +02:00
Ayush Kumar Mishra
7d834c87d2 Move Various str tests in library 2020-09-05 17:24:06 +05:30
Ayush Kumar Mishra
5a0a58bbef Added str tests in library 2020-09-05 17:18:45 +05:30
Josh Stone
864a28e01d Re-export ArrayChunksMut in alloc 2020-09-04 19:51:29 -07:00
bors
70c5f6efc4 Auto merge of #75200 - ssomers:btree_valmut, r=Mark-Simulacrum
BTreeMap: introduce marker::ValMut and reserve Mut for unique access

The mutable BTreeMap iterators (apart from `DrainFilter`) are double-ended, meaning they have to rely on a front and a back handle that each represent a reference into the tree. Reserve a type category `marker::ValMut` for them, so that we guarantee that they cannot reach operations on handles with borrow type `marker::Mut`and that these operations can assume unique access to the tree.

Including #75195, benchmarks report no genuine change:
```
benchcmp old new --threshold 5
 name                                 old ns/iter  new ns/iter  diff ns/iter   diff %  speedup
 btree::map::iter_100                 3,333        3,023                -310   -9.30%   x 1.10
 btree::map::range_unbounded_vs_iter  36,624       31,569             -5,055  -13.80%   x 1.16
```

r? @Mark-Simulacrum
2020-09-04 23:16:23 +00:00
bors
ef55a0a92f Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAus
Add `slice::check_range`

This method is useful for [`RangeBounds`] parameters. It's even been [rewritten](22ee68dc58/src/librustc_data_structures/sorted_map.rs (L214)) [many](22ee68dc58/library/alloc/src/vec.rs (L1299)) [times](22ee68dc58/library/core/src/slice/mod.rs (L2441)) in the standard library, sometimes assuming that the bounds won't be [`usize::MAX`].

For example, [`Vec::drain`] creates an empty iterator when [`usize::MAX`] is used as an inclusive end bound:

```rust
assert!(vec![1].drain(..=usize::max_value()).eq(iter::empty()));
```

If this PR is merged, I'll create another to use it for those methods.

[`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html
[`usize::MAX`]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.MAX
[`Vec::drain`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
2020-09-04 12:21:43 +00:00
Ayush Kumar Mishra
d16bbd1cb0 Move Vec slice UI tests in library 2020-09-04 17:18:26 +05:30
Scott McMurray
6092828d1f Add [T; N]: TryFrom<Vec<T>>
This is very similar to the existing `Box<[T; N]>: TryFrom<Box<[T]>>`, but allows avoiding the `shrink_to_fit` if you have a vector and not a boxed slice.
2020-09-03 21:13:56 -07:00
Ivan Tham
85146b9db7
Add slice primitive link to vec 2020-09-04 09:50:50 +08:00
Christiaan Dirkx
538e198193 Move various ui const tests to library
Move:
 - `src\test\ui\consts\const-nonzero.rs` to `library\core`
 - `src\test\ui\consts\ascii.rs` to `library\core`
 - `src\test\ui\consts\cow-is-borrowed` to `library\alloc`

Part of #76268
2020-09-04 02:35:27 +02:00
Tomasz Miąsko
f8cfb2f5ad Add tests for overflow in String / VecDeque operations using ranges 2020-09-04 00:00:00 +00:00
Tomasz Miąsko
d98bac4e4e Add tests for overflow in Vec::drain 2020-09-04 23:16:53 +02:00
Joshua Nelson
7b823df489 Link to #capacity-and-reallocation when using with_capacity 2020-09-03 18:08:25 -04:00
The8472
2f23a0fcca fix debug assertion
The InPlaceIterable debug assert checks that the write pointer
did not advance beyond the read pointer. But TrustedRandomAccess
never advances the read pointer, thus triggering the assert.
Skip the assert if the source pointer did not change during iteration.
2020-09-03 22:15:47 +02:00
Rune Tynan
2278c7255a
Remove vec-to_str.rs, merge the remaining test in with vec 2020-09-03 15:43:07 -04:00
The8472
8e5fe5569b improve comments and naming 2020-09-03 20:59:37 +02:00
The8472
6464586542 add explanation to specialization marker 2020-09-03 20:59:36 +02:00
The8472
acdd441cc3 remove separate no-drop code path since it resulted in more LLVM IR 2020-09-03 20:59:36 +02:00
The8472
435219dd82 remove empty Vec extend optimization
The optimization meant that every extend code path had to emit llvm
IR for from_iter and extend spec_extend, which likely impacts
compile times while only improving a few edge-cases
2020-09-03 20:59:35 +02:00
The8472
9aeea00222 get things to work under min_specialization by leaning more heavily on #[rustc_unsafe_specialization_marker] 2020-09-03 20:59:34 +02:00
The8472
a62cd1b44c fix benchmark compile errors 2020-09-03 20:59:33 +02:00
The8472
bec9f9223c apply required min_specialization attributes 2020-09-03 20:59:32 +02:00
The8472
80638330f2 support in-place collect for MapWhile adapters 2020-09-03 20:59:32 +02:00
The8472
5530858a08 generalize in-place collect to types of same size and alignment 2020-09-03 20:59:31 +02:00
The8472
fa34b39cd6 increase comment verbosity 2020-09-03 20:59:30 +02:00
The8472
872ab780c0 work around compiler overhead around lambdas in generics by extracting them into free functions 2020-09-03 20:59:29 +02:00
The8472
771b8ecc83 extract IntoIter drop/forget used by specialization into separate methods 2020-09-03 20:59:29 +02:00
The8472
6ad133443a add benchmark to cover in-place extend 2020-09-03 20:59:28 +02:00
The8472
a7a8b52e91 remove redundant cast 2020-09-03 20:59:28 +02:00
The8472
470bf54f94 test drops during in-place iteration 2020-09-03 20:59:27 +02:00
The8472
fe350dd82d move unsafety into method, not relevant to caller 2020-09-03 20:59:27 +02:00
The8472
0d2d033415 replace unsafe ptr::write with deref-write, benchmarks show no difference 2020-09-03 20:59:26 +02:00
The8472
9596e5a2f2 pacify tidy 2020-09-03 20:59:26 +02:00
The8472
6ed05fd995 replace drop flag with ManuallyDrop 2020-09-03 20:59:25 +02:00
The8472
ab382b7661 mark as_inner as unsafe and update comments 2020-09-03 20:59:24 +02:00
The8472
2a51e579f5 avoid exposing that binary heap's IntoIter is backed by vec::IntoIter, use a private trait instead 2020-09-03 20:59:24 +02:00
The8472
c731648e77 fix: bench didn't black_box its results 2020-09-03 20:59:23 +02:00
The8472
0856771248 fix build issue due to stabilized feature 2020-09-03 20:59:23 +02:00
The8472
e85cfa4f22 impl TrustedRandomAccess for vec::IntoIter 2020-09-03 20:59:22 +02:00
The8472
e1151844fa bench larger allocations 2020-09-03 20:59:22 +02:00
The8472
fd16202e36 include in-place .zip() in test 2020-09-03 20:59:21 +02:00
The8472
fbb3371e5b remove unecessary feature flag
# Conflicts:
#	library/alloc/src/lib.rs
2020-09-03 20:59:21 +02:00
The8472
085eb20a61 move free-standing method into trait impl 2020-09-03 20:59:19 +02:00
The8472
3d5e9f1904 bench in-place zip 2020-09-03 20:59:18 +02:00
The8472
2b0b2ae9f6 additional specializations tests 2020-09-03 20:59:17 +02:00
The8472
00a32eb54f fix some in-place-collect edge-cases
- it's an allocation optimization, so don't attempt to do it on ZSTs
- drop the tail of partially exhausted iters
2020-09-03 20:59:17 +02:00
The8472
8c816b96dd remove redundant code 2020-09-03 20:59:16 +02:00
The8472
cc67c8eb91 improve comments 2020-09-03 20:59:16 +02:00
The8472
290fe895ba specialize creating a Vec from a slice iterator where T: Copy
this was already implemented for Extend but not for FromIterator
2020-09-03 20:59:15 +02:00
The8472
dac0edfaaa restore SpecFrom<T, TrustedLen<Item=T>> specialization by nesting
specializations
2020-09-03 20:59:15 +02:00
The8472
582fbb1d62 use From specializations on extend if extended Vec is empty
this enables in-place iteration and allocation reuse in additional cases
2020-09-03 20:59:14 +02:00
The8472
a596ff36b5 exercise more of the in-place pipeline in the bench 2020-09-03 20:59:14 +02:00
The8472
a9c78e371e bench in-place collect of droppables 2020-09-03 20:59:13 +02:00
The8472
8ac96e6a98 cyclic in-place reuse bench 2020-09-03 20:59:13 +02:00
The8472
bb4f888a59 return the things under test so they get black_box()'ed 2020-09-03 20:59:12 +02:00
The8472
2f700d085a add benches from bluss' gists 2020-09-03 20:59:12 +02:00
The8472
a4e385a0d0 use memmove instead of generic in-place iteration for IntoIter source
this is the original SpecExtend<_, IntoIter> logic except generalizing
the fast-path to include a memmove
2020-09-03 20:59:11 +02:00
The8472
631543dcb4 restore Vec::extend specialization for vec::IntoIter sources that
was lost during refactoring
2020-09-03 20:59:11 +02:00
The8472
07a8c1b95a hide binary_heap::IntoIter internals behind impl Trait 2020-09-03 20:59:10 +02:00
The8472
232065074d recover vectorization
switch to try_fold and segregate the drop handling to keep
collect::<Vec<u8>>() and similar optimizer-friendly

It comes at the cost of less accurate debug_asserts and code complexity
2020-09-03 20:59:09 +02:00
The8472
6c5c47b82b update benches 2020-09-03 20:59:09 +02:00
The8472
bead910b21 simplify pointer arithmetic 2020-09-03 20:59:08 +02:00
The8472
328a75f766 use add instead of offset 2020-09-03 20:59:07 +02:00
The8472
88b7ae642c implement drop handling 2020-09-03 20:59:06 +02:00
The8472
73a982e9ec assert that SourceIter requirements have not been violated by the pipeline 2020-09-03 20:59:06 +02:00
The8472
2a327394e4 mark SourceIter as unsafe, document invariants 2020-09-03 20:59:05 +02:00
The8472
bb2d533bb9 in-place collect for Vec. Box<[]> and BinaryHeap IntoIter and some adapters 2020-09-03 20:59:03 +02:00
The8472
038394a330 bench 2020-09-03 20:56:34 +02:00
The8472
076417e978 unrelated typo fix 2020-09-03 20:56:34 +02:00
Ivan Tham
4df64905ea
Link & primitive using relative link 2020-09-03 23:02:27 +08:00
bors
08deb863bd Auto merge of #76235 - jyn514:std-intra-links, r=poliorcetics
Convert many files to intra-doc links

Helps with https://github.com/rust-lang/rust/issues/75080
r? @poliorcetics
I recommend reviewing one commit at a time, but the diff is small enough you can do it all at once if you like :)
2020-09-03 05:53:48 +00:00
Rune Tynan
3e29fdb0fb
Remove a number of vec UI tests, make them unit tests in the alloc library 2020-09-03 01:40:15 -04:00
Joshua Nelson
44bacc3ffa Revert change to MaybeUninit until rustdoc bugs are fixed
https://github.com/rust-lang/rust/issues/76106
2020-09-02 17:38:21 -04:00
Joshua Nelson
59a1a05bff Convert many files to intra-doc links
- Use intra-doc links for `std::io` in `std::fs`
- Use intra-doc links for File::read in unix/ext/fs.rs
- Remove explicit intra-doc links for `true` in `net/addr.rs`
- Use intra-doc links in alloc/src/sync.rs
- Use intra-doc links in src/ascii.rs
- Switch to intra-doc links in alloc/rc.rs
- Use intra-doc links in core/pin.rs
- Use intra-doc links in std/prelude
- Use shorter links in `std/fs.rs`

  `io` is already in scope.
2020-09-02 17:37:40 -04:00
Anton
dbe50f5c24
Same typos in vec_deque 2020-09-02 14:09:42 +02:00
Anton
b67006422e
Fix typos in vec try_reserve(_exact) docs
`try_reserve` and `try_reserve_exact` docs refer to calling `reserve` and `reserve_exact`.
`try_reserve_exact` example uses `try_reserve` method instead of `try_reserve_exact`.
2020-09-02 13:12:44 +02:00
Joshua Nelson
726b187546 Use intra-doc links for MaybeUninit in boxed.rs 2020-09-01 23:54:17 -04:00
Jon Gjengset
8b55360f70
Will land in 1.48, not 1.47 2020-09-01 09:50:32 -04:00