Commit graph

1387 commits

Author SHA1 Message Date
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
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
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
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
Martin Habovstiak
41e21aa1c2 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-02 17:18:34 +01:00
Matthias Krüger
d96ce3ea8e
Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbini
Bump stage0 compiler

r? `@pietroalbini` (or anyone else)
2021-12-02 15:52:03 +01:00
Mark Rousskov
b221c877e8 Apply cfg-bootstrap switch 2021-11-30 10:51:42 -05:00
bors
207c80f105 Auto merge of #91352 - nnethercote:RawVec-reserve_for_push, r=dtolnay
Introduce `RawVec::reserve_for_push`.

If `Vec::push`'s capacity check fails it calls `RawVec::reserve`, which
then also does a capacity check.

This commit introduces `reserve_for_push` which skips the redundant
capacity check, for some slight compile time speed-ups.

I tried lots of minor variations on this, e.g. different inlining
attributes. This was the best one I could find.

r? `@ghost`
2021-11-30 13:52:38 +00:00
Cédric Barreteau
29f5c98a17 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-11-29 21:14:20 -05:00
Nicholas Nethercote
6a83352aa3 Introduce RawVec::reserve_for_push.
If `Vec::push`'s capacity check fails it calls `RawVec::reserve`, which
then also does a capacity check.

This commit introduces `reserve_for_push` which skips the redundant
capacity check, for some slight compile time speed-ups.

I tried lots of minor variations on this, e.g. different inlining
attributes. This was the best one I could find.
2021-11-30 08:10:47 +11:00
bors
4919988fe1 Auto merge of #91241 - dtolnay:firstchunk, r=oli-obk
Eliminate an unreachable codepath from String::from_utf8_lossy

`Utf8Lossy`'s `Iterator` implementation ensures that only the **final** chunk has an empty slice for `broken`:

dd549dcab4/library/core/src/str/lossy.rs (L46-L47)

Thus the only way the **first** chunk could have an empty `broken` is if it is the **final** chunk, i.e. there is only one chunk total. And the only way that there could be one chunk total with an empty `broken` is if the whole input is valid utf8 and non-empty.

That condition has already been handled by an early return, so at the point that the first `REPLACEMENT` is being pushed, it's impossible for `first_broken` to be empty.
2021-11-27 22:53:21 +00:00
bors
5fd3a5c7c1 Auto merge of #89916 - the8472:advance_by-avoid-err-0, r=dtolnay
Fix Iterator::advance_by contract inconsistency

The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n.
It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator.
These statements are inconsistent.
Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too.

While adding some tests I also found a bug in `Take::advance_back_by`.
2021-11-27 11:31:26 +00:00
Nicholas Nethercote
dbfb91385f Add a unit test for zero-sized types in RawVec.
Because there's some subtle behaviour specific to zero-sized types and
it's currently not well tested.
2021-11-26 19:30:45 +11:00
David Tolnay
9125dd74bd
Eliminate an unreachable codepath from String::from_utf8_lossy
Utf8Lossy's Iterator implementation ensures that only the final chunk
has an empty slice for broken. Thus the only way the first chunk could
have an empty broken is if it is the final chunk, i.e. there is only one
chunk total. And the only way that there could be one chunk total is if
the whole input is valid utf8 and non-empty. That condition has already
been handled by an early return, so at the point that the first
REPLACEMENT is being pushed, it's impossible for first_broken to be
empty.
2021-11-25 18:27:40 -08:00
Guillaume Gomez
0466a1256f Implement VecDeque::retain_mut 2021-11-25 13:28:31 +01:00
Ibraheem Ahmed
25271a5a98 fix doc links for downcast_unchecked 2021-11-20 18:22:05 -05:00
Matthias Krüger
09d9c098e0
Rollup merge of #89741 - sdroege:arc-rc-from-inner-unsafe, r=Mark-Simulacrum
Mark `Arc::from_inner` / `Rc::from_inner` as unsafe

While it's an internal function, it is easy to create invalid Arc/Rcs to
a dangling pointer with it.

Fixes https://github.com/rust-lang/rust/issues/89740
2021-11-20 22:33:48 +01:00
The8472
6851b8d931 document why we're not directly passing drop_ptr to drop_in_place 2021-11-20 01:29:04 +01:00
The8472
ce994027fe replace vec::Drain drop loops with drop_in_place 2021-11-20 01:12:07 +01:00
The8472
3f9b26dc64 Fix Iterator::advance_by contract inconsistency
The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n.
It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator.
These statements are inconsistent.
Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too.

While adding some tests I also found a bug in `Take::advance_back_by`.
2021-11-19 13:00:23 +01:00
Yuki Okushi
77c985f765
Rollup merge of #90607 - WaffleLapkin:const_str_from_utf8, r=oli-obk
Make slice->str conversion and related functions `const`

This PR marks the following APIs as `const`:
```rust
// core::str
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error>;
pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Everything but `from_utf8_unchecked_mut` uses `const_str_from_utf8` feature gate, `from_utf8_unchecked_mut` uses `const_str_from_utf8_unchecked_mut` feature gate.

---

I'm not sure why `from_utf8_unchecked_mut` was left out being  non-`const`, considering that `from_utf8_unchecked` is not only `const`, but **`const` stable**.

---

r? ```@oli-obk``` (performance-only `const_eval_select` use)
2021-11-19 02:22:57 +09:00
Yuki Okushi
3e97d9bd97
Rollup merge of #90480 - r00ster91:remove, r=kennytm
Mention `Vec::remove` in `Vec::swap_remove`'s docs

Thought this was a nice addition.
2021-11-19 02:22:56 +09:00
Maybe Waffle
cf6f64a963 Make slice->str conversion and related functions const
This commit makes the following functions from `core::str` `const fn`:
- `from_utf8[_mut]` (`feature(const_str_from_utf8)`)
- `from_utf8_unchecked_mut` (`feature(const_str_from_utf8_unchecked_mut)`)
- `Utf8Error::{valid_up_to,error_len}` (`feature(const_str_from_utf8)`)
2021-11-18 00:50:42 +03:00