Commit graph

3735 commits

Author SHA1 Message Date
Mara Bos
d73015397d Fix Debug implementation for RwLock{Read,Write}Guard.
This would attempt to print the Debug representation of the lock that
the guard has locked, which will try to lock again, fail, and just print
"<locked>" unhelpfully.

After this change, this just prints the contents of the mutex, like the
other smart pointers (and MutexGuard) do.
2021-03-27 13:33:52 +01:00
Mara Bos
2afa4cc958 Use DebugStruct::finish_non_exhaustive() in std. 2021-03-27 13:29:23 +01:00
Mara Bos
ee1b33c7ac Add #[inline] to io::Error methods. 2021-03-27 12:22:17 +01:00
bors
aef11409b4 Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-se
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN

This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks.

This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623.

The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here.

While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623).

There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-27 10:40:16 +00:00
klensy
229d199994 lazily calls some fns 2021-03-27 10:20:32 +03:00
Yuki Okushi
d340f63cca
Rollup merge of #83524 - faern:document-socketaddr-mem-layout, r=sfackler
Document that the SocketAddr memory representation is not stable

Intended to help out with #78802. Work has been put into finding and fixing code that assumes the memory layout of `SocketAddrV4` and `SocketAddrV6`. But it turns out there are cases where new code continues to make the same assumption ([example](96927dc2b7 (diff-917db3d8ca6f862ebf42726b23c72a12b35e584e497ebdb24e474348d7c6ffb6R610-R621))).

The memory layout of a type in `std` is never part of the public API. Unless explicitly stated I guess. But since that is invalidly relied upon by a considerable amount of code for these particular types, it might make sense to explicitly document this. This can be temporary. Once #78802 lands it does not make sense to rely on the layout any longer, and this documentation can also be removed.
2021-03-27 12:37:24 +09:00
Yuki Okushi
c143267901
Rollup merge of #83388 - alamb:alamb/fmt-dcs, r=Mark-Simulacrum
Make # pretty print format easier to discover

# Rationale:

I use (cargo cult?) three formats in rust:  `{}`, debug `{:?}`, and pretty-print debug `{:#?}`. I discovered `{:#?}` in some blog post or guide when I started working in Rust. While `#` is documented I think it is hard to discover. So taking the good advice of ```@carols10cents```  I am trying to improve the docs with a PR

As a reminder "pretty print" means that where `{:?}` will print something like
```
foo: { b1: 1, b2: 2}
```

`{:#?}` will prints something like
```
foo {
  b1: 1
  b2: 3
}
```

# Changes
Add an example to `fmt` to try and make it easier to discover `#`
2021-03-27 12:37:20 +09:00
Reyk Floeter
3d6bd87b24 unix: Fix feature(unix_socket_ancillary_data) on macos and other BSDs
This adds support for CMSG handling on macOS and fixes it on OpenBSD
and other BSDs.

When traversing the CMSG list, the previous code had an exception for
Android where the next element after the last pointer could point to
the first pointer instead of NULL.  This is actually not specific to
Android: the `libc::CMSG_NXTHDR` implementation for Linux and
emscripten have a special case to return NULL when the length of the
previous element is zero; most other implementations simply return the
previous element plus a zero offset in this case.

This MR additionally adds `SocketAncillary::is_empty` because clippy
is right that it should be added.
2021-03-26 21:12:22 +01:00
lcnr
addc51a85f update array missing IntoIterator msg 2021-03-26 21:09:13 +01:00
Linus Färnstrand
147316a094 Document that the SocketAddr memory representation is not stable 2021-03-26 19:44:06 +01:00
Lukas Lueg
abcbe54575 Stabilize peekable_peek_mut
Resolves #78302

Update peekable.rs

Update library/core/src/iter/traits/iterator.rs

Co-authored-by: Ashley Mannix <kodraus@hey.com>
2021-03-26 17:41:14 +01:00
Josh Stone
3b1f5e3462 Use iter::zip in library/ 2021-03-26 09:32:29 -07:00
Josh Stone
b362958453 Add function core::iter::zip
This makes it a little easier to `zip` iterators:

```rust
for (x, y) in zip(xs, ys) {}
// vs.
for (x, y) in xs.into_iter().zip(ys) {}
```

You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and
`iter()`, respectively. This can also support arbitrary nesting, where
it's easier to see the item layout than with arbitrary `zip` chains:

```rust
for ((x, y), z) in zip(zip(xs, ys), zs) {}
for (x, (y, z)) in zip(xs, zip(ys, zs)) {}
// vs.
for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {}
for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {}
```

It may also format more nicely, especially when the first iterator is a
longer chain of methods -- for example:

```rust
    iter::zip(
        trait_ref.substs.types().skip(1),
        impl_trait_ref.substs.types().skip(1),
    )
    // vs.
    trait_ref
        .substs
        .types()
        .skip(1)
        .zip(impl_trait_ref.substs.types().skip(1))
```

This replaces the tuple-pair `IntoIterator` in rust-lang/rust#78204.
There is prior art for the utility of this in [`itertools::zip`].

[`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-26 09:32:10 -07:00
Christiaan Dirkx
4cce9e3db2 Cache GetProcessHeap 2021-03-26 14:47:25 +01:00
CDirkx
b01bf0e9d3 Apply suggestions from code review
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2021-03-26 12:38:27 +01:00
Christiaan Dirkx
0dbed6161a Rework std::sys::windows::alloc
Add documentation to the system functions and `SAFETY` comments.
Refactored helper functions, fixing the correctness of `get_header`.
2021-03-26 12:38:26 +01:00
Ömer Sinan Ağacan
819247f179 Update char::escape_debug_ext to handle different escapes in strings vs. chars
Fixes #83046

The program

    fn main() {
        println!("{:?}", '"');
        println!("{:?}", "'");
    }

would previously print

    '\"'
    "\'"

With this patch it now prints:

    '"'
    "'"
2021-03-26 11:23:51 +03:00
Alan Somers
5afb167bf5 Update backtrace to 0.3.56
Fixes #78184
2021-03-25 22:25:34 -06:00
Dylan DPC
85d08e9afe
Rollup merge of #83463 - ijackson:exitstatusext-doc-grammar, r=kennytm
ExitStatusExt: Fix missing word in two docs messages

Looks like I missed the lack of these "and"s.
2021-03-26 02:34:42 +01:00
Dylan DPC
827d1ea590
Rollup merge of #83456 - notriddle:vec-from-docs, r=JohnTitor
Add docs for Vec::from functions

Part of #51430
2021-03-26 02:34:41 +01:00
Nika Layzell
a591d7ab90 Add strong_count mutation methods to Rc 2021-03-25 11:22:46 -04:00
bors
6e17a5c5fd Auto merge of #83387 - cuviper:min-llvm-10, r=nagisa
Update the minimum external LLVM to 10

r? `@nikic`
2021-03-25 13:11:18 +00:00
Ian Jackson
88ca6c2219 ExitStatusExt: Fix missing word in two docs messages
Looks like I missed the lack of these "and"s.

Acked-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-25 10:48:27 +00:00
bors
bba40880c0 Auto merge of #82565 - m-ou-se:ununstabilize-bits, r=kennytm
Revert reverting of stabilizing integer::BITS.

Now that `lexical-core` has an updated version that won't break with this stabilization, let's try to stabilize this again.

See https://github.com/rust-lang/rust/issues/81654#issuecomment-778564715

Tracking issue with FCP: https://github.com/rust-lang/rust/issues/76904
2021-03-25 10:29:58 +00:00
Ian Jackson
11e40ce240 ExitStatus: print "exit status: {}" rather than "exit code: {}"
Proper Unix terminology is "exit status" (vs "wait status").  "exit
code" is imprecise on Unix and therefore unclear.  (As far as I can
tell, "exit code" is correct terminology on Windows.)

This new wording is unfortunately inconsistent with the identifier
names in the Rust stdlib.

It is the identifier names that are wrong, as discussed at length in eg
  https://doc.rust-lang.org/nightly/std/process/struct.ExitStatus.html
  https://doc.rust-lang.org/nightly/std/os/unix/process/trait.ExitStatusExt.html

Unfortunately for API stability reasons it would be a lot of work, and
a lot of disruption, to change the names in the stdlib (eg to rename
`std::process::ExitStatus` to `std::process::ChildStatus` or
something), but we should fix the message output.  Many (probably
most) readers of these messages about exit statuses will be users and
system administrators, not programmers, who won't even know that Rust
has this wrong terminology.

So I think the right thing is to fix the documentation (as I have
already done) and, now, the terminology in the implementation.

This is a user-visible change to the behaviour of all Rust programs
which run Unix subprocesses.  Hopefully no-one is matching against the
exit status string, except perhaps in tests.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-25 10:27:53 +00:00
Michael Howell
ef1bd5776d
Change wording 2021-03-25 02:58:34 -07:00
Anders Kaseorg
3c42d9fe20 libtest: Index tests by a unique TestId
This more robustly avoids problems with duplicate TestDesc.  See #81852
and #82274.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2021-03-24 23:08:13 -07:00
Ben Kimock
8c88418114 Try to make Vec benchmarks only run code they are benchmarking
Many of the Vec benchmarks assert what values should be produced by the
benchmarked code. In some cases, these asserts dominate the runtime of
the benchmarks they are in, causing the benchmarks to understate the
impact of an optimization or regression.
2021-03-25 00:14:00 -04:00
Michael Howell
b3321e2860 Add docs for Vec::from functions
Part of #51430
2021-03-24 18:43:18 -07:00
Yuki Okushi
ee34453a10
Rollup merge of #83440 - fee1-dead:core-cell-intralink, r=jyn514
Use intra-doc link in core::cell

``@rustbot`` label T-doc A-intra-doc-links

r? ``@jyn514``
2021-03-25 09:07:31 +09:00
Yuki Okushi
921a82007a
Rollup merge of #83421 - faern:add-into-err, r=joshtriplett
Add Result::into_err where the Ok variant is the never type

Equivalent of #66045 but for the inverse situation where `T: Into<!>` rather than `E: Into<!>`.

I'm using the same feature gate name. I can't see why one of these methods would be OK to stabilize but not the other.

Tracking issue: #61695
2021-03-25 09:07:28 +09:00
Yuki Okushi
29e64e913a
Rollup merge of #83349 - m-ou-se:unwrap-none, r=dtolnay
Remove Option::{unwrap_none, expect_none}.

This removes `Option::unwrap_none` and `Option::expect_none` since we're not going to stabilize them, see https://github.com/rust-lang/rust/issues/62633.

Closes #62633
2021-03-25 09:07:26 +09:00
Yuki Okushi
a6ababb162
Rollup merge of #83041 - guswynn:stable_debug_struct, r=m-ou-se
stabilize debug_non_exhaustive

tracking issue: https://github.com/rust-lang/rust/issues/67364

but it is still an open question whether the other `Debug*` struct's should have a similar method. I would guess that would best be put underneath a new feature gate, as this one seems uncontroversial enough to stabilize as is
2021-03-25 09:07:24 +09:00
Mara Bos
b1fac3a5e1
Bump debug_non_exhaustive stabilization to 1.53. 2021-03-24 22:54:04 +01:00
Mara Bos
bacd5226b7 Bump int_bits_const stable version to 1.53. 2021-03-24 22:34:38 +01:00
Mara Bos
81932be5e7 Revert "Revert stabilizing integer::BITS." 2021-03-24 22:34:36 +01:00
Deadbeef
c0fe54fedd
Use intra-doc link in core::cell 2021-03-24 21:42:49 +08:00
bors
680d9fcac1 Auto merge of #83408 - ijackson:expose-splitinclusive, r=dtolnay
Expose str::SplitInclusive in alloc and therefore in std

This seems to have been omitted from the beginning when this feature was first introduced in 86bf96291d.  Most users won't need to name this type which is probably why this wasn't noticed in the meantime.

See #83372 for a different but related bug.

### Notes for reviewers

I think I have got this right but TBH I am not very familiar with the relationship between core and std and so on.  <strike>I also haven't don't any kind of test (not even a build) yet.  I will do a local docs build to see that the type now appears in the std docs.</strike>  I did a local docs build and it has made this type appear as `std::str::SplitInclusive` as expected

The linkification of the return value from `str::split_inclusive` teleports me to the online url for `core::str::SplitInclusive`.  I think this may be a rustdoc anomaly (similar to #79630 maybe) but I am not sure.  Perhaps it means I haven't done the `std` -> `core` referrence correctly.

I made this insta-stable since it seems like simply a bug.  Please LMK if that is not right.  *(edited to add:)* In particular, IDK how this ought to relate to the (?)current release process.
2021-03-24 09:21:06 +00:00
David Tolnay
633a66fb66 Bump alloc::str::SplitInclusive to 1.53.0 release 2021-03-23 20:26:19 -07:00
Dylan DPC
a42e62fa0a
Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisa
Add internal io::Error::new_const to avoid allocations.

This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`.

The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.)

See https://github.com/rust-lang/rust/issues/83352
2021-03-24 01:52:29 +01:00
Linus Färnstrand
3bf076e76b Add test for Result::into_err 2021-03-23 21:41:50 +01:00
Linus Färnstrand
593f9293b9 Add Result::into_err where the Ok variant can never happen 2021-03-23 21:24:26 +01:00
Ian Jackson
52dc0718c0 Expose str::SplitInclusive in alloc and therefore in std
This seems to have been omitted from the beginning when this feature
was first introduced in 86bf96291d.

Most users won't need to name this type which is probably why this
wasn't noticed in the meantime.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-23 11:57:03 +00:00
bors
9b6339e4b9 Auto merge of #82271 - Aaron1011:debug-refcell, r=m-ou-se
Add `debug-refcell` feature to libcore

See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Attaching.20backtraces.20to.20RefCell/near/226273614
for some background discussion

This PR adds a new off-by-default feature `debug-refcell` to libcore.
When enabled, this feature stores additional debugging information in
`RefCell`. This information is included in the panic message when
`borrow()` or `borrow_mut()` panics, to make it easier to track down the
source of the issue.

Currently, we store the caller location for the earliest active borrow.
This has a number of advantages:
* There is only a constant amount of overhead per `RefCell`
* We don't need any heap memory, so it can easily be implemented in core
* Since we are storing the *earliest* active borrow, we don't need any
  extra logic in the `Drop` implementation for `Ref` and `RefMut`

Limitations:
* We only store the caller location, not a full `Backtrace`. Until
  we get support for `Backtrace` in libcore, this is the best tha we can
do.
* The captured location is only displayed when `borrow()` or
  `borrow_mut()` panics. If a crate calls `try_borrow().unwrap()`
  or `try_borrow_mut().unwrap()`, this extra information will be lost.

To make testing easier, I've enabled the `debug-refcell` feature by
default. I'm not sure how to write a test for this feature - we would
need to rebuild core from the test framework, and create a separate
sysroot.

Since this feature will be off-by-default, users will need to use
`xargo` or `cargo -Z build-std` to enable this feature. For users using
a prebuilt standard library, this feature will be disabled with zero
overhead.

I've created a simple test program:

```rust
use std::cell::RefCell;

fn main() {
    let _ = std::panic::catch_unwind(|| {
        let val = RefCell::new(true);
        let _first = val.borrow();
        let _second = val.borrow();
        let _third = val.borrow_mut();
    });

    let _ = std::panic::catch_unwind(|| {
        let val  = RefCell::new(true);
        let first = val.borrow_mut();
        drop(first);

        let _second = val.borrow_mut();

        let _thid = val.borrow();
    });
}
```

which produces the following output:

```
thread 'main' panicked at 'already borrowed: BorrowMutError at refcell_test.rs:6:26', refcell_test.rs:8:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'already mutably borrowed: BorrowError at refcell_test.rs:16:27', refcell_test.rs:18:25
```
2021-03-23 04:49:47 +00:00
Jubilee Young
e8dfbaca76 Rephrase -0.0 docs 2021-03-22 17:02:09 -07:00
Jubilee Young
6fdb8d8b36 Update signed fmt/-0f32 docs
"semantic equivalence" is too strong a phrasing here, which is why
actually explaining what kind of circumstances might produce a -0
was chosen instead.
2021-03-22 17:02:09 -07:00
Jubilee Young
74db93ed2d Preserve signed zero on roundtrip
This commit removes the previous mechanism of differentiating
between "Debug" and "Display" formattings for the sign of -0 so as
to comply with the IEEE 754 standard's requirements on external
character sequences preserving various attributes of a floating
point representation.

In addition, numerous tests are fixed.
2021-03-22 17:02:09 -07:00
Jubilee Young
588cc644ad Add ability to read NaN/Infinity 2021-03-22 17:02:08 -07:00
Jubilee Young
fc9b234928 Add IEEE754 tests 2021-03-22 17:02:06 -07:00
Andrew Lamb
93737dc634
Update library/alloc/src/fmt.rs 2021-03-22 17:09:11 -04:00
Josh Stone
fcb37cb7d6 Fix asm! from AT&T to Intel syntax 2021-03-22 13:12:53 -07:00
bors
5d04957a4b Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakis
Stabilize or_patterns (RFC 2535, 2530, 2175)

closes #54883

This PR stabilizes the or_patterns feature in Rust 1.53.

This is blocked on the following (in order):
- [x] The crater run in https://github.com/rust-lang/rust/pull/78935#issuecomment-731564021
- [x] The resolution of the unresolved questions and a second crater run (https://github.com/rust-lang/rust/pull/78935#issuecomment-735412705)
    - It looks like we will need to pursue some sort of edition-based transition for `:pat`.
- [x] Nomination and discussion by T-lang
- [x] Implement new behavior for `:pat` based on consensus (https://github.com/rust-lang/rust/pull/80100).
- [ ] An FCP on stabilization

EDIT: Stabilization report is in https://github.com/rust-lang/rust/pull/79278#issuecomment-772815177
2021-03-22 19:48:27 +00:00
Andrew Lamb
18748c9121 Make # format easier to discover 2021-03-22 15:14:24 -04:00
Josh Stone
7d872f538e Update the minimum external LLVM to 10 2021-03-22 11:33:43 -07:00
Aaron Hill
a23273e82c
Add debug-refcell feature to libcore
See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Attaching.20backtraces.20to.20RefCell/near/226273614
for some background discussion

This PR adds a new off-by-default feature `debug-refcell` to libcore.
When enabled, this feature stores additional debugging information in
`RefCell`. This information is included in the panic message when
`borrow()` or `borrow_mut()` panics, to make it easier to track down the
source of the issue.

Currently, we store the caller location for the earliest active borrow.
This has a number of advantages:
* There is only a constant amount of overhead per `RefCell`
* We don't need any heap memory, so it can easily be implemented in core
* Since we are storing the *earliest* active borrow, we don't need any
  extra logic in the `Drop` implementation for `Ref` and `RefMut`

Limitations:
* We only store the caller location, not a full `Backtrace`. Until
  we get support for `Backtrace` in libcore, this is the best tha we can
do.
* The captured location is only displayed when `borrow()` or
  `borrow_mut()` panics. If a crate calls `try_borrow().unwrap()`
  or `try_borrow_mut().unwrap()`, this extra information will be lost.

To make testing easier, I've enabled the `debug-refcell` feature by
default. I'm not sure how to write a test for this feature - we would
need to rebuild core from the test framework, and create a separate
sysroot.

Since this feature will be off-by-default, users will need to use
`xargo` or `cargo -Z build-std` to enable this feature. For users using
a prebuilt standard library, this feature will be disabled with zero
overhead.

I've created a simple test program:

```rust
use std::cell::RefCell;

fn main() {
    let _ = std::panic::catch_unwind(|| {
        let val = RefCell::new(true);
        let _first = val.borrow();
        let _second = val.borrow();
        let _third = val.borrow_mut();
    });

    let _ = std::panic::catch_unwind(|| {
        let val  = RefCell::new(true);
        let first = val.borrow_mut();
        drop(first);

        let _second = val.borrow_mut();

        let _thid = val.borrow();
    });
}
```

which produces the following output:

```
thread 'main' panicked at 'already borrowed: BorrowMutError { location: Location { file: "refcell_test.rs", line: 6, col: 26 } }', refcell_test.rs:8:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'already mutably borrowed: BorrowError { location: Location { file: "refcell_test.rs", line: 16, col: 27 } }', refcell_test.rs:18:25
```
2021-03-22 12:39:54 -04:00
Dylan DPC
ce06787548
Rollup merge of #83372 - eggyal:split-inclusive, r=Mark-Simulacrum
SplitInclusive is public API
2021-03-22 15:21:31 +01:00
Dylan DPC
f441c2a9a0
Rollup merge of #83272 - kornelski:takedocs, r=dtolnay
Clarify non-exact length in the Iterator::take documentation

There's an example which demonstrates incomplete length case, but it'd be best to explain it right from the start.
2021-03-22 15:21:26 +01:00
Dylan DPC
83faac9da4
Rollup merge of #82683 - jturner314:int-div-rem-doc-panic, r=nikomatsakis
Document panicking cases for integer division and remainder

This PR documents the cases when integer division and remainder operations panic. These operations panic in two cases: division by zero and overflow.

It's surprising that these operations always panic on overflow, unlike most other arithmetic operations, which panic on overflow only when `debug_assertions` is enabled. The panic on overflow for the remainder is also surprising because a return value of `0` would be reasonable in this case. ("Overflow" occurs only for `MIN % -1`.) Since the panics on overflow are somewhat surprising, they should be documented.

I guess it's worth asking: is panic on overflow (even when `debug_assertions` is disabled) the intended behavior? If not, what's the best way forward?
2021-03-22 15:21:24 +01:00
Dylan DPC
7bf8f82f72
Rollup merge of #82374 - clehner:licenses, r=joshtriplett
Add license metadata for std dependencies

These five crates are in the dependency tree of `std` but lack license metadata:
- `alloc`
- `core`
- `panic_abort`
- `panic_unwind`
- `unwind`

Querying the dependency tree of `std` is a useful thing to be able to do, since these crates will typically be linked into Rust binaries. Tools show the license fields missing, as seen in https://github.com/rust-lang/rust/issues/67014#issuecomment-782704534. This PR adds the license field for the five crates, based on the license of the `std` package and this repo as a whole. I also added the `repository` and `descriptions` fields, since those seem useful. For `description`, I copied text from top-level comments for the respective modules - except for `unwind` which has none.

I also note that https://github.com/rust-lang/rust/pull/73530 attempted to add license metadata for all crates in this repo, but was rejected because there was question about some of them. I hope that this smaller change, focusing only on the runtime dependencies, will be easier to review.

cc `@Mark-Simulacrum` `@Lokathor`
2021-03-22 15:21:23 +01:00
bors
7f82ddb875 Auto merge of #82680 - jturner314:div_euclid-docs, r=JohnTitor
Fix inequality in docs for div_euclid

This commit fixes the statement of the inequality that the Euclidean remainder satisfies. (The remainder is guaranteed to be less than abs(rhs), not rhs.) It also rewords the documentation to make it a little easier to read.

(You might wonder why I've written `abs(rhs)` instead of `rhs.abs()`. Two reasons: first, the `rem_euclid` docs use `abs(rhs)` instead of `rhs.abs()`, and second, the absolute value here is the mathematical absolute value, not the the `.abs()` operation which may overflow.)
2021-03-22 09:37:50 +00:00
Alan Egerton
fe957350c7
SplitInclusive is public API 2021-03-22 09:07:52 +00:00
bors
142c831861 Auto merge of #83360 - Dylan-DPC:rollup-17xulpv, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #80193 (stabilize `feature(osstring_ascii)`)
 - #80771 (Make NonNull::as_ref (and friends) return refs with unbound lifetimes)
 - #81607 (Implement TrustedLen and TrustedRandomAccess for Range<integer>, array::IntoIter, VecDequeue's iterators)
 - #82554 (Fix invalid slice access in String::retain)
 - #82686 (Move `std::sys::unix::platform` to `std::sys::unix::ext`)
 - #82771 (slice: Stabilize IterMut::as_slice.)
 - #83329 (Cleanup LLVM debuginfo module docs)
 - #83336 (Fix ICE with `use clippy:🅰️:b;`)
 - #83350 (Download a more recent LLVM version if `src/version` is modified)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-22 04:03:53 +00:00
Dylan DPC
34285def87
Rollup merge of #82771 - emilio:iter-mut-as-slice, r=m-ou-se
slice: Stabilize IterMut::as_slice.

Much like #72584.

As per #58957 there's no blocker for this, and I wanted to use this
today :-)

Closes #58957
2021-03-22 02:20:30 +01:00
Dylan DPC
c66d66e8d1
Rollup merge of #82686 - CDirkx:unix-platform, r=m-ou-se
Move `std::sys::unix::platform` to `std::sys::unix::ext`

This moves the operating system dependent alias `platform` (`std::os::{linux, android, ...}`) from `std::sys::unix` to `std::sys::unix::ext` (a.k.a. `std::os::unix`), removing the need for compatibility code in `unix_ext` when documenting on another platform.

This is also a step in making it possible to properly move `std::sys::unix::ext` to `std::os::unix`, as ideally `std::sys` should not depend on the rest of `std`.
2021-03-22 02:20:28 +01:00
Dylan DPC
da143d38e4
Rollup merge of #82554 - SkiFire13:fix-string-retain-unsoundness, r=m-ou-se
Fix invalid slice access in String::retain

As noted in #78499, the previous fix was technically still unsound because it accessed elements of a slice outside its bounds (even though they were still inside the same allocation). This PR addresses that concern by switching to a dropguard approach.
2021-03-22 02:20:27 +01:00
Dylan DPC
29a53e6e69
Rollup merge of #81607 - the8472:trustedrandomaccess-all-the-things, r=m-ou-se
Implement TrustedLen and TrustedRandomAccess for Range<integer>, array::IntoIter, VecDequeue's iterators

This should make some `FromIterator` and `.zip()` specializations applicable in a few more cases.

``@rustbot`` label libs-impl
2021-03-22 02:20:26 +01:00
Dylan DPC
ad8aa185df
Rollup merge of #80771 - thomcc:nonnull-refmut, r=dtolnay
Make NonNull::as_ref (and friends) return refs with unbound lifetimes

# Rationale:

1. The documentation for all of these functions claims that this is what the functions already do, as they all come with this comment:

    > You must enforce Rust's aliasing rules, *since the returned lifetime 'a is arbitrarily chosen* and does not necessarily reflect the actual lifetime of the data...

    So I think it's just a bug that they weren't this way already. Note that had it not been for this part, I wouldn't be making this PR, so if we decide we won't take this change, I'll follow it up with a docs PR to fix this.

2. This is how the equivalent raw pointer functions behave.

    They also take `self` and not `&self`/`&mut self`, but that can't be changed compatibly at this point. This is the next best thing.

3. Without this fix, often code that uses these methods will find it has to expand the lifetime of the result.

    (I can't speak for others but even in unsafe-heavy code, needing to do this unexpectedly is a huge red flag -- if Rust thinks something should have a specific lifetime, I assume it's for a reason)

### Can this cause existing code to be unsound?

I'm confident this can't cause new unsoundness since the reference exists for at most its lifetime, but you get a borrow checker error if you do something that would require/allow the reference to exist past its lifetime.

Additionally, the aliasing rules of a reference only applies while the reference exists.

This *must* be the case, as it is required by the rules used by safe code. (That said, the documentation in this file sort of contradicts it, but I think it's just ambiguity between the lifetime `'a` in `&'a T` and lifetime of the `&'a T` reference itself...)

We are increasing the lifetime of these references, but they should already have hard bounds on that lifetime, or they'd have borrow checker errors.

(CC ``@RalfJung`` because I have gone and done the mistake where I say something definitive about aliasing in Rust which is honestly outside the group of things I should make definitive comments about).

# Caveats

1. This is insta-stable (except for on the unstable functions ofc). I don't think there's any other alternative.

2. I don't believe this is a breaking change in practice. In theory someone could be assigning `NonNull::as_ref` to a function pointer of type `fn(&NonNull<T>) -> &T`. Now they'd need to use a slightly different function pointer type which is (probably) incompatible. This seems pathological, but I guess crater could be used if there are concerns.

3. This has no tests. The old version didn't either that I saw. I could add some stuff that fails to compile without it, if that would be useful.

4. Sometimes the NLL borrow checker gives up and decides lifetimes live till the end of the scope, as opposed to the range where they're used. If this change can cause this to happen more, then my soundness rationale is wrong, and it's likely breaking.

    In practice this seems super unlikely.

Anyway. That was a lot of typing.

Fixes https://github.com/rust-lang/rust/issues/80183
2021-03-22 02:20:24 +01:00
Dylan DPC
e9398bcc4d
Rollup merge of #80193 - zseri:stabilize-osstring-ascii, r=m-ou-se
stabilize `feature(osstring_ascii)`

This PR stabilizes `feature(osstring_ascii)`.

Fixes #70516.
2021-03-22 02:20:23 +01:00
Ben Kimock
73d773482a fmt, change to cold 2021-03-21 19:17:07 -04:00
Mara Bos
ee10a1dd81 Bump stable version of bufreader_seek_relative. 2021-03-21 23:12:48 +01:00
Ben Kimock
f5e37100d9 Mark RawVec::reserve as inline and outline the resizing logic 2021-03-21 18:11:42 -04:00
Mara Bos
2bd7c1b5de Bump slice_iter_mut_as_slice stable version. 2021-03-21 23:01:28 +01:00
Mara Bos
6bbcc5bfbb
Fix typos
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2021-03-21 21:44:25 +01:00
The8472
6c67e55270 specialize in-place collection further via TrustedRandomAccess
This allows the optimizer to turn certain iterator pipelines such as

```rust
let vec = vec![0usize; 100];
vec.into_iter().map(|e| e as isize).collect::<Vec<_>>()
```

into a noop.

The optimization only applies when iterator sources are  `T: Copy`
since `impl TrustedRandomAccess for IntoIter<T>`.
No such requirement applies to the output type (`Iterator::Item`).
2021-03-21 20:54:06 +01:00
The8472
a1a04e0842 add transmute-via-iterators bench 2021-03-21 20:54:05 +01:00
The8472
08a1dd287d implement TrustedRandomAccess for array::IntoIter 2021-03-21 20:43:48 +01:00
The8472
895d7a9a09 implement TrustedRandomAccess for Ranges over int types 2021-03-21 20:43:48 +01:00
The8472
1438207c3d use BITS constant 2021-03-21 20:41:01 +01:00
The8472
236c0cf103 implement TrustedLen and TrustedRandomAccess for VecDeque iterators 2021-03-21 20:41:01 +01:00
Mara Bos
7b71719faf Use io::Error::new_const everywhere to avoid allocations. 2021-03-21 20:22:38 +01:00
Mara Bos
96783625a0 Add test for io::Error::new_const. 2021-03-21 20:22:26 +01:00
Mara Bos
2da9856f17 Add internal io::Error::new_const tot avoid allocations. 2021-03-21 20:21:51 +01:00
Mara Bos
f398a49829 Add test for io::Error's size. 2021-03-21 20:20:58 +01:00
Mara Bos
0acdada18b Bump osstring_ascii stabilization version to 1.53.0. 2021-03-21 17:49:14 +01:00
bors
f82664191d Auto merge of #83053 - oli-obk:const_stab_version, r=m-ou-se
Fix const stability `since` versions.

fixes #82085

r? `@m-ou-se`
2021-03-21 16:21:39 +00:00
Dylan DPC
0fa6831655
Rollup merge of #83280 - starthal:fix-typo-keyword-docs, r=dtolnay
Fix pluralization in keyword docs
2021-03-21 02:01:37 +01:00
Yechan Bae
26a62701e4 Update the comment 2021-03-20 13:42:54 -04:00
bors
eb9ec31168 Auto merge of #82919 - bstrie:stabchar, r=dtolnay
Stabilize `assoc_char_funcs` and `assoc_char_consts`

Stabilizes the following associated items on `char`:

* [`char::MAX`](https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.MAX)
* [`char::REPLACEMENT_CHARACTER`](https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.REPLACEMENT_CHARACTER)
* [`char::UNICODE_VERSION`](https://doc.rust-lang.org/std/primitive.char.html#associatedconstant.UNICODE_VERSION)
* [`char::decode_utf16`](https://doc.rust-lang.org/std/primitive.char.html#method.decode_utf16)
* [`char::from_u32`](https://doc.rust-lang.org/std/primitive.char.html#method.from_u32)
* [`char::from_u32_unchecked`](https://doc.rust-lang.org/std/primitive.char.html#method.from_u32_unchecked)
* [`char::from_digit`](https://doc.rust-lang.org/std/primitive.char.html#method.from_digit)

Closes #71763.
2021-03-20 06:36:42 +00:00
Stephen Albert-Moore
3855597186 Fix broken doc link reference 2021-03-20 00:36:41 -04:00
bstrie
567f0e1a39
Stabilize assoc_char_funcs and assoc_char_consts 2021-03-19 20:35:08 -07:00
mark
553ceb0791 core/std/alloc: stabilize or_patterns 2021-03-19 19:45:42 -05:00
Dylan DPC
dbf589f970
Rollup merge of #83269 - bstrie:revertdep, r=m-ou-se
Revert the second deprecation of collections::Bound

Per the review at https://github.com/rust-lang/rust/pull/82122#discussion_r596448078 and the decision at https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/unavoidable.20breakage.20when.20deprecating.20an.20enum.3F , revert this small portion of #82122 for the time being. This doesn't affect the other components of that patch, i.e. `intrinsics::drop_in_place` is still deprecated-for-real, and uses of `collections::Bound` remain removed from the repo.
2021-03-19 23:01:39 +01:00
Dylan DPC
2cc5d72792
Rollup merge of #83254 - jfrimmel:panic_output-stream, r=m-ou-se,joshtriplett
Include output stream in `panic!()` documentation

Fixes #83252.
2021-03-19 23:01:38 +01:00
Dylan DPC
1a0e32f4bc
Rollup merge of #83244 - cuviper:vec_deque-zst, r=m-ou-se
Fix overflowing length in Vec<ZST> to VecDeque

`Vec` can hold up to `usize::MAX` ZST items, but `VecDeque` has a lower
limit to keep its raw capacity as a power of two, so we should check
that in `From<Vec<T>> for VecDeque<T>`. We can also simplify the
capacity check for the remaining non-ZST case.

Before this fix, the new test would fail on the length:

```
thread 'collections::vec_deque::tests::test_from_vec_zst_overflow' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `9223372036854775808`', library/alloc/src/collections/vec_deque/tests.rs:474:5
note: panic did not contain expected string
      panic message: `"assertion failed: `(left == right)`\n  left: `0`,\n right: `9223372036854775808`"`,
 expected substring: `"capacity overflow"`
```

That was a result of `len()` using a mask `& (size - 1)` with the
improper length. Now we do get a "capacity overflow" panic as soon as
that `VecDeque::from(vec)` is attempted.

Fixes #80167.
2021-03-19 23:01:37 +01:00
Dylan DPC
f7febc8865
Rollup merge of #82570 - WaffleLapkin:split_whitespace_as_str, r=m-ou-se
Add `as_str` method for split whitespace str iterators

This PR adds `as_str` methods to `SplitWhitespace` and `SplitAsciiWhitespace`
str iterators. The methods return the remainder, similar to `as_str` methods on
`Chars` and other split iterators. This PR is a continuation of https://github.com/rust-lang/rust/pull/75265, which added `as_str` for all other str split iterators.

The feature gate for new methods is `#![feature(str_split_whitespace_as_str)]`.

`SplitWhitespace` and `SplitAsciiWhitespace` use iterators under the hood, so to implement `as_str` it's required to either
1. Make fields of some iterators `pub(crate)`
2. Add getter methods (like `into_inner`, `inner`, `inner_mut`...) to some (all) iterators
3. Completely rewrite `SplitWhitespace` and `SplitAsciiWhitespace`

This PR uses the 1. approach since it's easier to implement and requires fewer changes (and no changes to the public API). If you think that's not the right way, please, tell me.

r? `@m-ou-se`
2021-03-19 23:01:35 +01:00
Dylan DPC
99f411d438
Rollup merge of #83270 - steffahn:missing_word_in_skip_while_doc, r=joshtriplett
Fix typo/inaccuracy in the documentation of Iterator::skip_while

One of the examples used to say “this leads to a possibly confusing situation, where the type of the closure is a double reference” while _actually_ referring to the type of the closure _argument_.

This PR just changes a single word in documentation.

`````@rustbot````` modify labels: A-iterators, T-doc, T-lang
2021-03-19 15:03:29 +01:00
Dylan DPC
675ae2e366
Rollup merge of #83215 - bstrie:dephaikuraw, r=joshtriplett
Deprecate std::os::haiku::raw, which accidentally wasn't deprecated

In early 2016, all `std::os::*::raw` modules [were deprecated](aa23c98450) in accordance with [RFC 1415](https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md). However, at this same time support for Haiku was being added to libstd, landing shortly after the aforementioned commit, and due to some crossed wires a `std::os::haiku::raw` module was added and was not marked as deprecated.

I have been in correspondence with the author of the Haiku patch, ````@nielx,```` who has confirmed that this was simply an oversight and that the definitions from the libc crate should be preferred instead.
2021-03-19 15:03:26 +01:00
Dylan DPC
db4a97c4cb
Rollup merge of #82892 - jix:clarify-read-read, r=joshtriplett
Clarify docs for Read::read's return value

Right now the docs for `Read::read`'s return value are phrased in a way that makes it easy for the reader to assume that the return value is never larger than the passed buffer. This PR clarifies that this is a requirement for implementations of the trait, but that callers have to expect a buggy yet safe implementation failing to do so, especially if unchecked accesses to the buffer are done afterwards.

I fell into this trap recently, and when I noticed, I looked at the docs again and had the feeling that I might not have been the first one to miss this.

The same issue of trusting the return value of `read` was also present in std itself for about 2.5 years and only fixed recently, see #80895.

I hope that clarifying the docs might help others to avoid this issue.
2021-03-19 15:03:22 +01:00
Dylan DPC
4abcd4042c
Rollup merge of #82500 - CDirkx:hermit-pipe, r=joshtriplett
Reuse `std::sys::unsupported::pipe` on `hermit`

Pipes are not supported on `hermit` and `hermit/pipe.rs` is identical to `unsupported/pipe.rs`. This PR reduces duplication between the two by doing the following on `hermit`:

```rust
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
```
2021-03-19 15:03:14 +01:00
bors
eb95acea8a Auto merge of #71780 - jcotton42:string_remove_matches, r=joshtriplett
Implement String::remove_matches

Closes #50206.

I lifted the function help from `@frewsxcv's` original PR (#50015), hope they don't mind.

I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
2021-03-19 00:47:37 +00:00
Jannis Harder
9dfda62763 Clarify docs for Read::read's return value 2021-03-18 22:52:46 +01:00
Stephen Albert-Moore
b6a12d58f5
Fix pluralization in keyword docs 2021-03-18 17:04:58 -04:00
J. Frimmel
19bd0669b4
Apply suggestions from code review
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-03-18 21:15:19 +01:00
Kornel
6cfdc385a1 Expand documentation of Iterator::take and skip 2021-03-18 20:07:29 +00:00
Frank Steffahn
99b2054fe5 Fix typo/inaccuracy in the documentation of Iterator::skip_while
One of the examples used to say “this leads to a possibly confusing situation,
where the type of the closure is a double reference” while _actually_ referring to
the type of the closure _argument_.
2021-03-18 18:58:22 +01:00
bstrie
1e322e33fe Revert the second deprecation of collections::Bound 2021-03-18 13:57:31 -04:00
Stein Somers
fd6e4e41b7 BTree: no longer search arrays twice to check Ord 2021-03-18 17:47:53 +01:00
Julian Frimmel
d5e45b50cd Incorporate review feedback #2 2021-03-18 15:15:28 +01:00
Julian Frimmel
61e5d549b4 Add more information about panicking
This includes the description of the default `std` behavior and mentions
the `panic::set_hook()` function.
2021-03-18 14:24:13 +01:00
bors
0464f638af Auto merge of #77566 - Marwes:smaller_hashmap, r=Amanieu
feat: Update hashbrown to instantiate less llvm IR

Includes https://github.com/rust-lang/hashbrown/pull/204 and https://github.com/rust-lang/hashbrown/pull/205 (not yet merged) which both serve to reduce the amount of IR generated for hashmaps.

Inspired by the llvm-lines data gathered in https://github.com/rust-lang/rust/pull/76680 (cc `@Julian-Wollersberger)`
2021-03-18 11:03:49 +00:00
Julian Frimmel
55d9e0f601 Include output stream in panic!() documentation 2021-03-18 09:52:21 +01:00
bors
895a8e71b1 Auto merge of #81312 - dylni:clarify-btree-range-search-comments, r=m-ou-se
Clarify BTree `range_search` comments

These comments were added by #81169. However, the soundness issue [might not be exploitable here](https://github.com/rust-lang/rust/pull/81169#issuecomment-765271717), so the comments should be updated.

cc `@ssomers`
2021-03-18 08:18:06 +00:00
bors
2aafe452b8 Auto merge of #82868 - petrochenkov:bto, r=estebank
Report missing cases of `bare_trait_objects`

Fixes https://github.com/rust-lang/rust/issues/65371
2021-03-18 05:27:26 +00:00
Dylan DPC
03400455e1
Rollup merge of #83223 - JohnTitor:display-err-from-mmap, r=joshtriplett
Display error details when a `mmap` call fails

Fixes #82388
2021-03-18 00:28:15 +01:00
Dylan DPC
c99200fa53
Rollup merge of #82434 - jyn514:hash, r=JohnTitor
Add more links between hash and btree collections

- Link from `core::hash` to `HashMap` and `HashSet`
- Link from HashMap and HashSet to the module-level documentation on
  when to use the collection
- Link from several collections to Wikipedia articles on the general
  concept

See also https://github.com/rust-lang/rust/pull/81989#issuecomment-783920840.
2021-03-18 00:28:07 +01:00
Dylan DPC
90797ef008
Rollup merge of #82191 - Soveu:dedup, r=nagisa
Vec::dedup_by optimization

Now `Vec::dedup_by` drops items in-place as it goes through them.
From my benchmarks, it is around 10% faster when T is small, with no major regression when otherwise.

I used `ptr::copy` instead of conditional `ptr::copy_nonoverlapping`, because the latter had some weird performance issues on my ryzen laptop (it was 50% slower on it than on intel/sandybridge laptop)
It would be good if someone was able to reproduce these results.
2021-03-18 00:28:04 +01:00
The8472
d7fdd90655 add bench 2021-03-18 00:25:20 +01:00
The8472
dd166da8f8 generalize slice::fill specialization for byte-sized items
This should also improve cross-crate inlining since the method is generic
2021-03-18 00:25:20 +01:00
Vadim Petrochenkov
dac96d45af Fix use of bare trait objects everywhere 2021-03-18 02:18:58 +03:00
Josh Stone
c07955c6b6 Fix overflowing length in Vec<ZST> to VecDeque
`Vec` can hold up to `usize::MAX` ZST items, but `VecDeque` has a lower
limit to keep its raw capacity as a power of two, so we should check
that in `From<Vec<T>> for VecDeque<T>`. We can also simplify the
capacity check for the remaining non-ZST case.

Before this fix, the new test would fail on the length:

```
thread 'collections::vec_deque::tests::test_from_vec_zst_overflow' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `9223372036854775808`', library/alloc/src/collections/vec_deque/tests.rs:474:5
note: panic did not contain expected string
      panic message: `"assertion failed: `(left == right)`\n  left: `0`,\n right: `9223372036854775808`"`,
 expected substring: `"capacity overflow"`
```

That was a result of `len()` using a mask `& (size - 1)` with the
improper length. Now we do get a "capacity overflow" panic as soon as
that `VecDeque::from(vec)` is attempted.
2021-03-17 16:02:07 -07:00
bors
36f1f04f18 Auto merge of #82122 - bstrie:dep4real, r=dtolnay
Deprecate `intrinsics::drop_in_place` and `collections::Bound`, which accidentally weren't deprecated

Fixes #82080.

I've taken the liberty of updating the `since` values to 1.52, since an unobservable deprecation isn't much of a deprecation (even the detailed release notes never bothered to mention these deprecations).

As mentioned in the issue I'm *pretty* sure that using a type alias for `Bound` is semantically equivalent to the re-export; [the reference implies](https://doc.rust-lang.org/reference/items/type-aliases.html) that type aliases only observably differ from types when used on unit structs or tuple structs, whereas `Bound` is an enum.
2021-03-17 19:39:03 +00:00
Stein Somers
33d22f8400 BTree: clarify order sanity enforced by range searches 2021-03-17 20:09:07 +01:00
Joshua Nelson
a7491d932f
fix whitespace
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2021-03-17 09:27:34 -04:00
bors
0ce0fedb67 Auto merge of #81358 - mcastorina:to-upper-lower-speed, r=joshtriplett
Add a check for ASCII characters in to_upper and to_lower

This extra check has better performance. See discussion here:
https://internals.rust-lang.org/t/to-upper-speed/13896

Thanks to `@gilescope` for helping discover and test this.
2021-03-17 11:17:18 +00:00
Yuki Okushi
3122510748
Rollup merge of #82826 - pierwill:fix-IPv, r=JohnTitor
(std::net::parser): Fix capitalization of IP version names

Also add some missing puctuation in doc and code comments.
2021-03-17 15:20:49 +09:00
Yuki Okushi
f414c33e5e Display error details when a mmap call fails 2021-03-17 12:01:55 +09:00
dylni
35a2096538 Fix comments based on review 2021-03-16 22:17:49 -04:00
bstrie
cad3c4241d Deprecate std::os::haiku::raw 2021-03-16 17:43:33 -04:00
Yuki Okushi
39af66f651
Rollup merge of #83160 - m-ou-se:deprecate-rustc-serialize-derives, r=petrochenkov
Deprecate RustcEncodable and RustcDecodable.

We can't remove the `RustcEncodable` and `RustcDecodable` derive macros from the prelude, but we can deprecate them.
2021-03-16 23:54:00 +09:00
Yuki Okushi
d3460cd3c8
Rollup merge of #83091 - usbalbin:const_copy, r=oli-obk
Constify `copy` related functions

Constify

* `*const T::copy_to[_nonoverlapping]`
* `*mut T::copy_to[_nonoverlapping]`
* `*mut T::copy_from[_nonoverlapping]`
* `mem::transmute_copy`
* `mem::swap`
* `ptr::swap[_nonoverlapping]`
* `mem::replace`
* `ptr::replace`
2021-03-16 23:53:56 +09:00
Yuki Okushi
b6df781643
Rollup merge of #83072 - henryboisdequin:patch-1, r=Dylan-DPC
Update `Vec` docs

Fix typos/nits in `Vec` docs
2021-03-16 23:53:54 +09:00
Yuki Okushi
62d38da9fa
Rollup merge of #81822 - Kixunil:path_try_exists, r=kennytm
Added `try_exists()` method to `std::path::Path`

This method is similar to the existing `exists()` method, except it
doesn't silently ignore the errors, leading to less error-prone code.

This change intentionally does NOT touch the documentation of `exists()`
nor recommend people to use this method while it's unstable.
Such changes are reserved for stabilization to prevent confusing people.

Apart from that it avoids conflicts with #80979.

`@joshtriplett` requested this PR in [internals discussion](https://internals.rust-lang.org/t/the-api-of-path-exists-encourages-broken-code/13817/25?u=kixunil)
2021-03-16 23:53:52 +09:00
Soveu
b0092bc995 Vec::dedup optimization - add benches 2021-03-16 14:41:26 +01:00
Markus Westerlind
7cf8d3ac2b feat: Update hashbrown to instantiate less llvm IR
Includes https://github.com/rust-lang/hashbrown/pull/204 and https://github.com/rust-lang/hashbrown/pull/205 (not yet merged) which both server to reduce the amount of IR generated for hashmaps.

Inspired by the llvm-lines data gathered in https://github.com/rust-lang/rust/pull/76680
2021-03-16 11:20:26 +01:00
Martin Habovstiak
4330268181 Filled tracking issue for path_try_exists
This adds the ID of the tracking issue to the feature.
2021-03-16 08:41:14 +01:00
bors
195ad4830e Auto merge of #82898 - oli-obk:tait_🧊, r=nikomatsakis
Add a `min_type_alias_impl_trait` feature gate

This new feature gate only permits type alias impl trait to be constrained by function and trait method return types. All other possible constraining sites like const/static types, closure return types and binding types are now forbidden and gated under the `type_alias_impl_trait` and `impl_trait_in_bindings` feature gates (which are both marked as incomplete, as they have various ways to ICE the compiler or cause query cycles where they shouldn't).

r? `@nikomatsakis`

This is best reviewed commit-by-commit
2021-03-16 04:24:48 +00:00
Camelid
34c6cee397 Rename #[doc(spotlight)] to #[doc(notable_trait)]
"spotlight" is not a very specific or self-explaining name.
Additionally, the dialog that it triggers is called "Notable traits".
So, "notable trait" is a better name.

* Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]`
* Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]`
* Update documentation
* Improve documentation
2021-03-15 13:59:54 -07:00
Soveu
96d6f22a8e
Merge branch 'master' into dedup 2021-03-15 21:51:38 +01:00
Soveu
2285f11724 Vec::dedup optimization - add test for panic 2021-03-15 21:26:22 +01:00
Albin Hedman
db9a53b5d7
Constify mem::transmute_copy 2021-03-15 20:45:57 +01:00
Albin Hedman
45988ee438
Constify mem::replace and ptr::replace 2021-03-15 20:45:43 +01:00
Albin Hedman
64e2248794
Constify mem::swap and ptr::swap[_nonoverlapping] 2021-03-15 20:45:22 +01:00
Albin Hedman
62cf244563
Constify copy_to and copy_from 2021-03-15 20:45:20 +01:00
Soveu
afdbc9ece1 Vec::dedup optimization - finishing polishes 2021-03-15 20:36:29 +01:00
Soveu
2abab1f688 Vec::dedup optimization - add tests 2021-03-15 20:24:35 +01:00
Mara Bos
924e522d16 Deprecate RustcEncodable and RustcDecodable. 2021-03-15 20:16:16 +01:00
bors
107896c32d Auto merge of #83121 - the8472:env-rwlock-2, r=joshtriplett
use RWlock when accessing os::env (take 2)

This reverts commit acdca316c3 (#82877) i.e. redoes #81850 since the invalid unlock attempts in the child process have been fixed in #82949

r? `@joshtriplett`
2021-03-15 18:32:10 +00:00
Oli Scherer
1f7df1956a Replace type_alias_impl_trait by min_type_alias_impl_trait with no actual changes in behaviour
This makes `type_alias_impl_trait` not actually do anything anymore
2021-03-15 17:32:43 +00:00
Oli Scherer
6f3635d87b Fix const stability since versions. 2021-03-15 14:39:18 +00:00
dylni
922ccacc93 Clarify BTree range searching comments 2021-03-15 00:26:41 -04:00
The8472
e22143c075 Revert "Revert "use RWlock when accessing os::env #81850""
This reverts commit acdca316c3.
2021-03-14 19:10:34 +01:00
Mara Bos
8dc0ae24bc Remove Option::{unwrap_none, expect_none}. 2021-03-14 12:54:34 +01:00
Motoki Ikeda
5ec0540da5 Fix a typo in thread_local_dtor.rs 2021-03-14 16:39:29 +09:00
Motoki Ikeda
71a784d763 Fix a typo in swap_nonoverlapping_bytes 2021-03-14 16:32:15 +09:00
Yuki Okushi
f8206ac63d
Rollup merge of #83081 - hyd-dev:assert-message, r=m-ou-se
Fix panic message of `assert_failed_inner`

cc https://github.com/rust-lang/rust/pull/79100#discussion_r593731020

r? ``@m-ou-se``
2021-03-14 13:07:37 +09:00
Yuki Okushi
54546a893d
Rollup merge of #83066 - Seppel3210:master, r=joshtriplett
Add `reverse` search alias for Iterator::rev()

When searching for "reverse" in rustdoc you can't find the rev method on Iterator so here is a search alias for that.
2021-03-14 13:07:35 +09:00
Yuki Okushi
dda9d0589f
Rollup merge of #82943 - kornelski:threadstdio, r=joshtriplett
Demonstrate best practice for feeding stdin of a child processes

Documentation change.

It's possible to create a deadlock with stdin/stdout I/O on a single thread:

* the child process may fill its stdout buffer, and have to wait for the parent process to read it,
* but the parent process may be waiting until its stdin write finishes before reading the stdout.

Therefore, the parent process should use separate threads for writing and reading.

These examples are not deadlocking in practice, because they use short strings, but I think it's better to demonstrate code that works even for long writes. The problem is non-obvious and tricky to debug (it seems that even libstd has a similar issue: #45572).

This also demonstrates how to use stdio with threads: it's not obvious that `.take()` can be used to avoid fighting with the borrow checker.

I've checked that the modified examples run fine.
2021-03-14 13:07:34 +09:00
Yuki Okushi
9ce0820eef
Rollup merge of #82804 - alexcrichton:fix-wasi, r=pnkfelix
std: Fix a bug on the wasm32-wasi target opening files

This commit fixes an issue pointed out in #82758 where LTO changed the
behavior of a program. It turns out that LTO was not at fault here, it
simply uncovered an existing bug. The bindings to
`__wasilibc_find_relpath` assumed that the relative portion of the path
returned was always contained within thee input `buf` we passed in. This
isn't actually the case, however, and sometimes the relative portion of
the path may reference a sub-portion of the input string itself.

The fix here is to use the relative path pointer coming out of
`__wasilibc_find_relpath` as the source of truth. The `buf` used for
local storage is discarded in this function and the relative path is
copied out unconditionally. We might be able to get away with some
`Cow`-like business or such to avoid the extra allocation, but for now
this is probably the easiest patch to fix the original issue.
2021-03-14 13:07:33 +09:00
Yuki Okushi
67bc866e59
Rollup merge of #82121 - lopopolo:pathbuf-osstring-extend, r=joshtriplett
Implement Extend and FromIterator for OsString

Add the following trait impls:

- `impl Extend<OsString> for OsString`
- `impl<'a> Extend<&'a OsStr> for OsString`
- `impl FromIterator<OsString> for OsString`
- `impl<'a> FromIterator<&'a OsStr> for OsString`

Because `OsString` is a platform string with no particular semantics, concatenating them together seems acceptable.

I came across a use case for these trait impls in https://github.com/artichoke/artichoke/pull/1089:

Artichoke is a Ruby interpreter. Its CLI accepts multiple `-e` switches for executing inline Ruby code, like:

```console
$ cargo -q run --bin artichoke -- -e '2.times {' -e 'puts "foo: #{__LINE__}"' -e '}'
foo: 2
foo: 2
```

I use `clap` for command line argument parsing, which collects these `-e` commands into a `Vec<OsString>`. To pass these commands to the interpreter for `Eval`, I need to join them together. Combining these impls with `Iterator::intersperse` https://github.com/rust-lang/rust/issues/79524 would enable me to build a single bit of Ruby code.

Currently, I'm doing something like:

```rust
let mut commands = commands.into_iter();
let mut buf = if let Some(command) = commands.next() {
    command
} else {
    return Ok(Ok(()));
};
for command in commands {
    buf.push("\n");
    buf.push(command);
}
```

If there's interest, I'd also like to add impls for `Cow<'a, OsStr>`, which would avoid allocating the `"\n"` `OsString` in the concatenate + intersperse use case.
2021-03-14 13:07:28 +09:00
Yuki Okushi
6caa350503
Rollup merge of #81465 - joshtriplett:duration-formatting-documentation, r=m-ou-se
Add documentation about formatting `Duration` values

Explain why Duration has a Debug impl but not a Display impl, and
mention the use of Unicode.
2021-03-14 13:07:27 +09:00
Josh Triplett
8fd2f0c81f Add documentation about formatting Duration values
Explain why Duration has a Debug impl but not a Display impl, and
mention the use of Unicode.
2021-03-13 13:06:30 -08:00
bors
acca818928 Auto merge of #83064 - cjgillot:fhash, r=jackh726
Tweaks to stable hashing
2021-03-13 20:21:40 +00:00
Vlad Frolov
dd2b8a0444 provide a more realistic example for BinaryHeap::as_slice 2021-03-13 17:21:56 +02:00
hyd-dev
bc8093ed55
Fix panic message of assert_failed_inner 2021-03-13 18:50:43 +08:00
Sebastian Widua
f201746625 Add reverse search alias for Iterator::rev() 2021-03-13 10:07:01 +01:00
bors
ec487bf3cf Auto merge of #82760 - WaffleLapkin:unleak_extend_from_within, r=kennytm
Fix leak in Vec::extend_from_within

Fixes #82533
2021-03-13 07:06:01 +00:00
Henry Boisdequin
81d1d82596
Update Vec docs 2021-03-13 07:58:03 +05:30
bors
46a934a1dc Auto merge of #83022 - m-ou-se:mem-replace-no-swap, r=nagisa
Don't implement mem::replace with mem::swap.

`swap` is a complicated operation, so this changes the implementation of `replace` to use `read` and `write` instead.

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

I wrote there:

> Implementing the simpler operation (replace) with the much more complicated operation (swap) doesn't make a whole lot of sense. `replace` is just read+write, and the primitive for moving out of a `&mut`. `swap` is for doing that to *two* `&mut` at the same time, which is both more niche and more complicated (as shown by `swap_nonoverlapping_bytes`).

This could be especially interesting for `Option<VeryLargeStruct>::take()`, since swapping such a large structure with `swap_nonoverlapping_bytes` is going to be much less efficient than `ptr::write()`'ing a `None`.

But also for small values where `swap` just reads/writes using temporary variable, this makes a `replace` or `take` operation simpler:
![image](https://user-images.githubusercontent.com/783247/110839393-c7e6bd80-82a3-11eb-97b7-28acb14deffd.png)
2021-03-12 23:27:23 +00:00
Gus Wynn
b8e498162e
Update library/core/src/fmt/builders.rs
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2021-03-12 08:52:26 -08:00
bors
77b996e1c6 Auto merge of #83042 - JohnTitor:rollup-s8efv94, r=JohnTitor
Rollup of 11 pull requests

Successful merges:

 - #80385 (Clarify what `Cell::replace` returns)
 - #82571 (Rustdoc Json: Add tests for Reexports, and improve jsondocck)
 - #82860 (Add `-Z unpretty` flag for the THIR)
 - #82950 (convert slice doc link to intra-doc links)
 - #82965 (Add spirv extension handling in compiletest)
 - #82966 (update MSYS2 link in README)
 - #82979 (Fix "run" button position in error index)
 - #83001 (Ignore Vim swap files)
 - #83003 (rustdoc: tweak the search index format)
 - #83013 (Adjust some `#[cfg]`s to take non-Unix non-Windows operating systems into account)
 - #83018 (Reintroduce accidentally deleted assertions.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-12 00:23:05 +00:00
Yuki Okushi
16ce4f7513
Rollup merge of #82950 - mockersf:slice-intra-doc-link, r=jyn514
convert slice doc link to intra-doc links

Continuing where #80189 stopped, with `core::slice`.

I had an issue with two dead links in my doc when implementing `Deref<Target = [T]>` for one of my type. This means that [`binary_search_by_key`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.binary_search_by_key) was available, but not [`sort_by_key`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.sort_by_key) even though it was linked in it's doc (same issue with [`as_ptr`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_ptr) and [`as_mut_pbr`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_mut_ptr)). It becomes available if I implement `DerefMut`, as it needs an `&mut self`.

<details>
  <summary>Code that will have dead links in its doc</summary>

```rust
pub struct A;
pub struct B;

impl std::ops::Deref for B{
    type Target = [A];

    fn deref(&self) -> &Self::Target {
        &A
    }
}
```
</details>

I removed the link to `sort_by_key` from `binary_search_by_key` doc as I didn't find a nice way to have a live link:
- `binary_search_by_key` is in `core`
- `sort_by_key` is in `alloc`
- intra-doc link `slice::sort_by_key` doesn't work, as `alloc` is not available when `core` is being build (the warning can't be ignored: ```error[E0710]: an unknown tool name found in scoped lint: `rustdoc::broken_intra_doc_links` ```)
- keeping the link as an anchor `#method.sort_by_key` meant a dead link
- an absolute link would work but doesn't feel right...
2021-03-12 08:55:15 +09:00
Yuki Okushi
2f0bbc0d1d
Rollup merge of #80385 - camelid:clarify-cell-replace-docs, r=Mark-Simulacrum
Clarify what `Cell::replace` returns
2021-03-12 08:55:09 +09:00
Gus Wynn
73ddfa0eea stabilize debug_non_exhaustive 2021-03-11 15:17:44 -08:00
bors
03e864fd86 Auto merge of #82417 - the8472:fix-copy_file_range-append, r=m-ou-se
Fix io::copy specialization using copy_file_range when writer was opened with O_APPEND

fixes #82410

While `sendfile()` returns `EINVAL` when the output was opened with O_APPEND,  `copy_file_range()` does not and returns `EBADF` instead, which – unlike other `EBADF` causes – is not fatal for this operation since a regular `write()` will likely succeed.

We now treat `EBADF` as a non-fatal error for `copy_file_range` and fall back to a read-write copy as we already did for several other errors.
2021-03-11 21:41:01 +00:00
Mara Bos
bf27819f37 Don't implement mem::replace with mem::swap. 2021-03-11 19:04:47 +01:00
Camille GILLOT
84bf599bac Add inlining. 2021-03-11 12:24:43 +01:00
François Mockers
232b9f1641 apply review 2021-03-10 18:32:55 +01:00
François Mockers
0d07153507 add back sort_by_key link, allow linter and add comment 2021-03-10 18:18:28 +01:00
Dylan DPC
e58313248a
Rollup merge of #82977 - camsteffen:opt-get-insert-def, r=m-ou-se
Rename `Option::get_or_default` to `get_or_insert_default`

...as [suggested](https://github.com/rust-lang/rust/issues/82901#issuecomment-793548515) by `@m-ou-se.` In hindsight this seems rather obvious, at least to me.

r? `@joshtriplett`
2021-03-10 17:55:47 +01:00
Dylan DPC
d01648b60e
Rollup merge of #82949 - the8472:forget-envlock-on-fork, r=joshtriplett
Do not attempt to unlock envlock in child process after a fork.

This implements the first two points from https://github.com/rust-lang/rust/issues/64718#issuecomment-793030479

This is a breaking change for cases where the environment is accessed in a Command::pre_exec closure. Except for single-threaded programs these uses were not correct anyway since they aren't async-signal safe.

Note that we had a ui test that explicitly tried `env::set_var` in `pre_exec`. As expected it failed with these changes when I tested locally.
2021-03-10 17:55:43 +01:00
Dylan DPC
759204ffc4
Rollup merge of #82217 - m-ou-se:edition-prelude, r=nikomatsakis
Edition-specific preludes

This changes `{std,core}::prelude` to export edition-specific preludes under `rust_2015`, `rust_2018` and `rust_2021`. (As suggested in https://github.com/rust-lang/rust/issues/51418#issuecomment-395630382.) For now they all just re-export `v1::*`, but this allows us to add things to the 2021edition prelude soon.

This also changes the compiler to make the automatically injected prelude import dependent on the selected edition.

cc `@rust-lang/libs` `@djc`
2021-03-10 17:55:38 +01:00
Cameron Steffen
b0514a6a0a Rename Option::get_or_insert_default 2021-03-10 09:07:16 -06:00
philippeitis
c5ac064666
Stabilize bufreader_seek_relative 2021-03-10 01:52:11 -08:00
bstrie
49aa79ec11 Deprecate items that accidentally weren't deprecated
Fixes #82080
2021-03-09 19:09:20 -05:00
Yuki Okushi
1c3fea2f8c
Rollup merge of #82849 - camsteffen:option-get-or-default, r=joshtriplett
Add Option::get_or_default

Tracking issue: #82901

The original issue is #55042, which was closed, but for an invalid reason (see discussion there). Opening this to reconsider (I hope that's okay). It seems like the only gap for `Option` being "entry-like".

I ran into a need for this method where I had a `Vec<Option<MyData>>` and wanted to do `vec[n].get_or_default().my_data_method()`. Using an `Option` as an inner component of a data structure is probably where the need for this will normally arise.
2021-03-10 08:01:32 +09:00
Yuki Okushi
74e74e9df8
Rollup merge of #82411 - ijackson:fix-exitstatus, r=dtolnay
Fixes to ExitStatus and its docs

* On Unix, properly display every possible wait status (and don't panic on weird values)
* In the documentation, be clear and consistent about "exit status" vs "wait status".
2021-03-10 08:01:27 +09:00
Yuki Okushi
c46f948a80
Rollup merge of #79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis
Stabilize `unsafe_op_in_unsafe_fn` lint

This makes it possible to override the level of the `unsafe_op_in_unsafe_fn`, as proposed in https://github.com/rust-lang/rust/issues/71668#issuecomment-729770896.

Tracking issue: #71668
r? ```@nikomatsakis``` cc ```@SimonSapin``` ```@RalfJung```

# Stabilization report

This is a stabilization report for `#![feature(unsafe_block_in_unsafe_fn)]`.

## Summary

Currently, the body of unsafe functions is an unsafe block, i.e. you can perform unsafe operations inside.

The `unsafe_op_in_unsafe_fn` lint, stabilized here, can be used to change this behavior, so performing unsafe operations in unsafe functions requires an unsafe block.

For now, the lint is allow-by-default, which means that this PR does not change anything without overriding the lint level.

For more information, see [RFC 2585](https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md)

### Example

```rust
// An `unsafe fn` for demonstration purposes.
// Calling this is an unsafe operation.
unsafe fn unsf() {}

// #[allow(unsafe_op_in_unsafe_fn)] by default,
// the behavior of `unsafe fn` is unchanged
unsafe fn allowed() {
    // Here, no `unsafe` block is needed to
    // perform unsafe operations...
    unsf();

    // ...and any `unsafe` block is considered
    // unused and is warned on by the compiler.
    unsafe {
        unsf();
    }
}

#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn warned() {
    // Removing this `unsafe` block will
    // cause the compiler to emit a warning.
    // (Also, no "unused unsafe" warning will be emitted here.)
    unsafe {
        unsf();
    }
}

#[deny(unsafe_op_in_unsafe_fn)]
unsafe fn denied() {
    // Removing this `unsafe` block will
    // cause a compilation error.
    // (Also, no "unused unsafe" warning will be emitted here.)
    unsafe {
        unsf();
    }
}
```
2021-03-10 08:01:25 +09:00
The8472
d854789ce1 Do not attempt to unlock envlock in child process after a fork.
This is a breaking change for cases where the environment is
accessed in a Command::pre_exec closure. Except for
single-threaded programs these uses were not correct
anyway since they aren't async-signal safe.
2021-03-09 22:14:07 +01:00
Kornel
ce2d95cd75 Demonstrate best practice for feeding stdin of a child processes
It's possible to create a deadlock with stdin/stdout I/O on a single thread:

* the child process may fill its stdout buffer, and have to wait for the parent process to read it,
* but the parent process may be waiting until its stdin write finishes before reading the stdout.

Therefore, the parent process should use separate threads for writing and reading.
2021-03-09 20:47:23 +00:00
François Mockers
14e23f117e convert slice doc link to intra-doc links 2021-03-09 21:26:07 +01:00
Ian Jackson
11ca64401a
Always compile the fragile wait status test cases, just run them conditionally
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2021-03-09 10:53:03 +00:00
Mara Bos
ba63a84acc
Rollup merge of #82731 - de-vri-es:bump-libc-for-std, r=Mark-Simulacrum
Bump libc dependency of std to 0.2.88.

This PR bumps the `libc` dependency of `std` to 0.2.88. This will fix `TcpListener::accept` for Android on x86 platforms (31a2777d8f).

This will really finally fix https://github.com/rust-lang/rust/issues/82400 for the main branch :)

r? ``@JohnTitor``
2021-03-09 09:05:22 +00:00
Mara Bos
0083e6c989
Rollup merge of #81879 - imbrem:make-reverse-repr-transparent, r=m-ou-se
Added #[repr(transparent)] to core::cmp::Reverse

I found casting from an `&T` to an `&Reverse<T>` potentially useful, but found that `Reverse` was not `#[repr(transparent)]`, so after asking about it [on Reddit](https://www.reddit.com/r/rust/comments/le60uv/make_stdcmpreverse_reprtransparent_and_add_a/), I decided to go ahead and make a pull request which simply adds the attribute to the struct.
2021-03-09 09:05:19 +00:00
Mara Bos
c013dc01f1
Rollup merge of #81127 - hanmertens:binary_heap_sift_down_perf, r=dtolnay
Improve sift_down performance in BinaryHeap

Replacing `child < end - 1` with `child <= end.saturating_sub(2)` in `BinaryHeap::sift_down_range` (surprisingly) results in a significant speedup of `BinaryHeap::into_sorted_vec`. The same substitution can be done for `BinaryHeap::sift_down_to_bottom`, which causes a slight but probably statistically insignificant speedup for `BinaryHeap::pop`. It's interesting that benchmarks aside from `bench_into_sorted_vec` are barely affected, even those that do use `sift_down_*` methods internally.

| Benchmark                | Before (ns/iter) | After (ns/iter) | Speedup |
|--------------------------|------------------|-----------------|---------|
| bench_find_smallest_1000<sup>1</sup> | 392,617          | 385,200         |    1.02 |
| bench_from_vec<sup>1</sup>           | 506,016          | 504,444         |    1.00 |
| bench_into_sorted_vec<sup>1</sup>    | 476,869          | 384,458         |    1.24 |
| bench_peek_mut_deref_mut<sup>3</sup> | 518,753          | 519,792         |    1.00 |
| bench_pop<sup>2</sup>                | 446,718          | 444,409         |    1.01 |
| bench_push<sup>3</sup>               | 772,481          | 770,208         |    1.00 |

<sup>1</sup>: internally calls `sift_down_range`
<sup>2</sup>: internally calls `sift_down_to_bottom`
<sup>3</sup>: should not be affected
2021-03-09 09:05:18 +00:00
bors
bb3afe1e60 Auto merge of #82911 - m-ou-se:rollup-rjomgja, r=m-ou-se
Rollup of 11 pull requests

Successful merges:

 - #82711 (Add documentation for string->Cow conversions)
 - #82767 (Update minifier dependency version)
 - #82800 (Move rustdoc UI tests into a subdirectory)
 - #82810 (Typo fix in Unstable book: `cargo cov` -> `cargo profdata`)
 - #82829 (Handle negative literals in cast overflow warning)
 - #82854 (Account for `if (let pat = expr) {}`)
 - #82870 (Add note about the `#[doc(no-inline)]` usage)
 - #82874 (Add codegen tests for some issues closed by LLVM 12)
 - #82881 (diagnostics: Be clear about "crate root" and `::foo` paths in resolve diagnostics)
 - #82888 (Grammar Fixes)
 - #82897 ([.mailmap] Add entry for Ramkumar Ramachandra)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-09 01:47:39 +00:00
bors
eb476b172f Auto merge of #82877 - ehuss:revert-rwlock, r=m-ou-se
Revert switch of env locking to rwlock, to fix deadlock in process spawning

This reverts commit 354f19cf24, reversing changes made to 0cfba2fd09.

PR https://github.com/rust-lang/rust/pull/81850 switched the environment lock from a mutex to an rwlock. However, process spawning (when not able to use `posix_spawn`) locks the environment before forking, and unlocks it after forking (in both the parent and the child). With a mutex, this works (although probably not correct even with a mutex). With an rwlock, on at least some targets, unlocking in the child does not work correctly, resulting in a deadlock.

This has manifested as CI hangs on i686 Linux; that target doesn't use `posix_spawn` in the CI environment due to the age of the installed C library (currently glibc 2.23). (Switching to `posix_spawn` would just mask this issue, though, which would still arise in any case that can't use `posix_spawn`.)

Some additional cleanup of environment handling around process spawning may help, but for now, revert the PR and go back to a standard mutex.

Fixes #82221
2021-03-08 22:53:20 +00:00
Mara Bos
2d3ba78561
Rollup merge of #82888 - Daggy1234:patch-1, r=joshtriplett
Grammar Fixes

Found typo's in the array rustdoc. Pr'ed a fix!
2021-03-08 20:09:07 +01:00
Mara Bos
a55b192d59
Rollup merge of #82870 - jfrimmel:improve-docs, r=jyn514
Add note about the `#[doc(no-inline)]` usage

This is required to correctly build the documentation (including all submodules, that are only available in certain targets).

See the linked issue and #82861 for reference.
2021-03-08 20:09:03 +01:00
Mara Bos
3114e2bcf3
Rollup merge of #82711 - notriddle:string-cow-docs, r=Mark-Simulacrum
Add documentation for string->Cow conversions

Mostly, it's just to reassure everyone that these functions don't allocate.

Part of #51430
2021-03-08 20:08:56 +01:00
Cameron Steffen
7e3ebe76ee Add Option::get_or_default 2021-03-08 09:24:10 -06:00