Commit graph

1432 commits

Author SHA1 Message Date
Ralf Jung
e4c1a3867f VecDeque: avoid more aliasing issues by working with raw pointers instead of references 2020-10-05 09:12:56 +02:00
Ralf Jung
f251dc446f VecDeque: fix incorrect &mut aliasing in IterMut::next/next_back 2020-10-05 09:12:54 +02:00
Dylan DPC
9dbc9ed870
Rollup merge of #77514 - scottmcm:less-once-chain-once, r=estebank
Replace some once(x).chain(once(y)) with [x, y] IntoIter

Now that we have by-value array iterators that are [already used](25c8c53dd9/compiler/rustc_hir/src/def.rs (L305-L307))...

For example,
```diff
-        once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
+        IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
```
2020-10-05 02:29:42 +02:00
Dylan DPC
23b1e3d772
Rollup merge of #77471 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BTreeMap: refactoring around edges, missed spots

Tweaks from #77244 (and more) that are really inconsistencies in #77005.

r? @Mark-Simulacrum
2020-10-05 02:29:38 +02:00
Dylan DPC
f1afed541e
Rollup merge of #77426 - tamird:sockaddr-scope-id, r=dtolnay
Include scope id in SocketAddrV6::Display

r? @tmandry

I couldn't find any unit tests for these functions.

cc @ghanan94 @brunowonka
2020-10-05 02:29:35 +02:00
Dylan DPC
fe087ece94
Rollup merge of #77395 - ssomers:btree_love_the_leaf_edge_comments, r=Mark-Simulacrum
BTreeMap: admit the existence of leaf edges in comments

The btree code is ambiguous about leaf edges (i.e., edges within leaf nodes). Iteration relies on them heavily, but some of the comments suggest there are no leaf edges (extracted from #77025)

r? @Mark-Simulacrum
2020-10-05 02:29:31 +02:00
Dylan DPC
583269d8c5
Rollup merge of #77219 - mightyiam:issue_77100, r=jyn514
core::global_allocator docs link to std::alloc::GlobalAlloc

Closes #77100
2020-10-05 02:29:29 +02:00
Dylan DPC
6c9e85726c
Rollup merge of #75853 - LeSeulArtichaut:core-intra-docs-3, r=jyn514
Use more intra-doc-links in `core::fmt`

This is a follow-up to #75819, which encountered some broken links due to #75176, so this PR contains the links that are blocked on #75176.

r? @jyn514
2020-10-05 02:29:23 +02:00
bors
beb5ae474d Auto merge of #77023 - HeroicKatora:len-missed-optimization, r=Mark-Simulacrum
Hint the maximum length permitted by invariant of slices

One of the safety invariants of references, and in particular of references to slices, is that they may not cover more than `isize::MAX` bytes. The unsafe `from_raw_parts` constructors of slices explicitly requires the caller to guarantee this fact. Violating it would also be UB with regards to the semantics of generated llvm code.

This effectively bounds the length of a (non-ZST) slice from above by a compile time constant. But when the length is loaded from a function argument it appears llvm is not aware of this requirement. The additional value range assertions allow some further elision of code branches, including overflow checks, especially in the presence of artithmetic on the indices.

This may have a performance impact, adding more code to a common method but allowing more optimization. I'm not quite sure, is the Rust side of const-prop strong enough to elide the irrelevant match branches?

Fixes: #67186
2020-10-04 21:08:06 +00:00
LeSeulArtichaut
17d3c0a178 Use more intra-doc-links in core::fmt 2020-10-04 22:33:22 +02:00
Andreas Molzer
e44784b875 Assume slice len is bounded by allocation size
Uses assume to check the length against a constant upper bound. The
inlined result then informs the optimizer of the sound value range.

This was tried with unreachable_unchecked before which introduces a
branch. This has the advantage of not being executed in sound code but
complicates basic blocks. It resulted in ~2% increased compile time in
some worst cases.

Add a codegen test for the assumption, testing the issue from #67186
2020-10-04 20:43:36 +02:00
bors
a835b483fe Auto merge of #77527 - jonas-schievink:rollup-szgq5he, r=jonas-schievink
Rollup of 8 pull requests

Successful merges:

 - #77072 (Minor `hash_map` doc adjustments + item attribute orderings)
 - #77368 (Backport LLVM apfloat commit to rustc_apfloat)
 - #77445 (BTreeMap: complete the compile-time test_variance test case)
 - #77504 (Support vectors with fewer than 8 elements for simd_select_bitmask)
 - #77513 (Change DocFragments from enum variant fields to structs with a nested enum)
 - #77518 (Only use Fira Sans for the first `td` in item lists)
 - #77521 (Move target feature whitelist from cg_llvm to cg_ssa)
 - #77525 (Enable RenameReturnPlace MIR optimization on mir-opt-level >= 2)

Failed merges:

r? `@ghost`
2020-10-04 13:49:36 +00:00
Jonas Schievink
80953177ed
Rollup merge of #77445 - ssomers:btree_cleanup_7, r=Mark-Simulacrum
BTreeMap: complete the compile-time test_variance test case

Some of the items added to the new `test_sync` belonged in the old `test_variance` as well. And fixed inconsistent paths to nearby modules.
r? @Mark-Simulacrum
2020-10-04 15:45:41 +02:00
Jonas Schievink
4ae7710e1d
Rollup merge of #77072 - sharnoff:hash-docs, r=LukasKalbertodt
Minor `hash_map` doc adjustments + item attribute orderings

This PR is really a couple visual changes glued together:
1. Some of the doc comments for items in `std::collections::hash_map` referenced the names of types without escaping their formatting (e.g. using "VacantEntry" instead of "`VacantEntry`") - the ones I could find were changed to the latter
2. The vast majority of pre-item attributes seem to place doc comments as the first attribute (instead of things like `#[feature(...)]`), so the few that had the other order were changed.
3. Also ordering related: the general trend seems to be that `#[feature]` attributes follow `#[inline]`, so I swapped the two lines in places where that ordering was reversed. This is primarily a change based on stylistic continuity and aesthetics - I'm not sure how important that actually is / should be.

I figured this would be pretty uncontroversial, but some of these might have been intentional for reasons I don't know about - if so, I'd be happy to remove the relevant changes. Of these, the final set of changes is probably the most unnecessary, so it also might be better to leave those out (in favor of reducing code churn).
2020-10-04 15:45:33 +02:00
Tamir Duberstein
4585c22818
Include scope id in SocketAddrV6::Display 2020-10-04 12:18:12 +00:00
bors
0644cc1242 Auto merge of #76610 - hch12907:master, r=LukasKalbertodt
Implement as_ne_bytes() for integers and floats

This is related to issue #64464.

I am pretty sure that these functions are actually const-ify-able, and technically as_bits() can also be implemented for floats, but I might need some comments on both.
2020-10-04 11:48:50 +00:00
bors
0d37dca25a Auto merge of #76448 - haraldh:default_alloc_error_handler_reduced, r=Amanieu
Implement Make `handle_alloc_error` default to panic (for no_std + liballoc)

Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.
2020-10-04 08:56:05 +00:00
bors
32cbc65e6b Auto merge of #77380 - fusion-engineering-forks:unbox-the-mutex, r=dtolnay
Unbox mutexes and condvars on some platforms

Both mutexes and condition variables contained a Box containing the actual os-specific object. This was done because moving these objects may cause undefined behaviour on some platforms.

However, this is not needed on Windows[1], Wasm[2], cloudabi[2], and 'unsupported'[3], were the box was only needlessly making them less efficient.

This change gets rid of the box on those platforms.

On those platforms, `Condvar` can no longer verify it is only used with one `Mutex`, as mutexes no longer have a stable address. This was addressed and considered acceptable in #76932.

[1]\: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initializesrwlock
[2]\: These are just a single atomic integer together with futex wait/wake calls/instructions.
[3]\: The `unsupported` platform doesn't support multiple threads at all.
2020-10-04 06:48:17 +00:00
bors
2251766944 Auto merge of #77517 - JohnTitor:rollup-msbd49e, r=JohnTitor
Rollup of 11 pull requests

Successful merges:

 - #75143 (Use `tracing` spans to trace the entire MIR interp stack)
 - #75699 (Uplift drop-bounds lint from clippy)
 - #76768 (Test and reject out-of-bounds shuffle vectors)
 - #77190 (updated p! macro to accept literals)
 - #77388 (Add some regression tests)
 - #77419 (Create E0777 error code for invalid argument in derive)
 - #77447 (BTreeMap: document DrainFilterInner better)
 - #77468 (Fix test name)
 - #77469 (Improve rustdoc error for failed intra-doc link resolution)
 - #77473 (Make --all-targets in x.py check opt-in)
 - #77508 (Fix capitalization in blog post name)

Failed merges:

r? `@ghost`
2020-10-04 04:33:28 +00:00
Yuki Okushi
25d0650d0f
Rollup merge of #77447 - ssomers:btree_cleanup_8, r=Mark-Simulacrum
BTreeMap: document DrainFilterInner better

r? @Mark-Simulacrum
2020-10-04 11:45:04 +09:00
Yuki Okushi
b654555a32
Rollup merge of #75699 - notriddle:drop-bounds-lint, r=petrochenkov
Uplift drop-bounds lint from clippy

Bounds on `T: Drop` do nothing, so they should warn.
2020-10-04 11:44:55 +09:00
bors
4cf3dc19a1 Auto merge of #76017 - JulianKnodt:fmt_fast, r=nagisa
Use less divisions in display u128/i128

This PR is an absolute mess, and I need to test if it improves the speed of fmt::Display for u128/i128, but I think it's correct.
It hopefully is more efficient by cutting u128 into at most 2 u64s, and also chunks by 1e16 instead of just 1e4.

Also I specialized the implementations for uints to always be non-false because it bothered me that it was checked at all

Do not merge until I benchmark it and also clean up the god awful mess of spaghetti.
Based on prior work in #44583

cc: `@Dylan-DPC`

Due to work on `itoa` and suggestion in original issue:
r? `@dtolnay`
2020-10-04 02:24:20 +00:00
Scott McMurray
d74b8e0505 Replace some once(x).chain(once(y)) with [x, y] IntoIter
Now that we have by-value array iterators...
2020-10-03 16:51:43 -07:00
Stein Somers
a58089e097 BTreeMap/Set: complete the compile-time test cases 2020-10-04 01:04:29 +02:00
bors
738d4a7a36 Auto merge of #74160 - CAD97:weak-as-unsized-ptr, r=RalfJung
Allow Weak::as_ptr and friends for unsized T

Relaxes `impl<T> Weak<T>` to `impl<T: ?Sized> Weak<T>` for the methods `rc::Weak::as_ptr`, `into_raw`, and `from_raw`.

Follow-up to #73845, which did most of the impl work to make these functions work for `T: ?Sized`.

We still have to adjust the implementation of `Weak::from_raw` here, however, because I missed a use of `ptr.is_null()` previously. This check was necessary when `into`/`from_raw` were first implemented, as `into_raw` returned `ptr::null()` for dangling weak. However, we now just (wrapping) offset dangling weaks' pointers the same as nondangling weak, so the null check is no longer necessary (or even hit). (I can submit just 17a928f as a separate PR if desired.)

As a nice side effect, moves the `fn is_dangling` definition closer to `Weak::new`, which creates the dangling weak.

This technically stabilizes that "something like `align_of_val_raw`" is possible to do. However, I believe the part of the functionality required by these methods here -- specifically, getting the alignment of a pointee from a pointer where it may be dangling iff the pointee is `Sized` -- is uncontroversial enough to stabilize these methods without a way to implement them on stable Rust.

r? `@RalfJung,` who reviewed #73845.

ATTN: This changes (relaxes) the (input) generic bounds on stable fn!
2020-10-03 14:18:26 +00:00
Ralf Jung
e27ef130c1
grammar nit 2020-10-03 12:15:26 +02:00
bors
6f56fbdc1c Auto merge of #77347 - jyn514:dox, r=Amanieu
Remove --cfg dox from rustdoc.rs

This was added in https://github.com/rust-lang/rust/pull/53076 because
several dependencies were using `cfg(dox)` instead of `cfg(rustdoc)` (now `cfg(doc)`).
I ran `rg 'cfg\(dox\)'` on the source tree with no matches, so I think
this is now safe to remove.

r? `@Mark-Simulacrum`
cc `@QuietMisdreavus` :)
2020-10-03 07:23:02 +00:00
Stein Somers
d71d13e82d BTreeMap: refactoring around edges, missed spots 2020-10-03 01:06:55 +02:00
Jonas Schievink
01ca8299d4
Rollup merge of #77264 - fusion-engineering-forks:skip-local-stdio, r=dtolnay
Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used.

The thread local `LOCAL_STDOUT` and `LOCAL_STDERR` are only used by the `test` crate to capture output from tests when running them in the same process in differen threads. However, every program will check these variables on every print, even outside of testing.

This involves allocating a thread local key, and registering a thread local destructor. This can be somewhat expensive.

This change keeps a global flag (`LOCAL_STREAMS`) which will be set to `true` when either of these local streams is used. (So, effectively only in test and benchmark runs.) When this flag is off, these thread locals are not even looked at and therefore will not be initialized on the first output on every thread, which also means no thread local destructors will be registered.

---

Together with https://github.com/rust-lang/rust/pull/77154, this should make output a little bit more efficient.
2020-10-03 00:31:14 +02:00
Jonas Schievink
ccc020ab42
Rollup merge of #77182 - GuillaumeGomez:missing-examples-fd-traits, r=pickfire
Add missing examples for Fd traits

Not sure what happened here... This is a reopening of #77142

r? @Dylan-DPC
2020-10-03 00:31:10 +02:00
Jonas Schievink
389f7cf7d6
Rollup merge of #76745 - workingjubilee:move-wrapping-tests, r=matklad
Move Wrapping<T> ui tests into library

Part of #76268
r? @matklad
2020-10-03 00:31:08 +02:00
Jonas Schievink
1118ab9930
Rollup merge of #75377 - canova:map_debug_impl, r=dtolnay
Fix Debug implementations of some of the HashMap and BTreeMap iterator types

HashMap's `ValuesMut`, BTreeMaps `ValuesMut`, IntoValues and `IntoKeys` structs were printing both keys and values on their Debug implementations. But they are iterators over either keys or values. Irrelevant values should not be visible. With this PR, they only show relevant fields.
This fixes #75297.

[Here's an example code.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0c79356ed860e347a0c1a205616f93b7) This prints this on nightly:
```
ValuesMut { inner: IterMut { range: [(1, "hello"), (2, "goodbye")], length: 2 } }
IntoKeys { inner: [(1, "hello"), (2, "goodbye")] }
IntoValues { inner: [(1, "hello"), (2, "goodbye")] }
[(2, "goodbye"), (1, "hello")]
```

After the patch this example prints these instead:
```
["hello", "goodbye"]
["hello", "goodbye"]
[1, 2]
["hello", "goodbye"]
```

I didn't add test cases for them, since I couldn't see any tests for Debug implementations anywhere. But please let me know if I should add it to a specific place.

r? @dtolnay
2020-10-03 00:31:04 +02:00
Jubilee Young
4e973966b9 Remove unnecessary mod-cfg 2020-10-02 11:40:57 -07:00
Jonas Schievink
14d8ee3465
Rollup merge of #77442 - pickfire:patch-7, r=scottmcm
Clean up on example doc fixes for ptr::copy

Follow up of #77385

r? @scottmcm
2020-10-02 20:27:14 +02:00
Jonas Schievink
72d275d844
Rollup merge of #77432 - tmiasko:posix-spawn-musl, r=cuviper
Use posix_spawn on musl targets

The posix_spawn had been available in a form suitable for use in a
Command implementation since musl 0.9.12. Use it in a preference to a
fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-10-02 20:27:11 +02:00
Jonas Schievink
18ac26d1c5
Rollup merge of #77409 - pickfire:patch-6, r=GuillaumeGomez
Add example for iter chain struct

r? @GuillaumeGomez
2020-10-02 20:27:06 +02:00
Jonas Schievink
2a09c184c0
Rollup merge of #77405 - timvermeulen:iter_advance_by_tracking_issue, r=scottmcm
Add tracking issue of iter_advance_by feature
2020-10-02 20:27:04 +02:00
Guillaume Gomez
d6b838b93a Simplify fd examples 2020-10-02 16:38:15 +02:00
Stein Somers
90c8b43bc3 BTreeMap: document DrainFilterInner better 2020-10-02 13:13:28 +02:00
bors
154f1f544d Auto merge of #77029 - ehuss:command-access, r=dtolnay
Add accessors to Command.

This adds some accessor methods to `Command` to provide a way to access the values set when building the `Command`. An example where this can be useful is to display the command to be executed. This is roughly based on the [`ProcessBuilder`](13b73cdaf7/src/cargo/util/process_builder.rs (L105-L134)) in Cargo.

Possible concerns about the API:
- Values with NULs on Unix will be returned as `"<string-with-nul>"`. I don't think it is practical to avoid this, since otherwise a whole separate copy of all the values would need to be kept in `Command`.
- Does not handle `arg0` on Unix. This can be awkward to support in `get_args` and is rarely used. I figure if someone really wants it, it can be added to `CommandExt` as a separate method.
- Does not offer a way to detect `env_clear`. I'm uncertain if it would be useful for anyone.
- Does not offer a way to get an environment variable by name (`get_env`). I figure this can be added later if anyone really wants it. I think the motivation for this is weak, though. Also, the API could be a little awkward (return a `Option<Option<&OsStr>>`?).
- `get_envs` could skip "cleared" entries and just return `&OsStr` values instead of `Option<&OsStr>`. I'm on the fence here. My use case is to display a shell command, and I only intend it to be roughly equivalent to the actual execution, and I probably won't display `None` entries. I erred on the side of providing extra information, but I suspect many situations will just filter out the `None`s.
- Could implement more iterator stuff (like `DoubleEndedIterator`).

I have not implemented new std items before, so I'm uncertain if the existing issue should be reused, or if a new tracking issue is needed.

cc #44434
2020-10-02 07:51:24 +00:00
Mara Bos
b1ce7a38a6 Disable condvar::two_mutexes test on non-unix platforms.
Condvars are no longer guaranteed to panic in this case on all
platforms. At least the unix implementation still does.
2020-10-02 09:47:08 +02:00
Mara Bos
f3837e788b No longer put windows condvars in a box.
Windows condition variables are movable (while not borrowed) according
to their documentation.
2020-10-02 09:47:08 +02:00
Mara Bos
ec69a858e4 No longer put wasm condvars in a box.
These condvars are just an AtomicUsize, so can be moved without
problems.
2020-10-02 09:47:08 +02:00
Mara Bos
7f56a35411 No longer put condvars on the 'unsupported' platform in a box.
These condvars are unsupported and implemented as a ZST, so can be moved
without problems.
2020-10-02 09:47:08 +02:00
Mara Bos
5769a46788 No longer put cloudabi condvars in a box.
Cloudabi condvars may be moved safely.
2020-10-02 09:47:08 +02:00
Mara Bos
b181f5a923 Make it possible to have unboxed condvars on specific platforms.
This commit keeps all condvars boxed on all platforms, but makes it
trivial to remove the box on some platforms later.
2020-10-02 09:47:08 +02:00
Mara Bos
dc81cbdcb1 No longer put windows mutexes in a box.
Windows SRW locks are movable (while not borrowed) according to their
documentation.
2020-10-02 09:47:08 +02:00
Mara Bos
4f1353e54f No longer put wasm mutexes in a box.
These mutexes are just an AtomicUsize, so can be moved without
problems.
2020-10-02 09:47:08 +02:00
Mara Bos
2f0386771d No longer put mutexes on the 'unsupported' platform in a box.
These mutexes are just a bool (in a cell), so can be moved without
problems.
2020-10-02 09:47:08 +02:00
Mara Bos
def5188ca8 No longer put cloudabi mutexes in a box.
Cloudabi mutexes may be moved safely.
2020-10-02 09:47:08 +02:00