Commit graph

5652 commits

Author SHA1 Message Date
Guillaume Gomez
77be7e441a
Rollup merge of #89729 - jkugelman:must-use-core-std-constructors, r=joshtriplett
Add #[must_use] to core and std constructors

Parent issue: #89692

r? ``@joshtriplett``
2021-10-11 14:11:43 +02:00
Guillaume Gomez
d7c9693401
Rollup merge of #89726 - jkugelman:must-use-alloc-constructors, r=joshtriplett
Add #[must_use] to alloc constructors

Added `#[must_use]`. to the various forms of `new`, `pin`, and `with_capacity` in the `alloc` crate. No extra explanations given as I couldn't think of anything useful to add.

I figure this deserves extra scrutiny compared to the other PRs I've done so far. In particular:

* The 4 `pin`/`pin_in` methods I touched. Are there legitimate use cases for pinning and not using the result? Pinning's a difficult concept I'm not very comfortable with.
* `Box`'s constructors. Do people ever create boxes just for the side effects... allocating or zeroing out memory?

Parent issue: #89692

r? ``@joshtriplett``
2021-10-11 14:11:42 +02:00
bors
6ae8912a3e Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov
Apply clippy suggestions for rustc and core
2021-10-11 11:14:47 +00:00
Flying-Toast
59b186d99a
Add enum_intrinsics_non_enums lint 2021-10-11 09:46:27 +02:00
bors
86d6d2b738 Auto merge of #89755 - jkugelman:must-use-conversions-that-move-self, r=joshtriplett
Add #[must_use] to conversions that move self

Everything here got the same message. Is the wording okay?

```rust
#[must_use = "`self` will be dropped if the result is not used"]
```

I want to draw attention to these methods in particular:

```rust
alloc::sync::Arc<MaybeUninit<T>>     unsafe fn assume_init(self) -> Arc<T>;
alloc::sync::Arc<[MaybeUninit<T>]>   unsafe fn assume_init(self) -> Arc<[T]>;
core::pin::Pin<&'a mut T>            const fn into_ref(self) -> Pin<&'a T>;
core::pin::Pin<&'a mut T>            const fn get_mut(self) -> &'a mut T;
core::pin::Pin<&'a mut T>            const unsafe fn get_unchecked_mut(self) -> &'a mut T;
core::pin::Pin<&'a mut T>            unsafe fn map_unchecked_mut(self, func: F) -> Pin<&'a mut U>;
core::pin::Pin<&'a mut Pin<P>>       fn as_deref_mut(self) -> Pin<&'a mut P::Target>;
```

Parent issue: #89692

r? `@joshtriplett`
2021-10-11 07:27:44 +00:00
John Kugelman
b115781bcd Add #[must_use] to conversions that move self 2021-10-10 19:50:52 -04:00
John Kugelman
cf2bcd10ed Add #[must_use] to from_value conversions 2021-10-10 19:00:33 -04:00
Matthias Krüger
9c4791300a
Rollup merge of #89707 - clemenswasser:apply_clippy_suggestions, r=Mark-Simulacrum
Apply clippy suggestions for std
2021-10-11 00:34:39 +02:00
Milan
15b119897c integrate I/O safety changes 2021-10-10 14:01:36 -04:00
Milan Landaverde
92d680589c cross-platform doctests 2021-10-10 14:01:09 -04:00
Milan Landaverde
d68a8d9870 moves use ptr within from_abstract_namespace fn 2021-10-10 14:01:08 -04:00
Milan Landaverde
565e349c79 Update tracking issue in stability refs 2021-10-10 14:01:07 -04:00
Milan Landaverde
1c2143193f rustfmt 2021-10-10 14:01:07 -04:00
Milan Landaverde
63ebfc2c55 Add abstract namespace support for Unix domain sockets 2021-10-10 14:01:06 -04:00
Matthias Krüger
4d89488c41
Rollup merge of #89735 - bjorn3:stabilize_proc_macro_is_available, r=petrochenkov
Stabilize proc_macro::is_available

Tracking issue: https://github.com/rust-lang/rust/issues/71436

The FCP for the stabilization of `proc_macro::is_available` has completed.
2021-10-10 18:22:26 +02:00
Matthias Krüger
c8b5a7b0c4
Rollup merge of #89720 - jkugelman:must-use-math-operations, r=joshtriplett
Add #[must_use] to math and bit manipulation methods

Also tidied up a few other nearby `#[must_use]`s.

Parent issue: #89692
2021-10-10 18:22:25 +02:00
Matthias Krüger
758a901a40
Rollup merge of #89719 - jkugelman:must-use-char-escape-methods, r=joshtriplett
Add #[must_use] to char escape methods

Parent issue: #89692
2021-10-10 18:22:24 +02:00
Matthias Krüger
0c04b1fc03
Rollup merge of #89718 - jkugelman:must-use-is_condition-tests, r=joshtriplett
Add #[must_use] to is_condition tests

There's nothing insightful to say about these so I didn't write any extra explanations.

Parent issue: #89692
2021-10-10 18:22:23 +02:00
Matthias Krüger
ce6097dfa4
Rollup merge of #89705 - nbdd0121:doc, r=GuillaumeGomez
Cfg hide no_global_oom_handling and no_fp_fmt_parse

These are unstable sysroot customisation cfg options that only projects building their own sysroot will use (e.g. Rust-for-linux). Most users shouldn't care. `no_global_oom_handling` can be especially annoying since it's applied on many commonly used alloc crate methods (e.g. `Box::new`, `Vec::push`).

r? ```@GuillaumeGomez```
2021-10-10 18:22:21 +02:00
Matthias Krüger
06cfd0af48
Rollup merge of #89438 - pierwill:prefix-free-hash, r=Amanieu
docs: `std:#️⃣:Hash` should ensure prefix-free data

Attempt to synthesize the discussion in #89429 into a suggestion regarding `Hash` implementations (not a hard requirement).

Closes #89429.
2021-10-10 18:22:20 +02:00
Matthias Krüger
4473b945bf
Rollup merge of #88713 - falk-hueffner:int-log10-documentation-fixes, r=scottmcm
Improve docs for int_log

* Clarify rounding.
* Avoid "wrapping" wording.
* Omit wrong claim on 0 only being returned in error cases.
* Typo fix for one_less_than_next_power_of_two.
2021-10-10 18:22:18 +02:00
Matthias Krüger
fd5bed73d0
Rollup merge of #88374 - joshlf:patch-2, r=JohnTitor
Fix documentation in Cell
2021-10-10 18:22:17 +02:00
John Kugelman
ecd7ea8a9c
Merge branch 'rust-lang:master' into must-use-alloc-constructors 2021-10-10 10:15:16 -04:00
Clemens Wasser
71dd0b928b Apply clippy suggestions 2021-10-10 15:38:19 +02:00
bors
0c87288f92 Auto merge of #89219 - nickkuk:str_split_once_get_unchecked, r=Mark-Simulacrum
Use get_unchecked in str::[r]split_once

This PR removes indices checking in `str::split_once` and `str::rsplit_once` methods.
2021-10-10 12:29:48 +00:00
bjorn3
09dd213cd2 Stabilize proc_macro::is_available 2021-10-10 14:09:54 +02:00
bors
9e8356c6ad Auto merge of #88952 - skrap:add-armv7-uclibc, r=nagisa
Add new tier-3 target: armv7-unknown-linux-uclibceabihf

This change adds a new tier-3 target: armv7-unknown-linux-uclibceabihf

This target is primarily used in embedded linux devices where system resources are slim and glibc is deemed too heavyweight.  Cross compilation C toolchains are available [here](https://toolchains.bootlin.com/) or via [buildroot](https://buildroot.org).

The change is based largely on a previous PR #79380 with a few minor modifications.  The author of that PR was unable to push the PR forward, and graciously allowed me to take it over.

Per the [target tier 3 policy](https://github.com/rust-lang/rfcs/blob/master/text/2803-target-tier-policy.md), I volunteer to be the "target maintainer".

This is my first PR to Rust itself, so I apologize if I've missed things!
2021-10-10 08:16:22 +00:00
John Kugelman
5b5c12be1c Add #[must_use] to core and std constructors 2021-10-10 02:44:26 -04:00
John Kugelman
58cc18c56b Add #[must_use] to alloc constructors 2021-10-10 02:19:30 -04:00
John Kugelman
bc9d13e658 Add #[must_use] to math and bit manipulation methods
Also tidied up a few other nearby `#[must_use]`s.
2021-10-09 22:43:32 -04:00
John Kugelman
fec9514727 Add #[must_use] to char escape methods 2021-10-09 21:35:09 -04:00
John Kugelman
475e9925a7 Add #[must_use] to is_condition tests
There's nothing insightful to say about these so I didn't write any
extra explanations.
2021-10-09 21:27:13 -04:00
pierwill
749194d847
Update library/core/src/hash/mod.rs
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2021-10-09 13:53:29 -05:00
Clemens Wasser
8545472a08 Apply clippy suggestions 2021-10-09 18:56:01 +02:00
Gary Guo
01825669b8 Cfg hide no_global_oom_handling and no_fp_fmt_parse 2021-10-09 17:07:33 +01:00
Guillaume Gomez
9f32ab88af
Rollup merge of #89664 - timClicks:51430-document-boxed-conversions, r=m-ou-se
Add documentation to boxed conversions

Among other changes, documents whether allocations are necessary
to complete the type conversion.

Part of #51430, supersedes #89199
2021-10-09 17:08:41 +02:00
Guillaume Gomez
21a5101e21
Rollup merge of #89614 - cuviper:unicode-14, r=joshtriplett
Update to Unicode 14.0

The Unicode Standard [announced Version 14.0](https://home.unicode.org/announcing-the-unicode-standard-version-14-0/) on September 14, 2021, and this pull request updates the generated tables in `core` accordingly.

This did require a little prep-work in `unicode-table-generator`. First, #81358 had modified the generated file instead of the tool, so that change is now reflected in the tool as well. Next, I found that the "Alphabetic" property in version 14 was panicking when generating a bitset, "cannot pack 264 into 8 bits". We've been using the skiplist for that anyway, so I changed this to fail gracefully. Finally, I confirmed that the tool still created the exact same tables for 13 before moving to 14.
2021-10-09 17:08:40 +02:00
Guillaume Gomez
703cb973ec
Rollup merge of #88436 - lf-:stabilize-command-access, r=yaahc
std: Stabilize command_access

Tracking issue: #44434 (not yet closed but the FCP is done so that should be soon).
2021-10-09 17:08:39 +02:00
Guillaume Gomez
3e4f95612e
Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplett
stack overflow handler specific openbsd change.
2021-10-09 17:08:38 +02:00
Guillaume Gomez
86bf3ce859
Rollup merge of #75644 - c410-f3r:array, r=yaahc
Add 'core::array::from_fn' and 'core::array::try_from_fn'

These auxiliary methods fill uninitialized arrays in a safe way and are particularly useful for elements that don't implement `Default`.

```rust
// Foo doesn't implement Default
struct Foo(usize);

let _array = core::array::from_fn::<_, _, 2>(|idx| Foo(idx));
```

Different from `FromIterator`, it is guaranteed that the array will be fully filled and no error regarding uninitialized state will be throw. In certain scenarios, however, the creation of an **element** can fail and that is why the `try_from_fn` function is also provided.

```rust
#[derive(Debug, PartialEq)]
enum SomeError {
    Foo,
}

let array = core::array::try_from_fn(|i| Ok::<_, SomeError>(i));
assert_eq!(array, Ok([0, 1, 2, 3, 4]));

let another_array = core::array::try_from_fn(|_| Err(SomeError::Foo));
assert_eq!(another_array, Err(SomeError::Foo));
 ```
2021-10-09 17:08:38 +02:00
Matthias Krüger
827b540424
Rollup merge of #89694 - jkugelman:must-use-string-transforms, r=joshtriplett
Add #[must_use] to string/char transformation methods

These methods could be misconstrued as modifying their arguments instead of returning new values.

Where possible I made the note recommend a method that does mutate in place.

Parent issue: #89692
2021-10-09 11:56:07 +02:00
Matthias Krüger
ee804594c8
Rollup merge of #89693 - jkugelman:must-use-stdin-stdout-stderr-locks, r=joshtriplett
Add #[must_use] to stdin/stdout/stderr locks

Affected methods:

```rust
std::io           fn stdin_locked() -> StdinLock<'static>;
std::io::Stdin    fn lock(&self) -> StdinLock<'_>;
std::io           fn stdout_locked() -> StdoutLock<'static>;
std::io::Stdout   fn lock(&self) -> StdoutLock<'_>;
std::io           fn stderr_locked() -> StderrLock<'static>;
std::io::Stderr   fn lock(&self) -> StderrLock<'_>;
```

Parent issue: https://github.com/rust-lang/rust/issues/89692
2021-10-09 11:56:07 +02:00
Matthias Krüger
346f833c3d
Rollup merge of #89678 - marcelo-gonzalez:master, r=joshtriplett
Fix minor std::thread documentation typo

callers of spawn_unchecked() need to make sure that the thread
not outlive references in the passed closure, not the other way around.
2021-10-09 11:56:01 +02:00
Matthias Krüger
36db658796
Rollup merge of #88707 - sylvestre:split_example, r=yaahc
String.split_terminator: Add an example when using a slice of chars
2021-10-09 11:55:58 +02:00
Tim McNamara
020ec0a039
Remove unnecessary hyphen
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-10-09 21:44:07 +13:00
Tim McNamara
fa5a212896
Simplify wording
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-10-09 20:51:36 +13:00
John Kugelman
2ec7588aa1
Update library/core/src/num/mod.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-10-09 02:05:03 -04:00
bors
910692de74 Auto merge of #89582 - jkugelman:optimize-file-read-to-end, r=joshtriplett
Optimize File::read_to_end and read_to_string

Reading a file into an empty vector or string buffer can incur unnecessary `read` syscalls and memory re-allocations as the buffer "warms up" and grows to its final size. This is perhaps a necessary evil with generic readers, but files can be read in smarter by checking the file size and reserving that much capacity.

`std::fs::read` and `std::fs::read_to_string` already perform this optimization: they open the file, reads its metadata, and call `with_capacity` with the file size. This ensures that the buffer does not need to be resized and an initial string of small `read` syscalls.

However, if a user opens the `File` themselves and calls `file.read_to_end` or `file.read_to_string` they do not get this optimization.

```rust
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
```

I searched through this project's codebase and even here are a *lot* of examples of this. They're found all over in unit tests, which isn't a big deal, but there are also several real instances in the compiler and in Cargo. I've documented the ones I found in a comment here:

https://github.com/rust-lang/rust/issues/89516#issuecomment-934423999

Most telling, the documentation for both the `Read` trait and the `Read::read_to_end` method both show this exact pattern as examples of how to use readers. What this says to me is that this shouldn't be solved by simply fixing the instances of it in this codebase. If it's here it's certain to be prevalent in the wider Rust ecosystem.

To that end, this commit adds specializations of `read_to_end` and `read_to_string` directly on `File`. This way it's no longer a minor footgun to start with an empty buffer when reading a file in.

A nice side effect of this change is that code that accesses a `File` as `impl Read` or `dyn Read` will benefit. For example, this code from `compiler/rustc_serialize/src/json.rs`:

```rust
pub fn from_reader(rdr: &mut dyn Read) -> Result<Json, BuilderError> {
    let mut contents = Vec::new();
    match rdr.read_to_end(&mut contents) {
```

Related changes:

- I also added specializations to `BufReader` to delegate to `self.inner`'s methods. That way it can call `File`'s optimized  implementations if the inner reader is a file.

- The private `std::io::append_to_string` function is now marked `unsafe`.

- `File::read_to_string` being more efficient means that the performance note for `io::read_to_string` can be softened. I've added `@camelid's` suggested wording from https://github.com/rust-lang/rust/issues/80218#issuecomment-936806502.

r? `@joshtriplett`
2021-10-09 05:24:47 +00:00
John Kugelman
54d807cfc7 Add #[must_use] to string/char transformation methods
These methods could be misconstrued as modifying their arguments instead
of returning new values.

Where possible I made the note recommend a method that does mutate in
place.
2021-10-09 01:01:40 -04:00
John Kugelman
e27bfb6e23 Add #[must_use] to stdin/stdout/stderr locks 2021-10-08 23:31:57 -04:00
Marcelo Diop-Gonzalez
82c974dab5 Fix minor std::thread documentation typo
callers of spawn_unchecked() need to make sure that the thread
not outlive references in the passed closure, not the other way around.
2021-10-08 15:29:04 -04:00
Loïc BRANSTETT
0a03ec4724 Cfg hide more conditions for alloc 2021-10-08 17:11:57 +02:00
Loïc BRANSTETT
31b2eb16e3 Cfg hide more conditions for core 2021-10-08 16:13:49 +02:00
Caio
85c4a52807 Also cfg flag auxiliar function 2021-10-08 06:40:24 -03:00
Tim McNamara
6a52fb7303 Add documentation to boxed conversions
Among other changes, documents whether allocations are necessary
to complete the type conversion.

Part of #51430

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>

Co-authored-by: Joshua Nelson <github@jyn.dev>
2021-10-08 21:40:25 +13:00
Jubilee
30e068f58b
Rollup merge of #89622 - m-ou-se:debug-assert-2021, r=estebank
Use correct edition for panic in [debug_]assert!().

See https://github.com/rust-lang/rust/issues/88638#issuecomment-915472783
2021-10-07 20:26:15 -07:00
Jubilee
37f17bca7c
Rollup merge of #89082 - smoelius:master, r=kennytm
Implement #85440 (Random test ordering)

This PR adds `--shuffle` and `--shuffle-seed` options to `libtest`. The options are similar to the [`-shuffle` option](c894b442d1/src/testing/testing.go (L1482-L1499)) that was recently added to Go.

Here are the relevant parts of the help message:
```
        --shuffle       Run tests in random order
        --shuffle-seed SEED
                        Run tests in random order; seed the random number
                        generator with SEED
...
By default, the tests are run in alphabetical order. Use --shuffle or set
RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated
"shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the
tests in the same order again. Note that --shuffle and --shuffle-seed do not
affect whether the tests are run in parallel.
```
Is an RFC needed for this?
2021-10-07 20:26:12 -07:00
Jubilee
2b6d7f75f7
Rollup merge of #88772 - orlp:result-map-or-else-docfix, r=yaahc
Fixed confusing wording on Result::map_or_else.

Fixes https://github.com/rust-lang/rust/issues/88195.
2021-10-07 20:26:11 -07:00
bors
2ee06e7372 Auto merge of #89638 - rust-lang:revert-88548-intersperse, r=Mark-Simulacrum
Revert "Stabilize `Iterator::intersperse()`"

Reverts rust-lang/rust#88548

First step in resolving https://github.com/rust-lang/rust/issues/88967
2021-10-07 23:50:54 +00:00
Ibraheem Ahmed
5f7e7d2e93 revert stabilization of core::task::ready! 2021-10-07 18:44:48 -04:00
John Kugelman
a990c76d84 Optimize File::read_to_end and read_to_string
Reading a file into an empty vector or string buffer can incur
unnecessary `read` syscalls and memory re-allocations as the buffer
"warms up" and grows to its final size. This is perhaps a necessary evil
with generic readers, but files can be read in smarter by checking the
file size and reserving that much capacity.

`std::fs::read` and `read_to_string` already perform this optimization:
they open the file, reads its metadata, and call `with_capacity` with
the file size. This ensures that the buffer does not need to be resized
and an initial string of small `read` syscalls.

However, if a user opens the `File` themselves and calls
`file.read_to_end` or `file.read_to_string` they do not get this
optimization.

```rust
let mut buf = Vec::new();
file.read_to_end(&mut buf)?;
```

I searched through this project's codebase and even here are a *lot* of
examples of this. They're found all over in unit tests, which isn't a
big deal, but there are also several real instances in the compiler and
in Cargo. I've documented the ones I found in a comment here:

https://github.com/rust-lang/rust/issues/89516#issuecomment-934423999

Most telling, the `Read` trait and the `read_to_end` method both show
this exact pattern as examples of how to use readers. What this says to
me is that this shouldn't be solved by simply fixing the instances of it
in this codebase. If it's here it's certain to be prevalent in the wider
Rust ecosystem.

To that end, this commit adds specializations of `read_to_end` and
`read_to_string` directly on `File`. This way it's no longer a minor
footgun to start with an empty buffer when reading a file in.

A nice side effect of this change is that code that accesses a `File` as
a bare `Read` constraint or via a `dyn Read` trait object will benefit.
For example, this code from `compiler/rustc_serialize/src/json.rs`:

```rust
pub fn from_reader(rdr: &mut dyn Read) -> Result<Json, BuilderError> {
    let mut contents = Vec::new();
    match rdr.read_to_end(&mut contents) {
```

Related changes:

- I also added specializations to `BufReader` to delegate to
  `self.inner`'s methods. That way it can call `File`'s optimized
  implementations if the inner reader is a file.

- The private `std::io::append_to_string` function is now marked
  `unsafe`.

- `File::read_to_string` being more efficient means that the performance
  note for `io::read_to_string` can be softened. I've added @camelid's
  suggested wording from:

  https://github.com/rust-lang/rust/issues/80218#issuecomment-936806502
2021-10-07 18:42:02 -04:00
Ibraheem Ahmed
a57c18b5e1 add Poll::ready 2021-10-07 15:47:28 -04:00
Jane Lusby
8965b5884a
Revert "Stabilize Iterator::intersperse()" 2021-10-07 10:39:36 -07:00
Guillaume Gomez
e32328bdc5
Rollup merge of #89596 - GuillaumeGomez:implicit-doc-cfg, r=jyn514
Make cfg imply doc(cfg)

This is a reopening of #79341, rebased and modified a bit (we made a lot of refactoring in rustdoc's types so they needed to be reflected in this PR as well):

 * `hidden_cfg` is now in the `Cache` instead of `DocContext` because `cfg` information isn't stored anymore on `clean::Attributes` type but instead computed on-demand, so we need this information in later parts of rustdoc.
 * I removed the `bool_to_options` feature (which makes the code a bit simpler to read for `SingleExt` trait implementation.
 * I updated the version for the feature.

There is only one thing I couldn't figure out: [this comment](https://github.com/rust-lang/rust/pull/79341#discussion_r561855624)

> I think I'll likely scrap the whole `SingleExt` extension trait as the diagnostics for 0 and >1 items should be different.

How/why should they differ?

EDIT: this part has been solved, the current code was fine, just needed a little simplification.

cc `@Nemo157`
r? `@jyn514`

Original PR description:

This is only active when the `doc_cfg` feature is active.

The implicit cfg can be overridden via `#[doc(cfg(...))]`, so e.g. to hide a `#[cfg]` you can use something like:

```rust
#[cfg(unix)]
#[doc(cfg(all()))]
pub struct Unix;
```

By adding `#![doc(cfg_hide(foobar))]` to the crate attributes the cfg `#[cfg(foobar)]` (and _only_ that _exact_ cfg) will not be implicitly treated as a `doc(cfg)` to render a message in the documentation.
2021-10-07 16:24:53 +02:00
Mara Bos
afe5335b97 Use correct edition for panic in [debug_]assert!() etc. 2021-10-07 14:27:08 +02:00
Josh Stone
459a7e340c Regenerate tables for Unicode 14.0.0 2021-10-06 17:49:33 -07:00
Manish Goregaokar
79a1fc8419
Rollup merge of #89531 - devnexen:stack_overflow_bsd_libc_upd, r=dtolnay
library std, libc dependency update

to solve #87528 build.
2021-10-06 12:33:22 -07:00
Manish Goregaokar
b4615b5bf9
Rollup merge of #89324 - yoshuawuyts:hardware-parallelism, r=m-ou-se
Rename `std:🧵:available_conccurrency` to `std:🧵:available_parallelism`

_Tracking issue: https://github.com/rust-lang/rust/issues/74479_

This PR renames  `std:🧵:available_conccurrency` to `std:🧵:available_parallelism`.

## Rationale

The API was initially named `std:🧵:hardware_concurrency`, mirroring the [C++ API of the same name](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency). We eventually decided to omit any reference to the word "hardware" after [this comment](https://github.com/rust-lang/rust/pull/74480#issuecomment-662045841). And so we ended up with `available_concurrency` instead.

---

For a talk I was preparing this week I was reading through ["Understanding and expressing scalable concurrency" (A. Turon, 2013)](http://aturon.github.io/academic/turon-thesis.pdf), and the following passage stood out to me (emphasis mine):

> __Concurrency is a system-structuring mechanism.__ An interactive system that deals with disparate asynchronous events is naturally structured by division into concurrent threads with disparate responsibilities. Doing so creates a better fit between problem and solution, and can also decrease the average latency of the system by preventing long-running computations from obstructing quicker ones.

> __Parallelism is a resource.__ A given machine provides a certain capacity for parallelism, i.e., a bound on the number of computations it can perform simultaneously. The goal is to maximize throughput by intelligently using this resource. For interactive systems, parallelism can decrease latency as well.

_Chapter 2.1: Concurrency is not Parallelism. Page 30._

---

_"Concurrency is a system-structuring mechanism. Parallelism is a resource."_ — It feels like this accurately captures the way we should be thinking about these APIs. What this API returns is not "the amount of concurrency available to the program" which is a property of the program, and thus even with just a single thread is effectively unbounded. But instead it returns "the amount of _parallelism_ available to the program", which is a resource hard-constrained by the machine's capacity (and can be further restricted by e.g. operating systems).

That's why I'd like to propose we rename this API from `available_concurrency` to `available_parallelism`. This still meets the criteria we previously established of not attempting to define what exactly we mean by "hardware", "threads", and other such words. Instead we only talk about "concurrency" as an abstract resource available to our program.

r? `@joshtriplett`
2021-10-06 12:33:17 -07:00
Manish Goregaokar
14da7fc9ae
Rollup merge of #89245 - DeveloperC286:iter_mut_fields_to_private, r=joshtriplett
refactor: make VecDeque's IterMut fields module-private, not just crate-private

Made the fields of VecDeque's IterMut private by creating a IterMut::new(...) function to create a new instance of IterMut and migrating usage to use IterMut::new(...).
2021-10-06 12:33:16 -07:00
Manish Goregaokar
91e3b5172c
Rollup merge of #89050 - DeveloperC286:drain_fields_to_private, r=joshtriplett
refactor: VecDeques Drain fields to private

Made the fields of VecDeque's Drain private by creating a Drain::new(...) function to create a new instance of Drain and migrating usage to use Drain::new(...).
2021-10-06 12:33:15 -07:00
Manish Goregaokar
1e3b5d6725
Rollup merge of #88523 - kpreid:category, r=yaahc
Expand documentation for `FpCategory`.

I intend these changes to be helpful to readers who are not yet familiar with the quirks of floating-point numbers. Additionally, I felt it was misleading to describe `Nan` as being the result of division by zero, since most divisions by zero (except for 0/0) produce `Infinite` floats, so I moved that remark to the `Infinite` variant with adjustment.

The first sentence of the `Nan` documentation is copied from `f32`; I followed the example of the `f64` documentation by referring to `f32` for general concepts, rather than duplicating the text.

----

I considered making similar changes to the documentation of the `is_*` methods of floats, but decided that that was a much larger and trickier problem; here, each of the variants' descriptions can be expected to be read in context of being mutually exclusive with the others.
2021-10-06 12:33:14 -07:00
Manish Goregaokar
3209582a87
Rollup merge of #87601 - a1phyr:feature_uint_add_signed, r=kennytm
Add functions to add unsigned and signed integers

This PR adds methods to unsigned integers to add signed integers with good overflow semantics under `#![feature(mixed_integer_ops)]`.

The added API is:

```rust
// `uX` is `u8`, `u16`, `u32`, `u64`,`u128`, `usize`
impl uX {
    pub const fn checked_add_signed(self, iX) -> Option<Self>;
    pub const fn overflowing_add_signed(self, iX) -> (Self, bool);
    pub const fn saturating_add_signed(self, iX) -> Self;
    pub const fn wrapping_add_signed(self, iX) -> Self;
}

impl iX {
    pub const fn checked_add_unsigned(self, uX) -> Option<Self>;
    pub const fn overflowing_add_unsigned(self, uX) -> (Self, bool);
    pub const fn saturating_add_unsigned(self, uX) -> Self;
    pub const fn wrapping_add_unsigned(self, uX) -> Self;

    pub const fn checked_sub_unsigned(self, uX) -> Option<Self>;
    pub const fn overflowing_sub_unsigned(self, uX) -> (Self, bool);
    pub const fn saturating_sub_unsigned(self, uX) -> Self;
    pub const fn wrapping_sub_unsigned(self, uX) -> Self;
}
```

Maybe it would be interesting to also have `add_signed` that panics in debug and wraps in release ?
2021-10-06 12:33:13 -07:00
Guillaume Gomez
8fac41a530 Clean up code a bit:
* Remove "bool_to_options" feature
 * Update version for compiler feature
 * rustfmt
2021-10-06 20:23:57 +02:00
Jonah Petri
bd821729cb Update libc to 0.2.103. 2021-10-06 14:33:13 +00:00
Jonah Petri
bc3eb354e7 add platform support details file for armv7-unknown-linux-uclibc 2021-10-06 14:33:13 +00:00
Yannick Koehler
11381a5a3a Add new target armv7-unknown-linux-uclibceabihf
Co-authored-by: Jonah Petri <jonah@petri.us>
2021-10-06 14:33:13 +00:00
Orson Peters
c3dfda0e3d Rebase Result::map_or_else doc wording on top of #89400. 2021-10-06 09:03:18 +02:00
Jane Lusby
5e1941c058
Apply suggestions from code review 2021-10-05 15:09:11 -07:00
Manish Goregaokar
4e8c853c9e
Rollup merge of #89502 - FabianWolff:issue-89493, r=joshtriplett
Fix Lower/UpperExp formatting for integers and precision zero

Fixes the integer part of #89493 (I daren't touch the floating-point formatting code). The issue is that the "subtracted" precision essentially behaves like extra trailing zeros, but this is not currently reflected in the code properly.
2021-10-05 12:52:46 -07:00
Manish Goregaokar
e745e098c4
Rollup merge of #89351 - tspiteri:wrapping_rem, r=dtolnay
for signed wrapping remainder, do not compare lhs with MIN

Since the wrapped remainder is going to be 0 for all cases when the rhs is -1, there is no need to compare the lhs with MIN.
2021-10-05 12:52:45 -07:00
Manish Goregaokar
eb860987cf
Rollup merge of #88828 - FabianWolff:issue-88585, r=dtolnay
Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock

Fixes #88585. POSIX [specifies](https://man7.org/linux/man-pages/man3/fork.3p.html) that after forking,
> to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called.

Rust's standard library does not currently adhere to this, as evidenced by #88585. The child process calls [`sys::signal()`](7bf0736e13/library/std/src/sys/unix/android.rs (L76)), which on Android calls [`libc::dlsym()`](7bf0736e13/library/std/src/sys/unix/weak.rs (L101)), which is [**not**](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, and in fact causes a deadlock in the example in #88585.

I think the easiest solution here would be to just call `libc::sigaction()` instead, which [is](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, provides the functionality we need, and is apparently available on all Android versions because it is also used e.g. [here](7bf0736e13/library/std/src/sys/unix/stack_overflow.rs (L112-L114)).
2021-10-05 12:52:42 -07:00
DeveloperC
5af61cb114 refactor: VecDeques IterMut fields to private
Made the fields of VecDeque's IterMut private by creating a IterMut::new(...) function to create a new instance of IterMut and migrating usage to use IterMut::new(...).
2021-10-05 19:09:49 +01:00
DeveloperC286
b2e4e59fbe refactor: VecDeques Drain fields to private 2021-10-05 19:02:36 +01:00
Wim Looman
0031ce3a91 Suppress some cfg from being shown in the stdlib docs 2021-10-05 18:15:29 +02:00
Trevor Spiteri
4ec0377d6a for signed overflowing remainder, delay comparing lhs with MIN
Since the wrapped remainder is going to be 0 for all cases when the rhs is -1,
there is no need to divide in this case. Comparing the lhs with MIN is only done
for the overflow bool. In particular, this results in better code generation for
wrapping remainder, which discards the overflow bool completely.
2021-10-05 15:15:24 +02:00
nickkuk
a35aaa2108 Use get_unchecked in str::[r]split_once 2021-10-05 14:42:08 +05:00
Manish Goregaokar
a23d7f01d3
Rollup merge of #89462 - devnexen:haiku_thread_aff_build_fix, r=nagisa
haiku thread affinity build fix
2021-10-04 23:56:22 -07:00
Manish Goregaokar
eeadc9d63f
Rollup merge of #89244 - DeveloperC286:pair_slices_fields_to_private, r=joshtriplett
refactor: VecDeques PairSlices fields to private

Reducing VecDeque's PairSlices fields to private, a `from(...)` method is already used to create PairSlices.
2021-10-04 23:56:18 -07:00
Manish Goregaokar
dd223d5c6d
Rollup merge of #88651 - AGSaidi:monotonize-inner-64b-aarch64, r=dtolnay
Use the 64b inner:monotonize() implementation not the 128b one for aarch64

aarch64 prior to v8.4 (FEAT_LSE2) doesn't have an instruction that guarantees
untorn 128b reads except for completing a 128b load/store exclusive pair
(ldxp/stxp) or compare-and-swap (casp) successfully. The requirement to
complete a 128b read+write atomic is actually more expensive and more unfair
than the previous implementation of monotonize() which used a Mutex on aarch64,
especially at large core counts.  For aarch64 switch to the 64b atomic
implementation which is about 13x faster for a benchmark that involves many
calls to Instant::now().
2021-10-04 23:56:17 -07:00
Manish Goregaokar
0fb01224dd
Rollup merge of #87631 - :solarish_upd_fs, r=joshtriplett
os current_exe using same approach as linux to get always the full ab…

…solute path
2021-10-04 23:56:15 -07:00
David Carlier
c79447e708 library std, libc dependency update
to solve #87528 build.
2021-10-05 05:58:09 +01:00
Jubilee
05b4cd6789
Rollup merge of #89413 - matthewjasper:spec-marker-fix, r=nikomatsakis
Correctly handle supertraits for min_specialization

Supertraits of specialization markers could circumvent checks for
min_specialization. Elaborating predicates prevents this.

r? ````@nikomatsakis````
2021-10-04 21:12:35 -07:00
Jubilee
7aa9ce55b9
Rollup merge of #89270 - seanyoung:join_fold, r=m-ou-se
path.push() should work as expected on windows verbatim paths

On Windows, std::fs::canonicalize() returns an so-called UNC path.  UNC paths differ with regular paths because:

- This type of path can much longer than a non-UNC path (32k vs 260 characters).
- The prefix for a UNC path is ``Component::Prefix(Prefix::DiskVerbatim(..)))``
- No `/` is allowed
- No `.` is allowed
- No `..` is allowed

Rust has poor handling of such paths. If you join a UNC path with a path with any of the above, then this will not work.

I've implemented a new method `fn join_fold()` which joins paths and also removes any `.` and `..` from it, and replaces `/` with `\` on Windows. Using this function it is possible to use UNC paths without issue. In addition, this function is useful on Linux too; paths can be appended without having to call `canonicalize()` to remove the `.` and `..`.

This PR needs test cases, which can I add. I hope this will a start of a discussion.
2021-10-04 21:12:35 -07:00
Jubilee
234fa90878
Rollup merge of #88780 - orlp:int-abs-diff, r=m-ou-se
Added abs_diff for integer types.

Closes https://github.com/rust-lang/rust/issues/62111.
2021-10-04 21:12:34 -07:00
Jubilee
99e6e3ff07
Rollup merge of #87993 - kornelski:try_reserve_stable, r=joshtriplett
Stabilize try_reserve

Stabilization PR for the [`try_reserve` feature](https://github.com/rust-lang/rust/issues/48043#issuecomment-898040475).
2021-10-04 21:12:33 -07:00
Jubilee
9866b090f4
Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplett
Stabilize `const_panic`

Closes #51999

FCP completed in #89006

```@rustbot``` label +A-const-eval +A-const-fn +T-lang

cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04 13:58:17 -07:00
Jubilee
5352e17df3
Rollup merge of #89483 - hkmatsumoto:patch-diagnostics-2, r=estebank
Practice diagnostic message convention

Detected by #89455.

r? ```@estebank```
2021-10-04 13:58:15 -07:00
Jubilee
e1478d650d
Rollup merge of #89443 - cuviper:btree-hash-len, r=dtolnay
Include the length in BTree hashes

This change makes it consistent with `Hash` for all other collections.
2021-10-04 13:58:11 -07:00
Jubilee
9e387cf27e
Rollup merge of #89400 - Nitepone:nitepone/map-or-else-docfix, r=dtolnay
Improve wording of `map_or_else` docs

Changes doc text to refer to the "default" parameter as the "default"
function.

Previously, the doc text referred to the "f" parameter as the "default" function; and the "default" parameter as the "fallback" function.
2021-10-04 13:58:09 -07:00
Jubilee
19d9a147be
Rollup merge of #88452 - xu-cheng:vecdeque-from-array, r=m-ou-se
VecDeque: improve performance for From<[T; N]>

Create `VecDeque` directly from the array instead of inserting items one-by-one.

Benchmark
```
./x.py bench library/alloc --test-args vec_deque::bench_from_array_1000
```

* Before
```
test vec_deque::bench_from_array_1000                    ... bench:       3,991 ns/iter (+/- 717)
```

* After
```
test vec_deque::bench_from_array_1000                    ... bench:         268 ns/iter (+/- 37)
```
2021-10-04 13:58:08 -07:00
Jubilee
ca8a10845f
Rollup merge of #87091 - the8472:more-advance-by-impls, r=joshtriplett
implement advance_(back_)_by on more iterators

Add more efficient, non-default implementations for `feature(iter_advance_by)` (#77404) on more iterators and adapters.

This PR only contains implementations where skipping over items doesn't elide any observable side-effects such as user-provided closures or `clone()` functions. I'll put those in a separate PR.
2021-10-04 13:58:07 -07:00
Benoît du Garreau
47edde1086 Optimize saturating_add_signed 2021-10-04 18:52:17 +02:00
bors
175b8db73b Auto merge of #88834 - the8472:char-count, r=joshtriplett
optimize str::from_utf8() validation when slice contains multibyte chars and str.chars().count() in all cases

The change shows small but consistent improvements across several x86 target feature levels. I also tried to optimize counting with `slice.as_chunks` but that yielded more inconsistent results, bigger improvements for some optimization levels, lesser ones in others.

```
old, -O2, x86-64
test str::str_char_count_emoji                                  ... bench:       1,924 ns/iter (+/- 26)
test str::str_char_count_lorem                                  ... bench:         879 ns/iter (+/- 12)
test str::str_char_count_lorem_short                            ... bench:           5 ns/iter (+/- 0)

new, -O2, x86-64
test str::str_char_count_emoji                                  ... bench:       1,878 ns/iter (+/- 21)
test str::str_char_count_lorem                                  ... bench:         851 ns/iter (+/- 11)
test str::str_char_count_lorem_short                            ... bench:           4 ns/iter (+/- 0)

old, -O2, x86-64-v2
test str::str_char_count_emoji                                  ... bench:       1,477 ns/iter (+/- 46)
test str::str_char_count_lorem                                  ... bench:         675 ns/iter (+/- 15)
test str::str_char_count_lorem_short                            ... bench:           5 ns/iter (+/- 0)

new, -O2, x86-64-v2
test str::str_char_count_emoji                                  ... bench:       1,323 ns/iter (+/- 39)
test str::str_char_count_lorem                                  ... bench:         593 ns/iter (+/- 18)
test str::str_char_count_lorem_short                            ... bench:           4 ns/iter (+/- 0)

old, -O2, x86-64-v3
test str::str_char_count_emoji                                  ... bench:         748 ns/iter (+/- 7)
test str::str_char_count_lorem                                  ... bench:         348 ns/iter (+/- 2)
test str::str_char_count_lorem_short                            ... bench:           5 ns/iter (+/- 0)

new, -O2, x86-64-v3
test str::str_char_count_emoji                                  ... bench:         650 ns/iter (+/- 4)
test str::str_char_count_lorem                                  ... bench:         301 ns/iter (+/- 1)
test str::str_char_count_lorem_short                            ... bench:           5 ns/iter (+/- 0)
```

and for the multibyte-char string validation:

```
old, -O2, x86-64
test str::str_validate_emoji                                    ... bench:       4,606 ns/iter (+/- 64)

new, -O2, x86-64
test str::str_validate_emoji                                    ... bench:       3,837 ns/iter (+/- 60)
```
2021-10-04 12:49:57 +00:00
Kornel
00152d8977 Stabilize try_reserve 2021-10-04 10:29:46 +01:00
Yoshua Wuyts
03fbc160cd Add doc aliases to std:🧵:available_parallelism 2021-10-04 11:13:39 +02:00
bors
44593aeb13 Auto merge of #89512 - Manishearth:rollup-meh9x7r, r=Manishearth
Rollup of 14 pull requests

Successful merges:

 - #86434 (Add `Ipv6Addr::is_benchmarking`)
 - #86828 (const fn for option copied, take & replace)
 - #87679 (BTree: refine some comments)
 - #87910 (Mark unsafe methods NonZero*::unchecked_(add|mul) as const.)
 - #88286 (Remove unnecessary unsafe block in `process_unix`)
 - #88305 (Manual Debug for Unix ExitCode ExitStatus ExitStatusError)
 - #88353 (Partially stabilize `array_methods`)
 - #88370 (Add missing `# Panics` section to `Vec` method)
 - #88481 (Remove some feature gates)
 - #89138 (Fix link in Ipv6Addr::to_ipv4 docs)
 - #89401 (Add truncate note to Vec::resize)
 - #89467 (Fix typos in rustdoc/lints)
 - #89472 (Only register `WSACleanup` if `WSAStartup` is actually ever called)
 - #89505 (Add regression test for spurious const error with NLL)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-04 07:25:50 +00:00
Jacob Pratt
bce8621983
Stabilize const_panic 2021-10-04 02:33:33 -04:00
Manish Goregaokar
e021a10395
Rollup merge of #89472 - nagisa:nagisa/wsa-cleanup, r=dtolnay
Only register `WSACleanup` if `WSAStartup` is actually ever called

See https://github.com/rust-lang/rust/pull/85595

Fixes #85441
2021-10-03 23:13:24 -07:00
Manish Goregaokar
d236c04bbf
Rollup merge of #89401 - owengage:master, r=joshtriplett
Add truncate note to Vec::resize

A very minor addition to the `Vec::resize` documentation to point out the `truncate` method.
When I was searching for something matching `truncate` I managed to miss it, along with some colleagues. We later found it by chance. We did find `resize` however, so I was hoping to point it out in the documentation.
2021-10-03 23:13:22 -07:00
Manish Goregaokar
c167eeedf4
Rollup merge of #89138 - newpavlov:patch-2, r=dtolnay
Fix link in Ipv6Addr::to_ipv4 docs
2021-10-03 23:13:21 -07:00
Manish Goregaokar
5e66ba799b
Rollup merge of #88370 - Seppel3210:master, r=dtolnay
Add missing `# Panics` section to `Vec` method

namely `Vec::extend_from_within`
2021-10-03 23:13:20 -07:00
Manish Goregaokar
70d82e0a6e
Rollup merge of #88353 - jhpratt:stabilize-array-as-ref, r=joshtriplett
Partially stabilize `array_methods`

This stabilizes `<[T; N]>::as_slice` and `<[T; N]>::as_mut_slice`, which is forms part of the `array_methods` feature: #76118.

This also makes `<[T; N]>::as_slice` const due to its trivial nature.
2021-10-03 23:13:19 -07:00
Manish Goregaokar
e4d257e1d3
Rollup merge of #88305 - ijackson:exitstatus-debug, r=dtolnay
Manual Debug for Unix ExitCode ExitStatus ExitStatusError

These structs have misleading names.  An ExitStatus[Error] is actually a Unix wait status; an ExitCode is actually an exit status.  These misleading names appear in the `Debug` output.

The `Display` impls on Unix have been improved, but the `Debug` impls are still misleading, as reported in #74832.

Fix this by pretending that these internal structs are called `unix_exit_status` and `unix_wait_status` as applicable.  (We can't actually rename the structs because of the way that the cross-platform machinery works: the names are cross-platform.)

After this change, this program
```
#![feature(exit_status_error)]
fn main(){
    let x = std::process::Command::new("false").status().unwrap();
    dbg!(x.exit_ok());
    eprintln!("x={:?}",x);
}
```
produces this output
```
[src/main.rs:4] x.exit_ok() = Err(
    ExitStatusError(
        unix_wait_status(
            256,
        ),
    ),
)
x=ExitStatus(unix_wait_status(256))
```

Closes #74832
2021-10-03 23:13:18 -07:00
Manish Goregaokar
f2ec71fe74
Rollup merge of #88286 - LeSeulArtichaut:unnecessary-unsafe-block-std, r=dtolnay
Remove unnecessary unsafe block in `process_unix`

Because it's nested under this unsafe fn!

This block isn't detected as unnecessary because of a bug in the compiler: #88260.
2021-10-03 23:13:18 -07:00
Manish Goregaokar
e500f1c1e9
Rollup merge of #87910 - iago-lito:mark_unsafe_nonzero_arithmetics_as_const, r=joshtriplett
Mark unsafe methods NonZero*::unchecked_(add|mul) as const.

Now that https://github.com/rust-lang/rfcs/pull/3016 has landed, these two unstable `std` function can be marked `const`, according to this detail of #84186.
2021-10-03 23:13:17 -07:00
Manish Goregaokar
0f9e960241
Rollup merge of #87679 - ssomers:btree_comments, r=joshtriplett
BTree: refine some comments
2021-10-03 23:13:16 -07:00
Manish Goregaokar
287af0403a
Rollup merge of #86828 - lambinoo:67441-const-fn-copied-take-replace, r=joshtriplett
const fn for option copied, take & replace

Tracking issue: [#67441](https://github.com/rust-lang/rust/issues/67441)

Adding const fn for the copied, take and replace method of Option. Also adding necessary unit test.

It's my first contribution so I am pretty sure I don't know what I'm doing but there's a first for everything!
2021-10-03 23:13:16 -07:00
Manish Goregaokar
22714ed4e3
Rollup merge of #86434 - CDirkx:ipv6-benchmarking, r=joshtriplett
Add `Ipv6Addr::is_benchmarking`

This PR adds the unstable method `Ipv6Addr::is_benchmarking`. This method is added for parity with `Ipv4Addr::is_benchmarking`, and I intend to use it in a future rework of `Ipv6Addr::is_global` (edit: #86634) to more accurately follow the [IANA Special Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml) (like is done in `Ipv4Addr::is_global`).

With `Ipv6Addr::is_benchmarking` and `Ipv4Addr::is_benchmarking` now both existing, `IpAddr::is_benchmarking` is also added.
2021-10-03 23:13:15 -07:00
Jacob Pratt
11140ff1a0
Stabilize unreachable_unchecked as const fn 2021-10-04 01:04:17 -04:00
bors
d25de31a0e Auto merge of #89165 - jkugelman:read-to-end-overallocation, r=joshtriplett
Fix read_to_end to not grow an exact size buffer

If you know how much data to expect and use `Vec::with_capacity` to pre-allocate a buffer of that capacity, `Read::read_to_end` will still double its capacity. It needs some space to perform a read, even though that read ends up returning `0`.

It's a bummer to carefully pre-allocate 1GB to read a 1GB file into memory and end up using 2GB.

This fixes that behavior by special casing a full buffer and reading into a small "probe" buffer instead. If that read returns `0` then it's confirmed that the buffer was the perfect size. If it doesn't, the probe buffer is appended to the normal buffer and the read loop continues.

Fixing this allows several workarounds in the standard library to be removed:

- `Take` no longer needs to override `Read::read_to_end`.
- The `reservation_size` callback that allowed `Take` to inhibit the previous over-allocation behavior isn't needed.
- `fs::read` doesn't need to reserve an extra byte in `initial_buffer_size`.

Curiously, there was a unit test that specifically checked that `Read::read_to_end` *does* over-allocate. I removed that test, too.
2021-10-04 04:44:56 +00:00
Ryan Lopopolo
e41bb97c25
Add #[repr(i8)] to Ordering
Followup to #89491 to allow `Ordering` to auto-derive `AsRepr` once
the proposal to add `AsRepr` (#81642) lands.
2021-10-03 20:59:54 -07:00
Josh Triplett
199b33f0d7
Use a test value that doesn't depend on the handling of even/odd rounding 2021-10-03 20:15:12 -07:00
Fabian Wolff
e3996ffcb6 Fix Lower/UpperExp formatting for integers and precision zero 2021-10-03 23:05:03 +02:00
Benoît du Garreau
4846fd92c0 Revert suggested use of unwrap_or 2021-10-03 22:56:34 +02:00
Alphyr
70e55a8938
Apply suggestions
Co-authored-by: kennytm <kennytm@gmail.com>
2021-10-03 22:44:07 +02:00
Xinye Tao
cd773c3587
Update outdated comment 2021-10-04 00:27:32 +08:00
bors
08759c691e Auto merge of #88086 - ssomers:btree_clone_testing, r=dtolnay
BTree: toughen panicky test of clone()

Test did not cover the second half of `clone_subtree` and why this clones key & value first.
2021-10-03 16:22:37 +00:00
Orson Peters
6dd6e7c002 Added tracking issue numbers for int_abs_diff. 2021-10-03 17:44:07 +02:00
Caio
91ad91efb6 Skip platforms without unwinding support 2021-10-03 12:25:23 -03:00
bors
5051904d66 Auto merge of #87870 - WaffleLapkin:pub_split_at_unchecked, r=dtolnay
Make `<[T]>::split_at_unchecked` and `<[T]>::split_at_mut_unchecked` public

The methods were originally added in https://github.com/rust-lang/rust/pull/75936 (30dc32b10e), but for some reason as private. Nevertheless, the methods have documentation and even a [tracking issue](https://github.com/rust-lang/rust/issues/76014).

It's very weird to have a tracking issue for private methods and these methods may be useful outside of the standard library. As such, this PR makes the methods public.
2021-10-03 13:41:52 +00:00
bors
4479cb82e5 Auto merge of #89459 - tspiteri:idiv-overflow-bitand, r=kennytm
Use bitand when checking for signed integer division overflow

For `self == Self::MIN && rhs == -1`, LLVM does not realize that this is the same check made by `self / rhs`, so the code generated may have some unnecessary duplication. For `(self == Self::MIN) & (rhs == -1)`, LLVM realizes it is the same check.
2021-10-03 10:34:57 +00:00
Hirochika Matsumoto
3818981ca1 Practice diagnostic message convention 2021-10-03 16:16:28 +09:00
bors
c24c9067ee Auto merge of #88060 - TennyZhuang:optimize-vec-retain, r=dtolnay
Optimize unnecessary check in Vec::retain

The function `vec::Vec::retain` only have two stages:

1. Nothing was deleted.
2. Some elements were deleted.

Here is an unnecessary check `if g.deleted_cnt > 0` in the loop, and it's difficult for compiler to optimize it. I split the loop into two stages manully and keep the code clean using const generics.

I write a special but common bench case for this optimization. I call retain on vec but keep all elements.

Before and after this optimization:

```
test vec::bench_retain_whole_100000                      ... bench:      84,803 ns/iter (+/- 17,314)
```

```
test vec::bench_retain_whole_100000                      ... bench:      42,638 ns/iter (+/- 16,910)
```

The result is expected, there are two `if`s before the optimization and one `if` after.
2021-10-03 06:24:06 +00:00
Cameron Steffen
eec856bfbc Make diangostic item names consistent 2021-10-02 19:38:19 -05:00
Simonas Kazlauskas
5b4873a759 Run the #85441 regression test on MSVC only
On MinGW toolchains the various features (such as function sections)
necessary to eliminate dead function references are disabled due to
various bugs. This means that the windows sockets library will most
likely remain linked to any mingw toolchain built program that also
utilizes libstd.

That said, I made an attempt to also enable `function-sections` and
`--gc-sections` during my experiments, but the symbol references
remained, sadly.
2021-10-02 22:16:23 +03:00
Christiaan Dirkx
9a6f2e655a Only register WSACleanup if WSAStartup is actually ever called 2021-10-02 22:08:35 +03:00
David Carlier
98dde56eb1 haiku thread affinity build fix 2021-10-02 13:24:30 +01:00
Trevor Spiteri
1139ee32aa Use bitand when checking for signed integer division overflow
For `self == Self::MIN && rhs == -1`, LLVM does not realize that this is the
same check made by `self / rhs`, so the code generated may have some unnecessary
duplication. For `(self == Self::MIN) & (rhs == -1)`, LLVM realizes it is the
same check.
2021-10-02 12:16:08 +02:00
bors
a8387aef8c Auto merge of #89450 - usbalbin:const_try_revert, r=oli-obk
Revert #86853

Should fix issue found in #89432
2021-10-02 07:41:25 +00:00
Albin Hedman
81bb5a54c3
Revert "Auto merge of #86853 - usbalbin:const_try, r=oli-obk"
This reverts commit c6007fdc70, reversing
changes made to 69c1c6a173.
2021-10-02 00:07:48 +02:00
Josh Stone
d6fde80cb4 Include the length in BTree hashes
This change makes it consistent with `Hash` for all other collections.
2021-10-01 12:29:09 -07:00
Fabian Wolff
65ef265c12 Call libc::sigaction() only on Android 2021-10-01 21:22:18 +02:00
Sean Young
fa4072f7d3 path.push() should work as expected on windows verbatim paths 2021-10-01 19:54:57 +01:00
pierwill
2a5dcd5890 fix: edit description of "prefix-free" 2021-10-01 13:18:06 -05:00
chrismit3s
1a796441f5 Clarify a sentence in the documentation of Vec (#84488) 2021-10-01 20:07:36 +02:00
pierwill
f531b8122e docs: std:#️⃣:Hash should ensure prefix-free data
Closes #89429
2021-10-01 12:41:22 -05:00
Benoît du Garreau
9faf621355 Add methods to add/sub uX to/from iX 2021-10-01 19:09:52 +02:00
Benoît du Garreau
b5dd5227ee Fix doc test 2021-10-01 19:08:14 +02:00
Alphyr
ab9f8a0b59 Apply suggestion for overflowing_add_signed
Co-authored-by: kennytm <kennytm@gmail.com>
2021-10-01 19:08:13 +02:00
Benoît du Garreau
fe11483afa Add functions to add unsigned and signed integers 2021-10-01 19:08:13 +02:00