Commit graph

2049 commits

Author SHA1 Message Date
Josh Stone
cd22381daa Use syscall! for copy_file_range too 2020-11-16 11:31:12 -08:00
Josh Stone
a035626eb5 Try weak symbols for all linux syscall! wrappers 2020-11-16 11:26:49 -08:00
Josh Stone
7a15f026f2 linux: try to use libc getrandom to allow interposition
We'll try to use a weak `getrandom` symbol first, because that allows
things like `LD_PRELOAD` interposition. For example, perf measurements
might want to disable randomness to get reproducible results. If the
weak symbol is not found, we fall back to a raw `SYS_getrandom` call.
2020-11-16 11:26:49 -08:00
Vadim Petrochenkov
a5bc780b50 std: Fix test got_symlink_permission on Windows 2020-11-16 21:09:26 +03:00
Mara Bos
bac213bee4
Rollup merge of #78903 - ssomers:btree_order_chaos_testing, r=Mark-Simulacrum
BTreeMap: test chaotic ordering & other bits & bobs

r? `@Mark-Simulacrum`
2020-11-16 17:26:33 +01:00
Mara Bos
c0a9bf9336
Rollup merge of #78769 - est31:remove_lifetimes, r=KodrAus
Remove unneeded lifetimes in array/mod.rs
2020-11-16 17:26:29 +01:00
Mara Bos
11ce918c75
Rollup merge of #78714 - m-ou-se:simplify-local-streams, r=KodrAus
Simplify output capturing

This is a sequence of incremental improvements to the unstable/internal `set_panic` and `set_print` mechanism used by the `test` crate:

1. Remove the `LocalOutput` trait and use `Arc<Mutex<dyn Write>>` instead of `Box<dyn LocalOutput>`. In practice, all implementations of `LocalOutput` were just `Arc<Mutex<..>>`. This simplifies some logic and removes all custom `Sink` implementations such as `library/test/src/helpers/sink.rs`. Also removes a layer of indirection, as the outermost `Box` is now gone. It also means that locking now happens per `write_fmt`, not per individual `write` within. (So `"{} {}\n"` now results in one `lock()`, not four or more.)

2. Since in all cases the `dyn Write`s were just `Vec<u8>`s, replace the type with `Arc<Mutex<Vec<u8>>>`. This simplifies things more, as error handling and flushing can be removed now. This also removes the hack needed in the default panic handler to make this work with `::realstd`, as (unlike `Write`) `Vec<u8>` is from `alloc`, not `std`.

3. Replace the `RefCell`s by regular `Cell`s. The `RefCell`s were mostly used as `mem::replace(&mut *cell.borrow_mut(), something)`, which is just `Cell::replace`. This removes an unecessary bookkeeping and makes the code a bit easier to read.

4. Merge `set_panic` and `set_print` into a single `set_output_capture`. Neither the test crate nor rustc (the only users of this feature) have a use for using these separately. Merging them simplifies things even more. This uses a new function name and feature name, to make it clearer this is internal and not supposed to be used by other crates.

Might be easier to review per commit.
2020-11-16 17:26:27 +01:00
Mara Bos
5bbf75da78
Rollup merge of #77691 - exrook:rename-layouterr, r=KodrAus
Rename/Deprecate LayoutErr in favor of LayoutError

Implements rust-lang/wg-allocators#73.

This patch renames LayoutErr to LayoutError, and uses a type alias to support users using the old name.

The new name will be instantly stable in release 1.49 (current nightly), the type alias will become deprecated in release 1.51 (so that when the current nightly is 1.51, 1.49 will be stable).

This is the only error type in `std` that ends in `Err` rather than `Error`, if this PR lands all stdlib error types will end in `Error` 🥰
2020-11-16 17:26:17 +01:00
Mara Bos
de0aa6169f
Rollup merge of #76339 - CDirkx:structural-match-range, r=Mark-Simulacrum
Test structural matching for all range types

As of #70166 all range types (`core::ops::Range` etc.) can be structurally matched upon, and by extension used in const generics. In reference to the fact that this is a publicly observable property of these types, and thus falls under the Rust stability guarantees of the standard library, a regression test was added in #70283.

This regression test was implemented by me by testing for the ability to use the range types within const generics, but that is not the actual property the std guarantees now (const generics is still unstable). This PR addresses that situation by adding extra tests for the range types that directly test whether they can be structurally matched upon.

Note: also adds the otherwise unrelated test `test_range_to_inclusive` for completeness with the other range unit tests
2020-11-16 17:26:13 +01:00
Mara Bos
4cdd220625
Rollup merge of #74989 - pubfnbar:impl-array-indexing, r=KodrAus
Implement `Index` and `IndexMut` for arrays

Adds implementations of `Index` and `IndexMut` for arrays that simply forward to the slice indexing implementation in order to fix the following problem:

If you implement `Index<MyIndexType>` for an array, you lose all the other indexing functionality that used to be available to the array via its implicit coercion to a slice. An example of what I'm talking about:
```rust
use std::ops::Index;

pub enum MyIndexType {
    _0, _1, _2, _3, _4, _5, _6, _7,
}

impl<T> Index<MyIndexType> for [T; 8] {
    type Output = T;

    fn index(&self, index: MyIndexType) -> &T {
        unsafe { self.get_unchecked(index as usize) }
    }
}

fn main() {
    let array = [11u8; 8];

    println!("{:?}", array[MyIndexType::_0]); // OK

    println!("{:?}", array[0usize]); // error[E0277]
    //               ^^^^^^^^^^^^^ `[u8; 8]` cannot be indexed by `usize`
}
```
2020-11-16 17:26:11 +01:00
pubfnbar
c03dfa6671 Implement Index[Mut] for arrays
Adds implementations of `Index` and `IndexMut` for arrays that simply forward to the slice indexing implementation.
2020-11-16 09:05:15 -05:00
Stefan Lankes
207de019dc
libary: Forward compiler-builtins "asm" and "mangled-names" feature
Now users will be able to do:
```
cargo build -Zbuild-std=core -Zbuild-std-features=compiler-builtins-asm
```
and correctly get the assembly implemenations for `memcpy` and friends.
2020-11-16 08:23:12 +01:00
bors
f5230fbf76 Auto merge of #78631 - ssomers:btree-alias_for_underfull, r=Mark-Simulacrum
BTreeMap: fix pointer provenance rules in underfullness

Continuing on #78480, and for readability, and possibly for performance: avoid aliasing when handling underfull nodes, and consolidate the code doing that. In particular:
- Avoid the rather explicit aliasing for internal nodes in `remove_kv_tracking`.
- Climb down to the root to handle underfull nodes using a reborrowed handle, rather than one copied with `ptr::read`, before resuming on the leaf level.
- Integrate the code tracking leaf edge position into the functions performing changes, rather than bolting it on.

r? `@Mark-Simulacrum`
2020-11-16 03:22:10 +00:00
Ralf Jung
af869c2f8d document that __rust_alloc is also magic to our LLVM fork 2020-11-15 18:40:49 +01:00
bjorn3
6f3872a14c Make the libstd build script smaller
Remove all rustc-link-lib from the std build script. Also remove use of
feature = "restricted-std" where not necessary.
2020-11-15 16:17:21 +01:00
bors
5fab31e5dd Auto merge of #79070 - jonas-schievink:rollup-wacn2b8, r=jonas-schievink
Rollup of 13 pull requests

Successful merges:

 - #77802 (Allow making `RUSTC_BOOTSTRAP` conditional on the crate name)
 - #79004 (Add `--color` support to bootstrap)
 - #79005 (cleanup: Remove `ParseSess::injected_crate_name`)
 - #79016 (Make `_` an expression, to discard values in destructuring assignments)
 - #79019 (astconv: extract closures into a separate trait)
 - #79026 (Implement BTreeMap::retain and BTreeSet::retain)
 - #79031 (Validate that locals have a corresponding `LocalDecl`)
 - #79034 (rustc_resolve: Make `macro_rules` scope chain compression lazy)
 - #79036 (Move Steal to rustc_data_structures.)
 - #79041 (Rename clean::{ItemEnum -> ItemKind}, clean::Item::{inner -> kind})
 - #79058 (Move likely/unlikely argument outside of invisible unsafe block)
 - #79059 (Print 'checking cranelift artifacts' to easily separate it from other artifacts)
 - #79063 (Update rustfmt to v1.4.26)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-15 13:19:05 +00:00
Jonas Schievink
aa685e2024
Rollup merge of #79026 - mbrubeck:btree_retain, r=m-ou-se
Implement BTreeMap::retain and BTreeSet::retain

Adds new methods `BTreeMap::retain` and `BTreeSet::retain`.  These are implemented on top of `drain_filter` (#70530).

The API of these methods is identical to `HashMap::retain` and `HashSet::retain`, which were implemented in #39560 and stabilized in #36648.  The docs and tests are also copied from HashMap/HashSet.

The new methods are unstable, behind the `btree_retain` feature gate, with tracking issue #79025.  See also rust-lang/rfcs#1338.
2020-11-15 13:39:54 +01:00
est31
43bfbb10bf Add column number support to Backtrace
Backtrace frames might include column numbers.
Print them if they are included.
2020-11-15 13:09:56 +01:00
bors
0468845924 Auto merge of #78472 - hermitcore:builtins, r=Mark-Simulacrum
add options to use optimized and mangled compiler builtins

In principle the compiler builtin features are also offered to alloc and std.
2020-11-15 10:37:11 +00:00
Stefan Lankes
6de51252e0
add options to use optimized and mangled compiler builtins 2020-11-15 08:23:31 +01:00
Dylan DPC
d57212d49e
Rollup merge of #78988 - alexcrichton:one-more-intrinsic, r=sfackler
Fix an intrinsic invocation on threaded wasm

This looks like it was forgotten to get updated in #74482 and wasm with
threads isn't built on CI so we didn't catch this by accident.
2020-11-15 03:02:57 +01:00
Dylan DPC
dbb37fb1ee
Rollup merge of #78590 - DeveloperC286:issue_60302, r=varkor
refactor: removing alloc::collections::vec_deque ignore-tidy-filelength

This PR removes the need for ignore-tidy-filelength for alloc::collections::vec_deque which is part of the issue https://github.com/rust-lang/rust/issues/60302

It is probably easiest to review this PR by looking at it commit by commit rather than looking at the overall diff.
2020-11-15 03:02:37 +01:00
David Tolnay
29128a5aa2
Disambiguate symlink argument names 2020-11-14 14:46:14 -08:00
Christiaan Dirkx
6554086526 Add u128 and i128 integer tests 2020-11-14 20:27:08 +01:00
bors
30e49a9ead Auto merge of #75272 - the8472:spec-copy, r=KodrAus
specialize io::copy to use copy_file_range, splice or sendfile

Fixes #74426.
Also covers #60689 but only as an optimization instead of an official API.

The specialization only covers std-owned structs so it should avoid the problems with #71091

Currently linux-only but it should be generalizable to other unix systems that have sendfile/sosplice and similar.

There is a bit of optimization potential around the syscall count. Right now it may end up doing more syscalls than the naive copy loop when doing short (<8KiB) copies between file descriptors.

The test case executes the following:

```
[pid 103776] statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=17, ...}) = 0
[pid 103776] write(4, "wxyz", 4)        = 4
[pid 103776] write(4, "iklmn", 5)       = 5
[pid 103776] copy_file_range(3, NULL, 4, NULL, 5, 0) = 5

```

0-1 `stat` calls to identify the source file type. 0 if the type can be inferred from the struct from which the FD was extracted
𝖬 `write` to drain the `BufReader`/`BufWriter` wrappers. only happen when buffers are present. 𝖬 ≾ number of wrappers present. If there is a write buffer it may absorb the read buffer contents first so only result in a single write. Vectored writes would also be an option but that would require more invasive changes to `BufWriter`.
𝖭 `copy_file_range`/`splice`/`sendfile` until file size, EOF or the byte limit from `Take` is reached. This should generally be *much* more efficient than the read-write loop and also have other benefits such as DMA offload or extent sharing.

## Benchmarks

```

OLD

test io::tests::bench_file_to_file_copy         ... bench:      21,002 ns/iter (+/- 750) = 6240 MB/s    [ext4]
test io::tests::bench_file_to_file_copy         ... bench:      35,704 ns/iter (+/- 1,108) = 3671 MB/s  [btrfs]
test io::tests::bench_file_to_socket_copy       ... bench:      57,002 ns/iter (+/- 4,205) = 2299 MB/s
test io::tests::bench_socket_pipe_socket_copy   ... bench:     142,640 ns/iter (+/- 77,851) = 918 MB/s

NEW

test io::tests::bench_file_to_file_copy         ... bench:      14,745 ns/iter (+/- 519) = 8889 MB/s    [ext4]
test io::tests::bench_file_to_file_copy         ... bench:       6,128 ns/iter (+/- 227) = 21389 MB/s   [btrfs]
test io::tests::bench_file_to_socket_copy       ... bench:      13,767 ns/iter (+/- 3,767) = 9520 MB/s
test io::tests::bench_socket_pipe_socket_copy   ... bench:      26,471 ns/iter (+/- 6,412) = 4951 MB/s
```
2020-11-14 12:01:55 +00:00
Thom Chiovoloni
55d7f736d8 Tighten the bounds on atomic Ordering in std::sys::unix::weak 2020-11-13 19:15:51 -08:00
The8472
bbfa92c82d Always handle EOVERFLOW by falling back to the generic copy loop
Previously EOVERFLOW handling was only applied for io::copy specialization
but not for fs::copy sharing the same code.

Additionally we lower the chunk size to 1GB since we have a user report
that older kernels may return EINVAL when passing 0x8000_0000
but smaller values succeed.
2020-11-13 22:38:27 +01:00
The8472
4854d418a5 do direct splice syscall and probe availability to get android builds to work
Android builds use feature level 14, the libc wrapper for splice is gated
on feature level 21+ so we have to invoke the syscall directly.
Additionally the emulator doesn't seem to support it so we also have to
add ENOSYS checks.
2020-11-13 22:38:27 +01:00
The8472
3dfc377aa1 move sendfile/splice/copy_file_range into kernel_copy module 2020-11-13 22:38:27 +01:00
The8472
888b1031bc limit visibility of copy offload helpers to sys::unix module 2020-11-13 22:38:27 +01:00
The8472
18bfe2a66b move copy specialization tests to their own module 2020-11-13 22:38:27 +01:00
The8472
7f5d2722af move copy specialization into sys::unix module 2020-11-13 22:38:23 +01:00
The8472
ad9b07c7e5 add benchmarks 2020-11-13 19:46:37 +01:00
The8472
46e7fbe60b reduce syscalls by inferring FD types based on source struct instead of calling stat()
also adds handling for edge-cases involving large sparse files where sendfile could fail with EOVERFLOW
2020-11-13 19:46:35 +01:00
The8472
0624730d9e add forwarding specializations for &mut variants
`impl Write for &mut T where T: Write`, thus the same should
apply to the specialization traits
2020-11-13 19:45:38 +01:00
The8472
cd3bddc044 prioritize sendfile over splice since it results in fewer context switches when sending to pipes
splice returns to userspace when the pipe is full, sendfile
just blocks until it's done, this can achieve much higher throughput
2020-11-13 19:45:38 +01:00
The8472
67a6059aa5 move tests module into separate file 2020-11-13 19:45:38 +01:00
The8472
5eb88fa5c7 hide unused exports on other platforms 2020-11-13 19:45:38 +01:00
The8472
16236470c1 specialize io::copy to use copy_file_range, splice or sendfile
Currently it only applies to linux systems. It can be extended to make use
of similar syscalls on other unix systems.
2020-11-13 19:45:27 +01:00
Matt Brubeck
bf6902ca61 Add BTreeMap::retain and BTreeSet::retain 2020-11-13 10:23:50 -08:00
C
75dfc711da refactor: vec_deque ignore-tidy-filelength
commit c547d5fabcd756515afa7263ee5304965bb4c497
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 11:22:23 2020 +0000

    test: updating ui/hygiene/panic-location.rs expected

commit 2af03769c4ffdbbbad75197a1ad0df8c599186be
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 10:43:30 2020 +0000

    fix: documentation unresolved link

commit c4b0df361ce27d7392d8016229f2e0265af32086
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:58:31 2020 +0000

    style: compiling with Rust's style guidelines

commit bdd2de5f3c09b49a18e3293f2457fcab25557c96
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:56:31 2020 +0000

    refactor: removing ignore-tidy-filelength

commit fcc4b3bc41f57244c65ebb8e4efe4cbc9460b5a9
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:51:35 2020 +0000

    refactor: moving trait RingSlices to ring_slices.rs

commit 2f0cc539c06d8841baf7f675168f68ca7c21e68e
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:46:09 2020 +0000

    refactor: moving struct PairSlices to pair_slices.rs

commit a55d3ef1dab4c3d85962b3a601ff8d1f7497faf2
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:31:45 2020 +0000

    refactor: moving struct Iter to iter.rs

commit 76ab33a12442a03726f36f606b4e0fe70f8f246b
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:24:32 2020 +0000

    refactor: moving struct IntoIter into into_iter.rs

commit abe0d9eea2933881858c3b1bc09df67cedc5ada5
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 02:19:07 2020 +0000

    refactor: moving struct IterMut into iter_mut.rs

commit 70ebd6420335e1895e2afa2763a0148897963e24
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 01:49:15 2020 +0000

    refactor: moved macros into macros.rs

commit b08dd2add994b04ae851aa065800bd8bd6326134
Author: C <DeveloperC@protonmail.com>
Date:   Sat Oct 31 01:05:36 2020 +0000

    refactor: moving vec_deque.rs to vec_deque/mod.rs
2020-11-13 17:56:39 +00:00
Guillaume Gomez
ef32ef7baf
Rollup merge of #77996 - tkaitchuck:master, r=m-ou-se
Doc change: Remove mention of `fnv` in HashMap

Disclaimer: I am the author of [aHash](https://github.com/tkaitchuck/aHash).

This changes the Rustdoc in `HashMap` from mentioning the `fnv` crate to mentioning the `aHash` crate, as an alternative `Hasher` implementation.

### Why

Fnv [has poor hash quality](https://github.com/rurban/smhasher), is [slow for larger keys](https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md#speed), and does not provide dos resistance, because it is unkeyed (this can also cause [other problems](https://accidentallyquadratic.tumblr.com/post/153545455987/rust-hash-iteration-reinsertion)).

Fnv has acceptable performance for integers and has very poor performance with keys >32 bytes. This is the reason it was removed from the standard library in https://github.com/rust-lang/rust/pull/37229 .

Because regardless of which dimension you value, there are better alternatives, it does not make sense for anyone to consider using `fnv`.

The text mentioning `fnv` in the standard library continues to create confusion: https://github.com/rust-lang/hashbrown/issues/153  https://github.com/rust-lang/hashbrown/issues/9 . There are also a number of [crates using it](https://crates.io/crates/fnv/reverse_dependencies) a great many of which are hashing strings (Which is when Fnv is the [worst](https://github.com/cbreeden/fxhash#benchmarks), [possible](https://github.com/tkaitchuck/aHash#speed), [choice](http://cglab.ca/~abeinges/blah/hash-rs/).)

I think aHash makes the most sense to mention as an alternative because it is the most credible option (in my obviously biased opinion). It offers [good performance on numbers and strings](https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md#speed), is [of high quality](https://github.com/tkaitchuck/aHash#hash-quality), and [provides dos resistance](https://github.com/tkaitchuck/aHash/wiki/How-aHash-is-resists-DOS-attacks). It is popular (see [stats](https://crates.io/crates/ahash)) and is the default hasher for [hashbrown](https://crates.io/crates/hashbrown) and [dashmap](https://crates.io/crates/dashmap) which are the most popular alternative hashmaps. Finally it does not have any of the [`gotcha` cases](https://github.com/tkaitchuck/aHash#fxhash) that `FxHash` suffers from. (Which is the other popular hashing option when DOS attacks are not a concern)

Signed-off-by: Tom Kaitchuck <tom.kaitchuck@emc.com>
2020-11-13 15:26:10 +01:00
Tom Kaitchuck
4e5848349c
Update library/std/src/collections/hash/map.rs
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-11-12 20:14:57 -08:00
Raoul Strackx
292f15ce87 Upgrading dlmalloc to 0.2.1 2020-11-12 21:40:52 +01:00
Mara Bos
40889819ee
Rollup merge of #78857 - SkiFire13:bheap-opt, r=KodrAus
Improve BinaryHeap performance

By changing the condition in the loops from `child < end` to `child < end - 1` we're guaranteed that `right = child + 1 < end` and since finding the index of the biggest sibling can be done with an arithmetic operation we can remove a branch from the loop body. The case where there's no right child, i.e. `child == end - 1` is instead handled outside the loop, after it ends; note that if the loops ends early we can use `return` instead of `break` since the check `child == end - 1` will surely fail.

I've also removed a call to `<[T]>::swap` that was hiding a bound check that [wasn't being optimized by LLVM](https://godbolt.org/z/zrhdGM).

A quick benchmarks on my pc shows that the gains are pretty significant:

|name                 |before ns/iter  |after ns/iter  |diff ns/iter  |diff %    |speedup |
|---------------------|----------------|---------------|--------------|----------|--------|
|find_smallest_1000   | 352,565        | 260,098       |     -92,467  | -26.23%  | x 1.36 |
|from_vec             | 676,795        | 473,934       |    -202,861  | -29.97%  | x 1.43 |
|into_sorted_vec      | 469,511        | 304,275       |    -165,236  | -35.19%  | x 1.54 |
|pop                  | 483,198        | 373,778       |    -109,420  | -22.64%  | x 1.29 |

The other 2 benchmarks for `BinaryHeap` (`peek_mut_deref_mut` and `push`) weren't impacted and as such didn't show any significant change.
2020-11-12 19:46:11 +01:00
Alex Crichton
010265a439 Fix an intrinsic invocation on threaded wasm
This looks like it was forgotten to get updated in #74482 and wasm with
threads isn't built on CI so we didn't catch this by accident.
2020-11-12 07:23:00 -08:00
Stein Somers
8972bcb0dd BTreeMap: test chaotic ordering & other bits & bobs 2020-11-12 16:18:30 +01:00
Stein Somers
4cfa5bddf1 BTreeMap: avoid aliasing while handling underfull nodes 2020-11-12 10:09:59 +01:00
bors
55794e4396 Auto merge of #78965 - jryans:emscripten-threads-libc, r=kennytm
Update thread and futex APIs to work with Emscripten

This updates the thread and futex APIs in `std` to match the APIs exposed by
Emscripten. This allows threads to run on `wasm32-unknown-emscripten` and the
thread parker to compile without errors related to the missing `futex` module.

To make use of this, Rust code must be compiled with `-C target-feature=atomics`
and Emscripten must link with `-pthread`.

I have confirmed this works well locally when building multithreaded crates.
Attempting to enable `std` thread tests currently fails for seemingly obscure
reasons and Emscripten is currently disabled in CI, so further work is needed to
have proper test coverage here.
2020-11-12 05:52:17 +00:00
J. Ryan Stinnett
bf3be09ee8 Fix timeout conversion 2020-11-12 03:40:15 +00:00
J. Ryan Stinnett
951576051b Update thread and futex APIs to work with Emscripten
This updates the thread and futex APIs in `std` to match the APIs exposed by
Emscripten. This allows threads to run on `wasm32-unknown-emscripten` and the
thread parker to compile without errors related to the missing `futex` module.

To make use of this, Rust code must be compiled with `-C target-feature=atomics`
and Emscripten must link with `-pthread`.

I have confirmed this works well locally when building multithreaded crates.
Attempting to enable `std` thread tests currently fails for seemingly obscure
reasons and Emscripten is currently disabled in CI, so further work is needed to
have proper test coverage here.
2020-11-12 01:41:49 +00:00
Jonas Schievink
56e0806a1a
Rollup merge of #78417 - ssomers:btree_chop_up_2, r=Mark-Simulacrum
BTreeMap: split off most code of append

To complete #78056, move the last single-purpose pieces of code out of map.rs into a separate module. Also, tweaked documentation and safeness - I doubt think this code would be safe if the iterators passed in wouldn't be as sorted as the method says they should be - and bounds on MergeIterInner.

r? ```@Mark-Simulacrum```
2020-11-11 20:59:00 +01:00
Jonas Schievink
62f0a78056
Rollup merge of #78216 - workingjubilee:duration-zero, r=m-ou-se
Duration::zero() -> Duration::ZERO

In review for #72790, whether or not a constant or a function should be favored for `#![feature(duration_zero)]` was seen as an open question. In https://github.com/rust-lang/rust/issues/73544#issuecomment-691701670 an invitation was opened to either stabilize the methods or propose a switch to the constant value, supplemented with reasoning. Followup comments suggested community preference leans towards the const ZERO, which would be reason enough.

ZERO also "makes sense" beside existing associated consts for Duration. It is ever so slightly awkward to have a series of constants specifying 1 of various units but leave 0 as a method, especially when they are side-by-side in code. It seems unintuitive for the one non-dynamic value (that isn't from Default) to be not-a-const, which could hurt discoverability of the associated constants overall. Elsewhere in `std`, methods for obtaining a constant value were even deprecated, as seen with [std::u32::min_value](https://doc.rust-lang.org/std/primitive.u32.html#method.min_value).

Most importantly, ZERO costs less to use. A match supports a const pattern, but const fn can only be used if evaluated through a const context such as an inline `const { const_fn() }` or a `const NAME: T = const_fn()` declaration elsewhere. Likewise, while https://github.com/rust-lang/rust/issues/73544#issuecomment-691949373 notes `Duration::zero()` can optimize to a constant value, "can" is not "will". Only const contexts have a strong promise of such. Even without that in mind, the comment in question still leans in favor of the constant for simplicity. As it costs less for a developer to use, may cost less to optimize, and seems to have more of a community consensus for it, the associated const seems best.

r? ```@LukasKalbertodt```
2020-11-11 20:58:52 +01:00
Nicholas-Baron
261ca04c92 Changed unwrap_or to unwrap_or_else in some places.
The discussion seems to have resolved that this lint is a bit "noisy" in
that applying it in all places would result in a reduction in
readability.

A few of the trivial functions (like `Path::new`) are fine to leave
outside of closures.

The general rule seems to be that anything that is obviously an
allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it
is a 0-sized allocation.
2020-11-10 20:07:47 -08:00
Mara Bos
aff7bd66e8 Merge set_panic and set_print into set_output_capture.
There were no use cases for setting them separately.
Merging them simplifies some things.
2020-11-10 21:58:13 +01:00
Mara Bos
08b7cb79e0 Use Cell instead of RefCell for LOCAL_{STDOUT,STDERR}. 2020-11-10 21:58:13 +01:00
Mara Bos
f534b75f05 Use Vec<u8> for LOCAL_STD{OUT,ERR} instead of dyn Write.
It was only ever used with Vec<u8> anyway. This simplifies some things.

- It no longer needs to be flushed, because that's a no-op anyway for
  a Vec<u8>.

- Writing to a Vec<u8> never fails.

- No #[cfg(test)] code is needed anymore to use `realstd` instead of
  `std`, because Vec comes from alloc, not std (like Write).
2020-11-10 21:58:09 +01:00
Mara Bos
72e96604c0 Remove io::LocalOutput and use Arc<Mutex<dyn>> for local streams. 2020-11-10 21:57:05 +01:00
Jonas Schievink
42fae6bb65
Rollup merge of #78910 - tmiasko:intrinsics-link, r=jyn514
Fix links to stabilized versions of some intrinsics
2020-11-10 14:45:34 +01:00
Jonas Schievink
354098ccdd
Rollup merge of #78897 - hyd-dev:alloc-error-hook-newline, r=m-ou-se
Add missing newline to error message of the default OOM hook

Currently the default OOM hook in libstd does not end the error message with a newline:
```
memory allocation of 4 bytes failedtimeout: the monitored command dumped core
/playground/tools/entrypoint.sh: line 11:     7 Aborted                 timeout --signal=KILL ${timeout} "$`@"`
```
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=030d8223eb57dfe47ef157709aa26542

This is because the `fmt::Arguments` passed to `dumb_print()` does not end with a newline. All other calls to `dumb_print()` in libstd pass a `\n`-ended `fmt::Arguments` to `dumb_print()`. For example:
25f6938da4/library/std/src/sys_common/util.rs (L18)
I think the `\n` was forgotten in #51264.

This PR appends `\n` to the error string.

~~Note that I didn't add a test, because I didn't find tests for functions in ` library/std/src/alloc.rs` or a test that is similar to the test of this change would be.~~ *Edit: CI told me there is an existing test. Sorry.*
2020-11-10 14:45:28 +01:00
Jonas Schievink
87ecb0afac
Rollup merge of #78896 - cyqsimon:master, r=m-ou-se
Clarified description of write! macro

Reordered the list of arguments in the description to match that in the actual macro.

Suggested and discussed [here](https://discord.com/channels/442252698964721669/443492145567891458/774341262609219624).
2020-11-10 14:45:27 +01:00
Jonas Schievink
e15fee9fe4
Rollup merge of #78854 - the8472:workaround-normalization-regression-master, r=Mark-Simulacrum
Workaround for "could not fully normalize" ICE

Workaround for "could not fully normalize" ICE (#78139) by removing the `needs_drop::<T>()` calls triggering it.
Corresponding beta PR: #78845

Fixes #78139 -- the underlying bug is likely not fixed but we don't have another test case isolated for now, so closing.
2020-11-10 14:45:19 +01:00
Giacomo Stevanato
387568cd56 Added SAFETY comment as request 2020-11-09 22:34:31 +01:00
hyd-dev
70e175b551
Add missing newline to error message of the default OOM hook 2020-11-10 00:15:07 +08:00
cyqsimon
bf982a52f6 Bad grammar 2020-11-09 23:52:33 +08:00
cyqsimon
2633e93aa0 Clarified description of write! macro 2020-11-09 23:00:31 +08:00
Stein Somers
7ca6e8f767 BTreeMap: fix pointer provenance rules, make borrowing explicit 2020-11-09 09:13:50 +01:00
Dylan DPC
a8beaa3b3c
Rollup merge of #78878 - shepmaster:intersecting-ignores, r=Mark-Simulacrum
Avoid overlapping cfg attributes when both macOS and aarch64

r? ``@Mark-Simulacrum``
2020-11-09 01:13:48 +01:00
Dylan DPC
5639d9793f
Rollup merge of #78476 - RalfJung:btree-alias, r=Mark-Simulacrum
fix some incorrect aliasing in the BTree

This line is wrong:
```
ptr::copy(slice.as_ptr().add(idx), slice.as_mut_ptr().add(idx + 1), slice.len() - idx);
```
When `slice.as_mut_ptr()` is called, that creates a mutable reference to the entire slice, which invalidates the raw pointer previously returned by `slice.as_ptr()`. (Miri currently misses this because raw pointers are not tracked properly.)

Cc ````````@ssomers````````
2020-11-09 01:13:40 +01:00
Dylan DPC
4e5b7add7f
Rollup merge of #78437 - ssomers:btree_no_ord_at_node_level, r=Mark-Simulacrum
BTreeMap: stop mistaking node for an orderly place

A second mistake in #77612 was to ignore the node module's rightful comment "this module doesn't care whether the entries are sorted". And there's a much simpler way to visit the keys in order, if you check this separately from a single pass checking everything.

r? ````````@Mark-Simulacrum````````
2020-11-09 01:13:38 +01:00
Dylan DPC
41134be153
Rollup merge of #78026 - sunfishcode:symlink-hard-link, r=dtolnay
Define `fs::hard_link` to not follow symlinks.

POSIX leaves it [implementation-defined] whether `link` follows symlinks.
In practice, for example, on Linux it does not and on FreeBSD it does.
So, switch to `linkat`, so that we can pick a behavior rather than
depending on OS defaults.

Pick the option to not follow symlinks. This is somewhat arbitrary, but
seems the less surprising choice because hard linking is a very
low-level feature which requires the source and destination to be on
the same mounted filesystem, and following a symbolic link could end
up in a different mounted filesystem.

[implementation-defined]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html
2020-11-09 01:13:28 +01:00
Dylan DPC
d69ee57f97
Rollup merge of #77640 - ethanboxx:int_error_matching_attempt_2, r=KodrAus
Refactor IntErrorKind to avoid "underflow" terminology

This PR is a continuation of #76455

# Changes

- `Overflow` renamed to `PosOverflow` and `Underflow` renamed to `NegOverflow` after discussion in #76455
- Changed some of the parsing code to return `InvalidDigit` rather than `Empty` for strings "+" and "-". https://users.rust-lang.org/t/misleading-error-in-str-parse-for-int-types/49178
- Carry the problem `char` with the `InvalidDigit` variant.
- Necessary changes were made to the compiler as it depends on `int_error_matching`.
- Redid tests to match on specific errors.

r? ```@KodrAus```
2020-11-09 01:13:25 +01:00
Tomasz Miąsko
f1739575ef Fix links to stabilized versions of some intrinsics 2020-11-09 00:00:00 +00:00
Stein Somers
685fd53ada BTreeMap: split off most code of append, slightly improve interfaces 2020-11-08 18:58:46 +01:00
Jake Goulding
b13817a795 Avoid overlapping cfg attributes when both macOS and aarch64 2020-11-08 09:43:51 -05:00
Mara Bos
96975e515a
Rollup merge of #78852 - camelid:intra-doc-bonanza, r=jyn514
Convert a bunch of intra-doc links

An intra-doc link bonanza!

This was accomplished using a bunch of trial-and-error with sed.
2020-11-08 13:36:28 +01:00
Mara Bos
77f333b304
Rollup merge of #78811 - a1phyr:const_io_structs, r=dtolnay
Make some std::io functions `const`

Tracking issue: #78812

Make the following functions `const`:
- `io::Cursor::new`
- `io::Cursor::get_ref`
- `io::Cursor::position`
- `io::empty`
- `io::repeat`
- `io::sink`

r? `````@dtolnay`````
2020-11-08 13:36:19 +01:00
Mara Bos
3541280753
Rollup merge of #78788 - jhpratt:isize-impl-fix, r=m-ou-se
Correct unsigned equivalent of isize to be usize

See [#74913 (comment)](https://github.com/rust-lang/rust/issues/74913#issuecomment-722334456) for why this matters. Apparently it hasn't been used anywhere else, though CI will tell for sure.
2020-11-08 13:36:18 +01:00
Mara Bos
2967e58be3
Rollup merge of #78728 - a1phyr:const_cell_into_inner, r=dtolnay
Constantify `UnsafeCell::into_inner` and related

Tracking issue: #78729

This PR constantifies:
- `UnsafeCell::into_inner`
- `Cell::into_inner`
- `RefCell::into_inner`
- `Atomic*::into_inner`

r? `````@dtolnay`````
2020-11-08 13:36:14 +01:00
Mara Bos
eef9951e44
Rollup merge of #78572 - de-vri-es:bsd-cloexec, r=m-ou-se
Use SOCK_CLOEXEC and accept4() on more platforms.

This PR enables the use of `SOCK_CLOEXEC` and `accept4` on more platforms.

-----

Android uses the linux kernel, so it should also support it.

DragonflyBSD introduced them in 4.4 (December 2015):
https://www.dragonflybsd.org/release44/

FreeBSD introduced them in 10.0 (January 2014):
https://wiki.freebsd.org/AtomicCloseOnExec

Illumos introduced them in a commit in April 2013, not sure when it was released. It is quite possible that is has always been in Illumos:
5dbfd19ad5
https://illumos.org/man/3socket/socket
https://illumos.org/man/3socket/accept4

NetBSD introduced them in 6.0 (Oktober 2012) and 8.0 (July 2018):
https://man.netbsd.org/NetBSD-6.0/socket.2
https://man.netbsd.org/NetBSD-8.0/accept.2

OpenBSD introduced them in 5.7 (May 2015):
https://man.openbsd.org/socket https://man.openbsd.org/accept
2020-11-08 13:36:07 +01:00
Mara Bos
1c66688adc
Rollup merge of #78065 - tshepang:nits, r=dtolnay
make concurrency helper more pleasant to read
2020-11-08 13:36:01 +01:00
Mara Bos
bdeace9f4e
Rollup merge of #76227 - CDirkx:const-poll, r=KodrAus
Stabilize `Poll::is_ready` and `is_pending` as const

Insta-stabilize the methods `is_ready` and `is_pending` of `std::task::Poll` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198).

Possible because of the recent stabilization of const control flow.

Part of #76225.
2020-11-08 13:35:58 +01:00
Mara Bos
1f034f77bc
Rollup merge of #76097 - pickfire:stabilize-spin-loop, r=KodrAus
Stabilize hint::spin_loop

Partially fix #55002, deprecate in another release

r? ``````@KodrAus``````
2020-11-08 13:35:54 +01:00
Giacomo Stevanato
8d1575365d Remove useless bound checks from into_sorted_vec 2020-11-07 22:20:26 +01:00
Giacomo Stevanato
25b3f61c38 Remove useless branches from sift_down_range loop 2020-11-07 22:20:26 +01:00
Giacomo Stevanato
6dfcf9afde Remove branches from sift_down_to_bottom loop 2020-11-07 22:20:26 +01:00
Camelid
8258cf285f Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
The8472
8c7046e675 remove needs_drop 2020-11-07 21:40:55 +01:00
Christiaan Dirkx
6728240f36 Test structural matching for all range types
Adds structural match tests for all range types.

Note: also adds the otherwise unrelated test `test_range_to_inclusive` for completeness
2020-11-07 01:31:44 +01:00
Benoît du Garreau
001dd7e6a5 Add tracking issue 2020-11-06 18:04:52 +01:00
Benoît du Garreau
ae059b532f Make some std::io functions const
Includes:
- io::Cursor::new
- io::Cursor::get_ref
- io::Cursor::position
- io::empty
- io::repeat
- io::sink
2020-11-06 17:48:26 +01:00
Yuki Okushi
8f70cad032
Rollup merge of #78730 - kornelski:not-inverse, r=Dylan-DPC
Expand explanation of reverse_bits

Original documentation only rephrased the function name
2020-11-07 01:02:20 +09:00
Yuki Okushi
162f400328
Rollup merge of #78538 - ssomers:btree_testing_rng, r=Mark-Simulacrum
BTreeMap: document a curious assumption in test cases

r? ```@Mark-Simulacrum```
2020-11-07 01:02:09 +09:00
Yuki Okushi
0e71fc75cc
Rollup merge of #78006 - pitaj:master, r=jyn514
Use Intra-doc links for std::io::buffered

Helps with #75080. I used the implicit link style for intrinsics, as that was what `minnumf32` and others already had.

``@rustbot`` modify labels: T-doc, A-intra-doc-links

r? ``@jyn514``
2020-11-07 01:02:03 +09:00
Yuki Okushi
4136ed26a1
Rollup merge of #74979 - maekawatoshiki:fix, r=Mark-Simulacrum
`#![deny(unsafe_op_in_unsafe_fn)]` in sys/hermit

Partial fix of #73904.

This encloses ``unsafe`` operations in ``unsafe fn`` in ``sys/hermit``.
Some unsafe blocks are not well documented because some system-based functions lack documents.
2020-11-07 01:01:59 +09:00
Ivan Tham
e8b5be5dff Stabilize hint::spin_loop
Partially fix #55002, deprecate in another release

Co-authored-by: Ashley Mannix <kodraus@hey.com>

Update stable version for stabilize_spin_loop

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Use better example for spinlock

As suggested by KodrAus

Remove renamed_spin_loop already available in master

Fix spin loop example
2020-11-06 23:41:55 +08:00
Maarten de Vries
3bee37c290 Disable accept4 on Android. 2020-11-06 14:17:48 +01:00
bors
f92b931045 Auto merge of #77856 - GuillaumeGomez:automatic-links-lint, r=jyn514,ollie27
Add non_autolinks lint

Part of #77501.

r? `@jyn514`
2020-11-06 04:17:41 +00:00
Peter Jaszkowiak
8d48e3bbb2 document HACKs 2020-11-05 19:26:08 -07:00
Peter Jaszkowiak
fe6dfcd28a Intra-doc links for std::io::buffered 2020-11-05 19:09:42 -07:00