Commit graph

1065 commits

Author SHA1 Message Date
Yuki Okushi
36b9a6ee73
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
Document Arc::from
2021-06-17 21:56:39 +09:00
Yuki Okushi
b1fb32d165
Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytm
Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`

To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.
2021-06-17 05:54:54 +09:00
Yuki Okushi
7fa1308db1
Stabilize maybe_uninit_ref 2021-06-14 05:08:03 +09:00
Deadbeef
8f78660c82 Remove "generic type" in boxed.rs 2021-06-12 04:11:48 +08:00
Yuki Okushi
58f4c0f949
Rollup merge of #85715 - fee1-dead:document-string, r=JohnTitor
Document `From` impls in string.rs
2021-06-09 12:03:59 +09:00
Scott McMurray
3802d573c3 Mention the Borrow guarantee on the Hash implementations for Array and Vec
To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.
2021-06-08 08:51:44 -07:00
bors
dda4a881e0 Auto merge of #83515 - tamird:string-remove-matches-rev, r=m-ou-se
String::remove_matches O(n^2) -> O(n)

Copy only non-matching bytes. Replace collection of matches into a
vector with iteration over rejections, exploiting the guarantee that we
mutate parts of the haystack that have already been searched over.

r? `@joshtriplett`
2021-06-08 01:05:48 +00:00
Tamir Duberstein
977903bb11
String::remove_matches O(n^2) -> O(n)
Copy only non-matching bytes.
2021-06-06 08:06:56 -04:00
Tamir Duberstein
38013e708e
Use iter::from_fn in String::remove_matches 2021-06-06 08:06:03 -04:00
Yuki Okushi
f923f73b9a
Rollup merge of #85930 - mominul:array_into_iter, r=m-ou-se
Update standard library for IntoIterator implementation of arrays

This PR partially resolves issue #84513 of updating the standard library part.

I haven't found any remaining doctest examples which are using iterators over e.g. &i32 instead of just i32 in the standard library. Can anyone point me to them if there's remaining any?

Thanks!

r? ```@m-ou-se```
2021-06-06 19:11:19 +09:00
Deadbeef
2727c3b174
Document Arc::from 2021-06-05 16:17:24 +00:00
Joshua Nelson
7411a9e7cc rustdoc: link to stable/beta docs consistently in documentation
## User-facing changes

- Intra-doc links to primitives that currently go to rust-lang.org/nightly/std/primitive.x.html will start going to channel that rustdoc was built with. Nightly will continue going to /nightly; Beta will link to /beta; stable compilers will link to /1.52.1 (or whatever version they were built as).
- Cross-crate links from std to core currently go to /nightly unconditionally. They will start going to /1.52.0 on stable channels (but remain the same on nightly channels).
- Intra-crate links from std to std (or core to core) currently go to the same URL they are hosted at; they will continue to do so. Notably, this is different from everything else because it can preserve the distinction between /stable and /1.52.0 by using relative links.

Note that "links" includes both intra-doc links and rustdoc's own
automatically generated hyperlinks.

 ## Implementation changes

- Update the testsuite to allow linking to /beta and /1.52.1 in docs
- Use an html_root_url for the standard library that's dependent on the channel

  This avoids linking to nightly docs on stable.

- Update rustdoc to use channel-dependent links for primitives from an
  unknown crate

- Set DOC_RUST_LANG_ORG_CHANNEL from bootstrap to ensure it's in sync
- Include doc.rust-lang.org in the channel
2021-06-04 14:18:21 -04:00
Yuki Okushi
df9ea79fc7
Rollup merge of #85717 - fee1-dead:document-cow, r=yaahc
Document `From` impls for cow.rs
2021-06-04 13:42:53 +09:00
bors
f1cee2c60e Auto merge of #85867 - steffahn:remove_unnecessary_specfromiter_impls, r=Mark-Simulacrum
Remove unnecessary SpecFromIter impls

Unless I’m missing something, these `SpecFromIter<&'a T, …> for Vec<T>` implementations were completely unused.
2021-06-03 22:45:14 +00:00
Mara Bos
f717992229 Stabilize VecDeque::partition_point. 2021-06-02 20:55:45 +02:00
Mara Bos
f086f1ec90 Bump vecdeque_binary_search stabilization to 1.54. 2021-06-02 20:51:08 +02:00
SOFe
f51f277d6c Bumped vecdeque_binary_search stabilization version to 1.53.0 2021-06-02 20:50:22 +02:00
SOFe
f7c283c160 Stabilize vecdeque_binary_search 2021-06-02 20:50:15 +02:00
Muhammad Mominul Huque
507d97b26e Update expressions where we can use array's IntoIterator implementation 2021-06-02 16:09:04 +06:00
Muhammad Mominul Huque
01d4d46f66 Replace IntoIter::new with IntoIterator::into_iter in std 2021-06-02 16:09:04 +06:00
Frank Steffahn
5ea3e733cb Update documentation of SpecFromIter to reflect the removed impls 2021-05-31 21:07:03 +02:00
Frank Steffahn
c902fdca45 Remove unnecessary SpecFromIter impls 2021-05-31 19:18:20 +02:00
bors
6a3dce99f6 Auto merge of #85814 - steffahn:fix_linked_list_itermut_debug, r=m-ou-se
Fix unsoundness of Debug implementation for linked_list::IterMut

Fix #85813, new `marker` field follows the example of `linked_list::Iter`.
2021-05-31 15:22:51 +00:00
Guillaume Gomez
980a4a725e
Rollup merge of #85817 - r00ster91:patch-9, r=dtolnay
Fix a typo

See also: #85737
2021-05-30 21:06:52 +02:00
Guillaume Gomez
b0f2a4c660
Rollup merge of #85801 - WaffleLapkin:master, r=joshtriplett
Add `String::extend_from_within`

This PR adds `String::extend_from_within` function under the `string_extend_from_within` feature gate similar to the [`Vec::extend_from_within`] function.

```rust
// String
pub fn extend_from_within<R>(&mut self, src: R)
where
    R: RangeBounds<usize>;
```

[`Vec::extend_from_within`]: https://github.com/rust-lang/rust/issues/81656
2021-05-30 21:06:51 +02:00
Frank Steffahn
b4dcdb4b47 Improve Debug impls for LinkedList reference iterators to show items 2021-05-30 01:03:34 +02:00
r00ster
8d70f40b31
Fix a typo 2021-05-30 00:06:27 +02:00
Frank Steffahn
7d364ad7c4 Fix unsoundness of Debug implementation for linked_list::IterMut 2021-05-29 21:33:31 +02:00
Waffle
23f9b92c5e Add String::extend_from_within
This patch adds `String::extend_from_within` function under the
`string_extend_from_within` feature gate similar to the
`Vec::extend_from_within` function.
2021-05-29 10:36:30 +03:00
The8472
f72c60a39a Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"
Due to a performance regression that didn't show up in the original perf run
this reverts commit 9111b8ae97, reversing
changes made to 9a700d2947.
2021-05-27 18:17:09 +02:00
bors
ea78d1edf3 Auto merge of #85737 - scottmcm:vec-calloc-option-nonzero, r=m-ou-se
Enable Vec's calloc optimization for Option<NonZero>

Someone on discord noticed that `vec![None::<NonZeroU32>; N]` wasn't getting the optimization, so here's a PR 🙃

We can certainly do this in the standard library because we know for sure this is ok, but I think it's also a necessary consequence of documented guarantees like those in https://doc.rust-lang.org/std/option/#representation and https://doc.rust-lang.org/core/num/struct.NonZeroU32.html

It feels weird to do this without adding a test, but I wasn't sure where that would belong.  Is it worth adding codegen tests for these?
2021-05-27 13:05:57 +00:00
Scott McMurray
04d34a97d1 Enable Vec's calloc optimization for Option<NonZero> 2021-05-26 23:19:35 -07:00
bors
9111b8ae97 Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum
Add `TrustedRandomAccess` specialization for `Vec::extend()`

This should do roughly the same as the `TrustedLen` specialization but result in less IR by using `__iterator_get_unchecked`
instead of `Iterator::for_each`

Conflicting specializations are manually prioritized by grouping them under yet another helper trait.
2021-05-26 19:22:31 +00:00
Deadbeef
3870e8a31d
Document From impls for cow.rs 2021-05-26 14:21:44 +00:00
Dylan DPC
27899e3887
Rollup merge of #85625 - SkiFire13:fix-85613-vec-dedup-drop-panics, r=nagisa
Prevent double drop in `Vec::dedup_by` if a destructor panics

Fixes #85613
2021-05-26 13:32:06 +02:00
Deadbeef
25e5a71986
Document From impls in string.rs 2021-05-26 08:28:39 +00:00
Yuki Okushi
e87bc66fca
Rollup merge of #85666 - fee1-dead:document-shared-from-cow, r=dtolnay
Document shared_from_cow functions
2021-05-26 13:31:04 +09:00
bors
47a90f4520 Auto merge of #85535 - dtolnay:weakdangle, r=kennytm
Weak's type parameter may dangle on drop

Way back in 34076bc0c9, #\[may_dangle\] was added to Rc\<T\> and Arc\<T\>'s Drop impls. That appears to have been because a test added in #28929 used Arc and Rc with dangling references at drop time. However, Weak was not covered by that test, and therefore no #\[may_dangle\] was forced to be added at the time.

As far as dropping, Weak has *even less need* to interact with the T than Rc and Arc do. Roughly speaking #\[may_dangle\] describes generic parameters that the outer type's Drop impl does not interact with except by possibly dropping them; no other interaction (such as trait method calls on the generic type) is permissible. It's clear this applies to Rc's and Arc's drop impl, which sometimes drop T but otherwise do not interact with one. It applies *even more* to Weak. Dropping a Weak cannot ever cause T's drop impl to run. Either there are strong references still in existence, in which case better not drop the T. Or there are no strong references still in existence, in which case the T would already have been dropped previously by the drop of the last strong count.
2021-05-26 01:17:02 +00:00
Deadbeef
37588e9e1b
Document shared_from_cow functions 2021-05-25 20:06:02 +08:00
Pietro Albini
9e22b844dd remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Giacomo Stevanato
c9595faa28 Make Vec::dedup panicking test actually detect double panics 2021-05-24 12:42:04 +02:00
Giacomo Stevanato
e0c9719672 Avoid a double drop in Vec::dedup if a destructor panics 2021-05-24 12:41:13 +02:00
Jubilee Young
c516e71874 Remove surplus prepend LinkedList fn
Originally committed to Rust in 2013, it is identical to append
with a reversed order of arguments.
2021-05-21 16:05:11 -07:00
David Tolnay
23a4050f7d
Weak's type parameter may dangle on drop 2021-05-20 19:43:41 -07:00
David Tolnay
c441675edf
Add Weak may_dangle tests 2021-05-20 19:42:29 -07:00
bors
a426fc37f2 Auto merge of #85391 - Mark-Simulacrum:opt-tostring, r=scottmcm
Avoid zero-length memcpy in formatting

This has two separate and somewhat orthogonal commits. The first change adjusts the ToString general impl for all types that implement Display; it no longer uses the full format machinery, rather directly falling onto a `std::fmt::Display::fmt` call. The second change directly adjusts the general core::fmt::write function which handles the production of format_args! to avoid zero-length push_str calls.

Both changes target the fact that push_str will still call memmove internally (or a similar function), as it doesn't know the length of the passed string. For zero-length strings in particular, this is quite expensive, and even for very short (several bytes long) strings, this is also expensive. Future work in this area may wish to have us fallback to write_char or similar, which may be cheaper on the (typically) short strings between the interpolated pieces in format_args!.
2021-05-20 00:55:27 +00:00
the8472
7cb4e5180f from review: more robust test
This also checks the contents and not only the capacity in case IntoIter's clone implementation is changed to add capacity at the end. Extra capacity at the beginning would be needed to make InPlaceIterable work.

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2021-05-19 01:41:12 +02:00
The8472
a44a059c3b add regression test 2021-05-19 01:41:12 +02:00
The8472
60a900ee10 remove InPlaceIterable marker from Peekable due to unsoundness
The unsoundness is not in Peekable per se, it rather is due to the
interaction between Peekable being able to hold an extra item
and vec::IntoIter's clone implementation shortening the allocation.

An alternative solution would be to change IntoIter's clone implementation
to keep enough spare capacity available.
2021-05-19 01:41:09 +02:00
bors
4e3e6db011 Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr
Implement the new desugaring from `try_trait_v2`

~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix.

`try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277

Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them.  (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits.

r? `@ghost`

~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-18 20:50:01 +00:00