Commit graph

1407 commits

Author SHA1 Message Date
Matthias Krüger
690d6b0958
Rollup merge of #92071 - ajtribick:patch-1, r=the8472
Update example code for Vec::splice to change the length

The current example for `Vec::splice` illustrates the replacement of a section of length 2 with a new section of length 2. This isn't a particularly interesting case for splice, and makes it look a bit like a shorthand for the kind of manipulations that could be done with a mutable slice.

In order to provide a stronger example, this updates the example to use different lengths for the source and destination regions, and uses a slice from the middle of the vector to illustrate that this does not necessarily have to be at the beginning or the end.

Resolves #92067
2021-12-19 10:45:54 +01:00
ajtribick
574bc67736 Update example code for Vec::splice to change the length 2021-12-18 16:10:00 +01:00
Szilárd Parrag
c53e8198af
docs: fix typo
Add missing `'s` to ` Let check it out.`
2021-12-18 11:21:58 +01:00
bors
a090c8659c Auto merge of #91527 - the8472:retain-opt, r=dtolnay
Optimize `vec::retain` performance

This simply moves the loops into the inner function which leads to better results.

```
old:

test vec::bench_retain_100000                            ... bench:     203,828 ns/iter (+/- 2,101)
test vec::bench_retain_iter_100000                       ... bench:      63,324 ns/iter (+/- 12,305)
test vec::bench_retain_whole_100000                      ... bench:      42,989 ns/iter (+/- 291)

new:

test vec::bench_retain_100000                            ... bench:      42,180 ns/iter (+/- 451)
test vec::bench_retain_iter_100000                       ... bench:      65,167 ns/iter (+/- 11,971)
test vec::bench_retain_whole_100000                      ... bench:      33,736 ns/iter (+/- 12,404)
```

Measured on x86_64-unknown-linux-gnu, Zen2

Fixes #91497
2021-12-16 07:58:36 +00:00
bors
c5ecc15704 Auto merge of #91962 - matthiaskrgr:rollup-2g082jw, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91880 (fix clippy::single_char_pattern perf findings)
 - #91885 (Remove `in_band_lifetimes` from `rustc_codegen_ssa`)
 - #91898 (Make `TyS::is_suggestable` check for non-suggestable types structually)
 - #91915 (Add another regression test for unnormalized fn args with Self)
 - #91916 (Fix a bunch of typos)
 - #91918 (Constify `bool::then{,_some}`)
 - #91920 (Use `tcx.def_path_hash` in `ExistentialPredicate.stable_cmp`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-15 12:41:42 +00:00
Matthias Krüger
99f4458a8c
Rollup merge of #91916 - steffahn:fix-typos, r=dtolnay
Fix a bunch of typos

I hope that none of these files is not supposed to be modified.

FYI, I opened separate PRs for typos in submodules, in the respective repositories
* https://github.com/rust-lang/stdarch/pull/1267
* https://github.com/rust-lang/backtrace-rs/pull/455
2021-12-15 10:57:02 +01:00
Matthias Krüger
d258e92900
Rollup merge of #90521 - jhpratt:stabilize-destructuring_assignment, r=jackh726,pnkfelix
Stabilize `destructuring_assignment`

Closes #71126

- [Stabilization report](https://github.com/rust-lang/rust/issues/71126#issuecomment-941148058)
- [Completed FCP](https://github.com/rust-lang/rust/issues/71126#issuecomment-954914819)

`@rustbot` label +F-destructuring-assignment +T-lang
Also needs +relnotes but I don't have permission to add that tag.
2021-12-15 08:36:19 +01:00
Jacob Pratt
d95f749f14
Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
bors
195e931b02 Auto merge of #91945 - matthiaskrgr:rollup-jszf9zp, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #90939 (Tweak errors coming from `for`-loop, `?` and `.await` desugaring)
 - #91859 (Iterator::cycle() — document empty iterator special case)
 - #91868 (Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`)
 - #91870 (Revert setting a default for the MACOSX_DEPLOYMENT_TARGET env var for linking)
 - #91881 (Stabilize `iter::zip`)
 - #91882 (Remove `in_band_lifetimes` from `rustc_typeck`)
 - #91940 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-15 03:28:55 +00:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
Matthias Krüger
50327d2c91
Rollup merge of #89825 - martinvonz:split-inclusive-empty, r=m-ou-se
Make split_inclusive() on an empty slice yield an empty output

`[].split_inclusive()` currently yields a single, empty slice. That's
different from `"".split_inslusive()`, which yields no output at
all. I think that makes the slice version harder to use.

The case where I ran into this bug was when writing code for
generating a diff between two slices of bytes. I wanted to prefix
removed lines with "-" and a added lines with "+". Due to
`split_inclusive()`'s current behavior, that means that my code prints
just a "-" or "+" for empty files. I suspect most existing callers
have similar "bugs" (which would be fixed by this patch).

Closes #89716.
2021-12-14 20:47:26 +01:00
Frank Steffahn
a957cefda6 Fix a bunch of typos 2021-12-14 16:40:43 +01:00
Matthias Krüger
7ec00cd135
Rollup merge of #91529 - TennyZhuang:try_reserve_binary_heap, r=yaahc
add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact

`try_reserve` of many collections were stablized in https://github.com/rust-lang/rust/pull/87993 in 1.57.0. Add `try_reserve` for the rest collections such as `BinaryHeap` should be not controversial.
2021-12-14 10:21:02 +01:00
bors
7ca74ea0af Auto merge of #91680 - saethlin:spare_capacity_mut-in-join, r=dtolnay
Use spare_capacity_mut instead of invalid unchecked indexing when joining str

This is a fix for https://github.com/rust-lang/rust/issues/91574

I think in general I'd prefer to see this code implemented with raw pointers or `MaybeUninit::write_slice`, but there's existing code in here based on copying from slice to slice, so converting everything from `&[T]` to `&[MaybeUninit<T>]` is less disruptive.
2021-12-14 04:29:54 +00:00
Matthias Krüger
87cda671e5
Rollup merge of #91749 - ssomers:btree_comments, r=Mark-Simulacrum
BTree: improve public descriptions and comments

BTreeSet has always used the term "value" next to and meaning the same thing as "elements" (in the mathematical sense but also used for key-value pairs in BTreeMap), while in the BTreeMap sense these "values" are known as "keys" and definitely not "values". Today I had enough of that.

r? `@Mark-Simulacrum`
2021-12-13 00:20:08 +01:00
Matthias Krüger
955e552d31
Rollup merge of #91814 - japm48:spelling-fix, r=RalfJung
doc: fix typo in comments

`dereferencable -> dereferenceable`

Fixes #91802.
2021-12-12 07:45:30 +01:00
Matthias Krüger
0f3a4c77c4
Rollup merge of #91746 - ssomers:btree_tests, r=Mark-Simulacrum
Btree: assert more API compatibility

Introducing a member such as `BTreeSet::min()` would silently break compatibility if no code calls the existing `BTreeSet::min(set)`. `BTreeSet` is the only btree class silently bringing in stable members, apart from many occurrences of `#[derive(Debug)]` on iterators.

r? `@Mark-Simulacrum`
2021-12-12 07:45:28 +01:00
japm48
0d7b830139 doc: fix typo in comments
dereferencable -> dereferenceable
2021-12-12 00:27:27 +01:00
The 8472
9063b64cff Fix zero-sized reference to deallocated memory
fixes #91772
2021-12-11 17:10:56 +01:00
TennyZhuang
2235af1a68 update feature gate 2021-12-11 22:54:17 +08:00
TennyZhuang
d0f8793d89 add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2021-12-11 20:29:44 +08:00
bors
c185610ebc Auto merge of #91761 - matthiaskrgr:rollup-bjowmvz, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #91668 (Remove the match on `ErrorKind::Other`)
 - #91678 (Add tests fixed by #90023)
 - #91679 (Move core/stream/stream/mod.rs to core/stream/stream.rs)
 - #91681 (fix typo in `intrinsics::raw_eq` docs)
 - #91686 (Fix `Vec::reserve_exact` documentation)
 - #91697 (Delete Utf8Lossy::from_str)
 - #91706 (Add unstable book entries for parts of asm that are not being stabilized)
 - #91709 (Replace iterator-based set construction by *Set::From<[T; N]>)
 - #91716 (Improve x.py logging and defaults a bit more)
 - #91747 (Add pierwill to .mailmap)
 - #91755 (Fix since attribute for const_linked_list_new feature)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-11 03:52:12 +00:00
Matthias Krüger
637859b26e
Rollup merge of #91755 - not-my-profile:fix-const_linked_list_new-since, r=dtolnay
Fix since attribute for const_linked_list_new feature

https://github.com/rust-lang/rust/pull/63684
was merged for 1.39 not 1.32
2021-12-10 22:41:31 +01:00
Matthias Krüger
3beeb75dde
Rollup merge of #91709 - juniorbassani:use-from-array-in-set-examples, r=jyn514
Replace iterator-based set construction by *Set::From<[T; N]>

This uses the array-based construction for `BtreeSet`s and `HashSet`s instead of first creating an iterator. I could also replace the `let mut a = Set::new(); a.insert(...);` fragments if desired.
2021-12-10 22:41:28 +01:00
Matthias Krüger
1d36c6ac2e
Rollup merge of #91686 - dalcde:patch-1, r=dtolnay
Fix `Vec::reserve_exact` documentation

The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.
2021-12-10 22:41:25 +01:00
Matthias Krüger
ca352c4522
Rollup merge of #91524 - rukai:fix_extend_from_slice_docs, r=dtolnay
Fix Vec::extend_from_slice docs

`other` is a slice not a vector.
2021-12-10 22:40:34 +01:00
Matthias Krüger
5510803fe9
Rollup merge of #91482 - JosephTLyons:update-HashMap-and-BTreeMap-documentation, r=yaahc
Update documentation to use `from()` to initialize `HashMap`s and `BTreeMap`s

As of Rust 1.56, `HashMap` and `BTreeMap` both have associated `from()` functions.  I think using these in the documentation cleans things up a bit.  It allows us to remove some of the `mut`s and avoids the Initialize-Then-Modify anti-pattern.
2021-12-10 22:40:33 +01:00
Martin Fischer
305dd6908c Fix since attribute for const_linked_list_new feature
https://github.com/rust-lang/rust/pull/63684
was merged for 1.39 not 1.32
2021-12-10 20:22:19 +01:00
Stein Somers
27b4b19c8c BTree: improve public descriptions and comments 2021-12-10 17:37:55 +01:00
Stein Somers
cc35a11a39 BTree: assert presence of derived functions 2021-12-10 16:30:04 +01:00
Stein Somers
c8bc4b7a55 BTree: rename compile-time assertions to match library/alloc/tests 2021-12-10 16:22:39 +01:00
bors
0b42deaccc Auto merge of #85157 - the8472:drain-drop-in-place, r=Mark-Simulacrum
replace vec::Drain drop loops with drop_in_place

The `Drain::drop` implementation came up in https://github.com/rust-lang/rust/pull/82185#issuecomment-789584796 as potentially interfering with other optimization work due its widespread use somewhere in `println!`

`@rustbot` label T-libs-impl
2021-12-09 15:01:42 +00:00
Júnior Bassani
cebd9494bd
Replace iterator-based set construction by *Set::From<[T; N]> 2021-12-09 11:56:19 -03:00
Dexter Chua
42f91047c8
Fix Vec::reserve_exact documentation
The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.
2021-12-08 20:00:19 -05:00
The 8472
2d8a11bdbb Use *mut [T] instead of [MaybeUninit<T>] 2021-12-09 00:20:13 +01:00
Ben Kimock
14f4ffae32 Use spare_capacity_mut instead of invalid unchecked indexing 2021-12-08 17:58:57 -05:00
Matthias Krüger
1c2fba6540
Rollup merge of #91547 - TennyZhuang:suggest_try_reserve, r=scottmcm
Suggest try_reserve in try_reserve_exact

During developing #91529 , I found that `try_reserve_exact` suggests `reserve` for further insertions. I think it's a mistake by copy&paste, `try_reserve` is better here.
2021-12-07 11:05:04 +01:00
bors
1597728ef5 Auto merge of #88611 - m-ou-se:array-into-iter-new-deprecate, r=joshtriplett
Deprecate array::IntoIter::new.
2021-12-05 12:53:01 +00:00
TennyZhuang
aa3370c92b doc: suggest try_reserve in try_reserve_exact
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2021-12-05 14:38:59 +08:00
Matthias Krüger
4af985ac00
Rollup merge of #91215 - GuillaumeGomez:vec-deque-retain-mut, r=m-ou-se
Implement VecDeque::retain_mut

Part of https://github.com/rust-lang/rust/issues/90829.

In https://github.com/rust-lang/rust/pull/90772, someone suggested that `retain_mut` should also be implemented on `VecDeque`. I think that it follows the same logic (coherency). So first: is it ok? Second: should I create a new feature for it or can we put it into the same one?

r? `@joshtriplett`
2021-12-05 00:37:59 +01:00
Mara Bos
1acb44f03c Use IntoIterator for array impl everywhere. 2021-12-04 19:40:33 +01:00
The 8472
67180ef056 Optimize vec::retain performance
This simply moves the loops into the inner function which leads to better results.


```
old:

test vec::bench_retain_100000                            ... bench:     203,828 ns/iter (+/- 2,101)
test vec::bench_retain_iter_100000                       ... bench:      63,324 ns/iter (+/- 12,305)
test vec::bench_retain_whole_100000                      ... bench:      42,989 ns/iter (+/- 291)


new:

test vec::bench_retain_100000                            ... bench:      42,180 ns/iter (+/- 451)
test vec::bench_retain_iter_100000                       ... bench:      65,167 ns/iter (+/- 11,971)
test vec::bench_retain_whole_100000                      ... bench:      33,736 ns/iter (+/- 12,404)
```
2021-12-04 16:20:35 +01:00
The 8472
d0f38cc4b4 update vec::retain benchmarks
Add `into_iter().filter().collect()` as a comparison point since it was reported to be faster than `retain`.
Remove clone inside benchmark loop to reduce allocator noise.
2021-12-04 16:20:35 +01:00
Lucas Kent
8bfc76dd62 Fix Vec::extend_from_slice docs 2021-12-05 01:22:49 +11:00
Matthias Krüger
0bd4ee79e0
Rollup merge of #90851 - ibraheemdev:downcast-unchecked, r=scottmcm
Add unchecked downcast methods

```rust
impl dyn Any (+ Send + Sync) {
    pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T;
    pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T;
}

impl<A: Allocator> Box<dyn Any (+ Send + Sync), A> {
    pub unsafe fn downcast_unchecked<T: Any>(&self) -> Box<T, A>;
}
```
2021-12-04 02:26:21 +01:00
Ibraheem Ahmed
4ec5cdc94b fix stability annotations for Box::downcast 2021-12-03 16:06:13 -05:00
bors
3e21768a0a Auto merge of #91486 - matthiaskrgr:rollup-699fo18, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #88906 (Implement write() method for Box<MaybeUninit<T>>)
 - #90269 (Make `Option::expect` unstably const)
 - #90854 (Type can be unsized and uninhabited)
 - #91170 (rustdoc: preload fonts)
 - #91273 (Fix ICE #91268 by checking that the snippet ends with a `)`)
 - #91381 (Android: -ldl must appear after -lgcc when linking)
 - #91453 (Document Windows TLS drop behaviour)
 - #91462 (Use try_normalize_erasing_regions in needs_drop)
 - #91474 (suppress warning about set_errno being unused on DragonFly)
 - #91483 (Sync rustfmt subtree)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-03 07:12:36 +00:00
Matthias Krüger
31003a3089
Rollup merge of #88906 - Kixunil:box-maybe-uninit-write, r=dtolnay
Implement write() method for Box<MaybeUninit<T>>

This adds method similar to `MaybeUninit::write` main difference being
it returns owned `Box`. This can be used to elide copy from stack
safely, however it's not currently tested that the optimization actually
occurs.

Analogous methods are not provided for `Rc` and `Arc` as those need to
handle the possibility of sharing. Some version of them may be added in
the future.

This was discussed in #63291 which this change extends.
2021-12-03 06:24:11 +01:00
bors
190367ba2e Auto merge of #91339 - cbarrete:vecdeque-remove-grow-check, r=Mark-Simulacrum
Remove unnecessary check in VecDeque::grow

All callers already check that the buffer is full before calling
`grow()`. This is where it makes the most sense, since `grow()` is
`inline(never)` and we don't want to pay for a function call just for
that check.
It could also be argued that it would be correct to call `grow()` even
if the buffer wasn't full yet.
This change breaks no code since `grow()` is not `pub`.
2021-12-03 04:14:07 +00:00
Joseph T Lyons
440cffd551 Use BTreeMap::from() instead of using BTreeMap::new() with BTreeMap::insert() 2021-12-02 12:27:23 -05:00