Commit graph

1017 commits

Author SHA1 Message Date
bors
70c5f6efc4 Auto merge of #75200 - ssomers:btree_valmut, r=Mark-Simulacrum
BTreeMap: introduce marker::ValMut and reserve Mut for unique access

The mutable BTreeMap iterators (apart from `DrainFilter`) are double-ended, meaning they have to rely on a front and a back handle that each represent a reference into the tree. Reserve a type category `marker::ValMut` for them, so that we guarantee that they cannot reach operations on handles with borrow type `marker::Mut`and that these operations can assume unique access to the tree.

Including #75195, benchmarks report no genuine change:
```
benchcmp old new --threshold 5
 name                                 old ns/iter  new ns/iter  diff ns/iter   diff %  speedup
 btree::map::iter_100                 3,333        3,023                -310   -9.30%   x 1.10
 btree::map::range_unbounded_vs_iter  36,624       31,569             -5,055  -13.80%   x 1.16
```

r? @Mark-Simulacrum
2020-09-04 23:16:23 +00:00
Chris Gillespie
5456414d91 Fix nlink example typo 2020-09-04 14:41:27 -07:00
Camelid
85b11d50b2
Improve docs for std::env::args() 2020-09-04 14:00:09 -07:00
bors
c59199efca Auto merge of #76292 - Aaron1011:fix/proc-macro-panic-hide, r=petrochenkov
Respect `-Z proc-macro-backtrace` flag for panics inside libproc_macro

Fixes #76270

Previously, any panic occuring during a call to a libproc_macro method
(e.g. calling `Ident::new` with an invalid identifier) would always
cause an ICE message to be printed.
2020-09-04 20:58:37 +00:00
Andy Russell
2ed1a21790
add some intra-doc links to Iterator 2020-09-04 15:51:58 -04:00
Mateusz Mikuła
1ea121c74f Fix warning whe building profiler_builtins crate 2020-09-04 15:10:29 +02:00
bors
ef55a0a92f Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAus
Add `slice::check_range`

This method is useful for [`RangeBounds`] parameters. It's even been [rewritten](22ee68dc58/src/librustc_data_structures/sorted_map.rs (L214)) [many](22ee68dc58/library/alloc/src/vec.rs (L1299)) [times](22ee68dc58/library/core/src/slice/mod.rs (L2441)) in the standard library, sometimes assuming that the bounds won't be [`usize::MAX`].

For example, [`Vec::drain`] creates an empty iterator when [`usize::MAX`] is used as an inclusive end bound:

```rust
assert!(vec![1].drain(..=usize::max_value()).eq(iter::empty()));
```

If this PR is merged, I'll create another to use it for those methods.

[`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html
[`usize::MAX`]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.MAX
[`Vec::drain`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
2020-09-04 12:21:43 +00:00
Ayush Kumar Mishra
d16bbd1cb0 Move Vec slice UI tests in library 2020-09-04 17:18:26 +05:30
Scott McMurray
fac272688e Use ops::ControlFlow in graph::iterate 2020-09-04 01:45:10 -07:00
numbermaniac
8f11127d89
time.rs: Make spelling of "Darwin" consistent 2020-09-04 14:21:52 +10:00
Lzu Tao
a3ee65f87e Remove a useless allowed attr 2020-09-04 02:42:50 +00:00
Ivan Tham
85146b9db7
Add slice primitive link to vec 2020-09-04 09:50:50 +08:00
Christiaan Dirkx
538e198193 Move various ui const tests to library
Move:
 - `src\test\ui\consts\const-nonzero.rs` to `library\core`
 - `src\test\ui\consts\ascii.rs` to `library\core`
 - `src\test\ui\consts\cow-is-borrowed` to `library\alloc`

Part of #76268
2020-09-04 02:35:27 +02:00
Tomasz Miąsko
f8cfb2f5ad Add tests for overflow in String / VecDeque operations using ranges 2020-09-04 00:00:00 +00:00
Tomasz Miąsko
d98bac4e4e Add tests for overflow in Vec::drain 2020-09-04 23:16:53 +02:00
Christiaan Dirkx
79d563c819 Move const tests for Ordering to library\core
Part of #76268
2020-09-04 00:40:11 +02:00
Joshua Nelson
7b823df489 Link to #capacity-and-reallocation when using with_capacity 2020-09-03 18:08:25 -04:00
Joshua Nelson
8c93125c17 Address review comments on Peekable::next_if 2020-09-03 18:03:33 -04:00
bors
0d0f6b1130 Auto merge of #70793 - the8472:in-place-iter-collect, r=Amanieu
specialize some collection and iterator operations to run in-place

This is a rebase and update of #66383 which was closed due inactivity.

Recent rustc changes made the compile time regressions disappear, at least for webrender-wrench. Running a stage2 compile and the rustc-perf suite takes hours on the hardware I have at the moment, so I can't do much more than that.

![Screenshot_2020-04-05 rustc performance data](https://user-images.githubusercontent.com/1065730/78462657-5d60f100-76d4-11ea-8a0b-4f3962707c38.png)

In the best case of the `vec::bench_in_place_recycle` synthetic microbenchmark these optimizations can provide a 15x speedup over the regular implementation which allocates a new vec for every benchmark iteration. [Benchmark results](https://gist.github.com/the8472/6d999b2d08a2bedf3b93f12112f96e2f). In real code the speedups are tiny, but it also depends on the allocator used, a system allocator that uses a process-wide mutex will benefit more than one with thread-local pools.

## What was changed

* `SpecExtend` which covered `from_iter` and `extend` specializations was split into separate traits
* `extend` and `from_iter` now reuse the `append_elements` if passed iterators are from slices.
* A preexisting `vec.into_iter().collect::<Vec<_>>()` optimization that passed through the original vec has been generalized further to also cover cases where the original has been partially drained.
* A chain of *Vec<T> / BinaryHeap<T> / Box<[T]>* `IntoIter`s  through various iterator adapters collected into *Vec<U>* and *BinaryHeap<U>* will be performed in place as long as `T` and `U` have the same alignment and size and aren't ZSTs.
* To enable above specialization the unsafe, unstable `SourceIter` and `InPlaceIterable` traits have been added. The first allows reaching through the iterator pipeline to grab a pointer to the source memory. The latter is a marker that promises that the read pointer will advance as fast or faster than the write pointer and thus in-place operation is possible in the first place.
* `vec::IntoIter` implements `TrustedRandomAccess` for `T: Copy` to allow in-place collection when there is a `Zip` adapter in the iterator. TRA had to be made an unstable public trait to support this.

## In-place collectible adapters

* `Map`
* `MapWhile`
* `Filter`
* `FilterMap`
* `Fuse`
* `Skip`
* `SkipWhile`
* `Take`
* `TakeWhile`
* `Enumerate`
* `Zip` (left hand side only, `Copy` types only)
* `Peek`
* `Scan`
* `Inspect`

## Concerns

`vec.into_iter().filter(|_| false).collect()` will no longer return a vec with 0 capacity, instead it will return its original allocation. This avoids the cost of doing any allocation or deallocation but could lead to large allocations living longer than expected.
If that's not acceptable some resizing policy at the end of the attempted in-place collect would be necessary, which in the worst case could result in one more memcopy than the non-specialized case.

## Possible followup work

* split liballoc/vec.rs to remove `ignore-tidy-filelength`
* try to get trivial chains such as `vec.into_iter().skip(1).collect::<Vec<)>>()` to compile to a `memmove` (currently compiles to a pile of SIMD, see #69187 )
* improve up the traits so they can be reused by other crates, e.g. itertools. I think currently they're only good enough for internal use
* allow iterators sourced from a `HashSet` to be in-place collected into a `Vec`
2020-09-03 21:20:21 +00:00
Christiaan Dirkx
a2e077e405 Make Ipv4Addr and Ipv6Addr const tests unit tests under library
These tests are about the standard library, not the compiler itself, thus should live in `library`, see #76268.
2020-09-03 23:17:21 +02:00
The8472
2f23a0fcca fix debug assertion
The InPlaceIterable debug assert checks that the write pointer
did not advance beyond the read pointer. But TrustedRandomAccess
never advances the read pointer, thus triggering the assert.
Skip the assert if the source pointer did not change during iteration.
2020-09-03 22:15:47 +02:00
Rune Tynan
2278c7255a
Remove vec-to_str.rs, merge the remaining test in with vec 2020-09-03 15:43:07 -04:00
bors
62dad457bc Auto merge of #73819 - euclio:rustdoc-summaries, r=jyn514,GuillaumeGomez
rustdoc: do not use plain summary for trait impls

Fixes #38386.
Fixes #48332.
Fixes #49430.
Fixes #62741.
Fixes #73474.

Unfortunately this is not quite ready to go because the newly-working links trigger a bunch of linkcheck failures. The failures are tough to fix because the links are resolved relative to the implementor, which could be anywhere in the module hierarchy.

(In the current docs, these links end up rendering as uninterpreted markdown syntax, so I don't think these failures are any worse than the status quo. It might be acceptable to just add them to the linkchecker whitelist.)

Ideally this could be fixed with intra-doc links ~~but it isn't working for me: I am currently investigating if it's possible to solve it this way.~~ Opened #73829.

EDIT: This is now ready!
2020-09-03 19:07:38 +00:00
The8472
8e5fe5569b improve comments and naming 2020-09-03 20:59:37 +02:00
The8472
6464586542 add explanation to specialization marker 2020-09-03 20:59:36 +02:00
The8472
acdd441cc3 remove separate no-drop code path since it resulted in more LLVM IR 2020-09-03 20:59:36 +02:00
The8472
435219dd82 remove empty Vec extend optimization
The optimization meant that every extend code path had to emit llvm
IR for from_iter and extend spec_extend, which likely impacts
compile times while only improving a few edge-cases
2020-09-03 20:59:35 +02:00
The8472
7492f76f77 please tidy 2020-09-03 20:59:34 +02:00
The8472
9aeea00222 get things to work under min_specialization by leaning more heavily on #[rustc_unsafe_specialization_marker] 2020-09-03 20:59:34 +02:00
The8472
a62cd1b44c fix benchmark compile errors 2020-09-03 20:59:33 +02:00
The8472
bec9f9223c apply required min_specialization attributes 2020-09-03 20:59:32 +02:00
The8472
80638330f2 support in-place collect for MapWhile adapters 2020-09-03 20:59:32 +02:00
The8472
55d1296a55 pacify tidy 2020-09-03 20:59:31 +02:00
The8472
5530858a08 generalize in-place collect to types of same size and alignment 2020-09-03 20:59:31 +02:00
The8472
fa34b39cd6 increase comment verbosity 2020-09-03 20:59:30 +02:00
The8472
872ab780c0 work around compiler overhead around lambdas in generics by extracting them into free functions 2020-09-03 20:59:29 +02:00
The8472
771b8ecc83 extract IntoIter drop/forget used by specialization into separate methods 2020-09-03 20:59:29 +02:00
The8472
6ad133443a add benchmark to cover in-place extend 2020-09-03 20:59:28 +02:00
The8472
a7a8b52e91 remove redundant cast 2020-09-03 20:59:28 +02:00
The8472
470bf54f94 test drops during in-place iteration 2020-09-03 20:59:27 +02:00
The8472
fe350dd82d move unsafety into method, not relevant to caller 2020-09-03 20:59:27 +02:00
The8472
0d2d033415 replace unsafe ptr::write with deref-write, benchmarks show no difference 2020-09-03 20:59:26 +02:00
The8472
9596e5a2f2 pacify tidy 2020-09-03 20:59:26 +02:00
The8472
6ed05fd995 replace drop flag with ManuallyDrop 2020-09-03 20:59:25 +02:00
The8472
ab382b7661 mark as_inner as unsafe and update comments 2020-09-03 20:59:24 +02:00
The8472
2a51e579f5 avoid exposing that binary heap's IntoIter is backed by vec::IntoIter, use a private trait instead 2020-09-03 20:59:24 +02:00
The8472
c731648e77 fix: bench didn't black_box its results 2020-09-03 20:59:23 +02:00
The8472
0856771248 fix build issue due to stabilized feature 2020-09-03 20:59:23 +02:00
The8472
e85cfa4f22 impl TrustedRandomAccess for vec::IntoIter 2020-09-03 20:59:22 +02:00
The8472
e1151844fa bench larger allocations 2020-09-03 20:59:22 +02:00
The8472
fd16202e36 include in-place .zip() in test 2020-09-03 20:59:21 +02:00
The8472
fbb3371e5b remove unecessary feature flag
# Conflicts:
#	library/alloc/src/lib.rs
2020-09-03 20:59:21 +02:00
The8472
70293c658f make tidy happy 2020-09-03 20:59:20 +02:00
The8472
21a17d105c support in-place iteration for most adapters
`Take` is not included since users probably call it with small constants
and it doesn't make sense to hold onto huge allocations in that case
2020-09-03 20:59:20 +02:00
The8472
085eb20a61 move free-standing method into trait impl 2020-09-03 20:59:19 +02:00
The8472
0f122e1119 add in-place iteration for Zip
this picks the left hand side as source since it might be more natural to
consume that as IntoIter source
2020-09-03 20:59:19 +02:00
The8472
3d5e9f1904 bench in-place zip 2020-09-03 20:59:18 +02:00
The8472
2b0b2ae9f6 additional specializations tests 2020-09-03 20:59:17 +02:00
The8472
00a32eb54f fix some in-place-collect edge-cases
- it's an allocation optimization, so don't attempt to do it on ZSTs
- drop the tail of partially exhausted iters
2020-09-03 20:59:17 +02:00
The8472
8c816b96dd remove redundant code 2020-09-03 20:59:16 +02:00
The8472
cc67c8eb91 improve comments 2020-09-03 20:59:16 +02:00
The8472
290fe895ba specialize creating a Vec from a slice iterator where T: Copy
this was already implemented for Extend but not for FromIterator
2020-09-03 20:59:15 +02:00
The8472
dac0edfaaa restore SpecFrom<T, TrustedLen<Item=T>> specialization by nesting
specializations
2020-09-03 20:59:15 +02:00
The8472
582fbb1d62 use From specializations on extend if extended Vec is empty
this enables in-place iteration and allocation reuse in additional cases
2020-09-03 20:59:14 +02:00
The8472
a596ff36b5 exercise more of the in-place pipeline in the bench 2020-09-03 20:59:14 +02:00
The8472
a9c78e371e bench in-place collect of droppables 2020-09-03 20:59:13 +02:00
The8472
8ac96e6a98 cyclic in-place reuse bench 2020-09-03 20:59:13 +02:00
The8472
bb4f888a59 return the things under test so they get black_box()'ed 2020-09-03 20:59:12 +02:00
The8472
2f700d085a add benches from bluss' gists 2020-09-03 20:59:12 +02:00
The8472
a4e385a0d0 use memmove instead of generic in-place iteration for IntoIter source
this is the original SpecExtend<_, IntoIter> logic except generalizing
the fast-path to include a memmove
2020-09-03 20:59:11 +02:00
The8472
631543dcb4 restore Vec::extend specialization for vec::IntoIter sources that
was lost during refactoring
2020-09-03 20:59:11 +02:00
The8472
07a8c1b95a hide binary_heap::IntoIter internals behind impl Trait 2020-09-03 20:59:10 +02:00
The8472
b90816deb7 remove example that relied on non-public trait 2020-09-03 20:59:10 +02:00
The8472
232065074d recover vectorization
switch to try_fold and segregate the drop handling to keep
collect::<Vec<u8>>() and similar optimizer-friendly

It comes at the cost of less accurate debug_asserts and code complexity
2020-09-03 20:59:09 +02:00
The8472
6c5c47b82b update benches 2020-09-03 20:59:09 +02:00
The8472
bead910b21 simplify pointer arithmetic 2020-09-03 20:59:08 +02:00
The8472
f904d0339a fix doc link 2020-09-03 20:59:07 +02:00
The8472
328a75f766 use add instead of offset 2020-09-03 20:59:07 +02:00
The8472
88b7ae642c implement drop handling 2020-09-03 20:59:06 +02:00
The8472
73a982e9ec assert that SourceIter requirements have not been violated by the pipeline 2020-09-03 20:59:06 +02:00
The8472
2a327394e4 mark SourceIter as unsafe, document invariants 2020-09-03 20:59:05 +02:00
The8472
bb2d533bb9 in-place collect for Vec. Box<[]> and BinaryHeap IntoIter and some adapters 2020-09-03 20:59:03 +02:00
The8472
038394a330 bench 2020-09-03 20:56:34 +02:00
The8472
076417e978 unrelated typo fix 2020-09-03 20:56:34 +02:00
Aaron Hill
53cce257ae
Respect -Z proc-macro-backtrace flag for panics inside libproc_macro
Fixes #76270

Previously, any panic occuring during a call to a libproc_macro method
(e.g. calling `Ident::new` with an invalid identifier) would always
cause an ICE message to be printed.
2020-09-03 12:13:26 -04:00
Ivan Tham
4df64905ea
Link & primitive using relative link 2020-09-03 23:02:27 +08:00
Jethro Beekman
0b5e681f5a Improve SGX RWLock initializer test 2020-09-03 10:29:49 +02:00
bors
08deb863bd Auto merge of #76235 - jyn514:std-intra-links, r=poliorcetics
Convert many files to intra-doc links

Helps with https://github.com/rust-lang/rust/issues/75080
r? @poliorcetics
I recommend reviewing one commit at a time, but the diff is small enough you can do it all at once if you like :)
2020-09-03 05:53:48 +00:00
Rune Tynan
3e29fdb0fb
Remove a number of vec UI tests, make them unit tests in the alloc library 2020-09-03 01:40:15 -04:00
bors
1e33c742ca Auto merge of #75971 - Amjad50:libstd-deny-unsafe_op_in_unsafe_fn, r=Mark-Simulacrum
Applied `#![deny(unsafe_op_in_unsafe_fn)]` in library/std/src/wasi

partial fix for #73904

There are still more that was not applied in [mod.rs]( 38fab2ea92/library/std/src/sys/wasi/mod.rs) and that is due to its using files from `../unsupported`

like:
```
#[path = "../unsupported/cmath.rs"]
pub mod cmath;
```
2020-09-03 02:15:16 +00:00
Amjad Alsharafi
559679b8c3 Applied #![deny(unsafe_op_in_unsafe_fn)] in library/std/src/wasi
All refactoring needed was only in `alloc.rs`, changed part of the code
in `alloc` method to satisfy the SAFETY statement
2020-09-03 08:27:59 +08:00
Dylan DPC
af331a2d01
Rollup merge of #76261 - camelid:intra-doc-links-for-core-marker, r=jyn514
Use intra-doc links in `core::marker`

Part of #75080.

Also cleaned up a few things.

---

@rustbot modify labels: A-intra-doc-links T-doc
2020-09-03 02:22:18 +02:00
Dylan DPC
3368f5c820
Rollup merge of #76243 - ama0:patch-1, r=jonas-schievink
Fix typos in vec try_reserve(_exact) docs

`try_reserve` and `try_reserve_exact` docs refer to calling `reserve` and `reserve_exact`.
`try_reserve_exact` example uses `try_reserve` method instead of `try_reserve_exact`.
2020-09-03 02:22:13 +02:00
Dylan DPC
6d2b885112
Rollup merge of #76242 - RalfJung:read-fixme, r=Dylan-DPC
Read: adjust a FIXME reference

There's already another reference to https://github.com/rust-lang/rust/issues/42788 for basically the same problem, so lets reuse it here:
5e208efaa8/library/std/src/io/mod.rs (L369-L376)

r? @Dylan-DPC
2020-09-03 02:22:11 +02:00
Dylan DPC
4918ed96ee
Rollup merge of #76238 - denisvasilik:intra-doc-links-core-iterator, r=jyn514
Move to intra-doc links for library/core/src/iter/traits/iterator.rs

Helps with #75080.

@jyn514 We're almost finished with this issue. Thanks for mentoring. If you have other topics to work on just let me know, I will be around in Discord.

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

Known issues:

* Link from `core` to `std` (#74481):

    [`OsStr`]
    [`String`]
    [`VecDeque<T>`]
2020-09-03 02:22:10 +02:00
Dylan DPC
d059f2619f
Rollup merge of #76204 - NoraCodes:nora/control_flow_enum, r=scottmcm
Rename and expose LoopState as ControlFlow

Basic PR for #75744. Addresses everything there except for documentation; lots of examples are probably a good idea.
2020-09-03 02:22:07 +02:00
Dylan DPC
3e156cfe90
Rollup merge of #76164 - lzutao:slice-array, r=ehuss
Link to slice pattern in array docs

Fix a todo in https://github.com/rust-lang/reference/issues/739#issuecomment-578408449
2020-09-03 02:22:04 +02:00
Dylan DPC
9605f94f69
Rollup merge of #76142 - CDirkx:const-ip, r=ecstatic-morse
Make all methods of `std::net::Ipv4Addr` const

Make the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature:
 - `octets`
 - `is_loopback`
 - `is_private`
 - `is_link_local`
 - `is_global` (unstable)
 - `is_shared` (unstable)
 - `is_ietf_protocol_assignment` (unstable)
 - `is_benchmarking` (unstable)
 - `is_reserved` (unstable)
 - `is_multicast`
 - `is_broadcast`
 - `is_documentation`
 - `to_ipv6_compatible`
 - `to_ipv6_mapped`

This would make all methods of `Ipv6Addr` const.

Of these methods, `is_global`, `is_broadcast`, `to_ipv6_compatible`, and `to_ipv6_mapped` require a change in implementation.

Part of #76205
2020-09-03 02:22:02 +02:00
Dylan DPC
10aa3d3f89
Rollup merge of #76120 - LukasKalbertodt:add-as-slice-method-to-array, r=Mark-Simulacrum
Add `[T; N]::as_[mut_]slice`

Part of me trying to populate arrays with a couple of basic useful methods, like slices already have. The ability to add methods to arrays were added in #75212.  Tracking issue: #76118

This adds:

```rust
impl<T, const N: usize> [T; N] {
    pub fn as_slice(&self) -> &[T];
    pub fn as_mut_slice(&mut self) -> &mut [T];
}
```

These methods are like the ones on `std::array::FixedSizeArray` and in the crate `arraytools`.
2020-09-03 02:22:00 +02:00
Dylan DPC
536b0c0c90
Rollup merge of #75150 - nanpuyue:deprecate_to_ipv6_compatible, r=LukasKalbertodt
Add a note for Ipv4Addr::to_ipv6_compatible

Previous discussion: #75019

> I think adding a comment saying "This isn't typically the method you want; these addresses don't typically function on modern systems. Use `to_ipv6_mapped` instead." would be a good first step, whether this method gets marked as deprecated or not.

_Originally posted by @joshtriplett in https://github.com/rust-lang/rust/pull/75150#issuecomment-680267745_
2020-09-03 02:21:58 +02:00
Camelid
7926435317
Add back missing link 2020-09-02 15:48:35 -07:00
Howard Su
a80d39041e
Use inline(never) instead of cold
inline(never) is better way to avoid optimizer to inline the function instead of cold.
2020-09-03 06:31:21 +08:00
Camelid
2908ed64aa Use intra-doc links in core::marker 2020-09-02 15:22:40 -07:00
Joshua Nelson
bb103476a9 Fix incorrect link in prelude 2020-09-02 17:38:21 -04:00
Joshua Nelson
44bacc3ffa Revert change to MaybeUninit until rustdoc bugs are fixed
https://github.com/rust-lang/rust/issues/76106
2020-09-02 17:38:21 -04:00
Joshua Nelson
59a1a05bff Convert many files to intra-doc links
- Use intra-doc links for `std::io` in `std::fs`
- Use intra-doc links for File::read in unix/ext/fs.rs
- Remove explicit intra-doc links for `true` in `net/addr.rs`
- Use intra-doc links in alloc/src/sync.rs
- Use intra-doc links in src/ascii.rs
- Switch to intra-doc links in alloc/rc.rs
- Use intra-doc links in core/pin.rs
- Use intra-doc links in std/prelude
- Use shorter links in `std/fs.rs`

  `io` is already in scope.
2020-09-02 17:37:40 -04:00
Leonora Tindall
96eb5e1751 Format ControlFlow changes with rustfmt 2020-09-02 14:12:21 -05:00
bors
a167485e27 Auto merge of #75960 - camelid:patch-6, r=jyn514
Improve docs for the `const` keyword

@rustbot modify labels: T-doc
2020-09-02 17:35:46 +00:00
Denis Vasilik
89e7fb3bbd Revert link removal of Some(T) 2020-09-02 19:11:19 +02:00
Denis Vasilik
83143a1ef4 Revert link removal of 2020-09-02 19:07:32 +02:00
Denis Vasilik
3a035891f0 Revert link removal 2020-09-02 18:51:53 +02:00
Denis Vasilik
1a438bbcb7 Revert module level documentation link 2020-09-02 18:51:08 +02:00
Denis Vasilik
7cf0fe1d02 Apply suggestions from review 2020-09-02 18:32:46 +02:00
bors
95815c9b2b Auto merge of #76241 - RalfJung:flt2dec, r=Mark-Simulacrum
flt2dec: properly handle uninitialized memory

The float-to-str code currently uses uninitialized memory incorrectly (see https://github.com/rust-lang/rust/issues/76092). This PR fixes that.

Specifically, that code used `&mut [T]` as "out references", but it would be incorrect for the caller to actually pass uninitialized memory. So the PR changes this to `&mut [MaybeUninit<T>]`, and then functions return a `&[T]` to the part of the buffer that they initialized (some functions already did that, indirectly via `&Formatted`, others were adjusted to return that buffer instead of just the initialized length).

What I particularly like about this is that it moves `unsafe` to the right place: previously, the outermost caller had to use `unsafe` to assert that things are initialized; now it is the functions that do the actual initializing which have the corresponding `unsafe` block when they call `MaybeUninit::slice_get_ref` (renamed in https://github.com/rust-lang/rust/pull/76217 to `slice_assume_init_ref`).

Reviewers please be aware that I have no idea how any of this code actually works. My changes were purely mechanical and type-driven. The test suite passes so I guess I didn't screw up badly...

Cc @sfackler this is somewhat related to your RFC, and possibly some of this code could benefit from (a generalized version of) the API you describe there. But for now I think what I did is "good enough".

Fixes https://github.com/rust-lang/rust/issues/76092.
2020-09-02 15:23:08 +00:00
南浦月
3b29913295 add a note for Ipv4Addr::to_ipv6_compatible 2020-09-02 21:08:09 +08:00
Anton
dbe50f5c24
Same typos in vec_deque 2020-09-02 14:09:42 +02:00
Anton
b67006422e
Fix typos in vec try_reserve(_exact) docs
`try_reserve` and `try_reserve_exact` docs refer to calling `reserve` and `reserve_exact`.
`try_reserve_exact` example uses `try_reserve` method instead of `try_reserve_exact`.
2020-09-02 13:12:44 +02:00
Ralf Jung
56129d39c0 flt2dec: properly handle uninitialized memory 2020-09-02 12:41:38 +02:00
Ralf Jung
0af3bd01df Read: adjust a FIXME reference 2020-09-02 12:34:15 +02:00
Joshua Nelson
726b187546 Use intra-doc links for MaybeUninit in boxed.rs 2020-09-01 23:54:17 -04:00
Joshua Nelson
cafab51b29 Remove explicit links to true and false in ip.rs 2020-09-01 23:33:44 -04:00
Camelid
ce904783d0
Improve wording for const pointers 2020-09-01 19:44:20 -07:00
Tyler Mandry
4dd75f8049
Rollup merge of #76221 - camelid:cleanup-iter-for, r=jyn514
Clean up header in `iter` docs for `for` loops

@rustbot modify labels: T-doc
2020-09-01 18:24:48 -07:00
Tyler Mandry
7edc93b45c
Rollup merge of #76207 - denisvasilik:intra-doc-links-core-clone, r=jyn514
# Move to intra-doc links for library/core/src/clone.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-01 18:24:43 -07:00
Tyler Mandry
11ff32f9ec
Rollup merge of #76206 - CDirkx:const-ipv6, r=ecstatic-morse
Make all methods of `std::net::Ipv6Addr` const

Make the following methods of `std::net::Ipv6Addr` unstable const under the `const_ipv6` feature:
- `segments`
- `is_unspecified`
- `is_loopback`
- `is_global` (unstable)
- `is_unique_local`
- `is_unicast_link_local_strict`
- `is_documentation`
- `multicast_scope`
- `is_multicast`
- `to_ipv4_mapped`
- `to_ipv4`

This would make all methods of `Ipv6Addr` const.

Changed the implementation of `is_unspecified` and `is_loopback` to use a `match` instead of `==`, all other methods did not require a change.

All these methods are dependent on `segments`, the current implementation of which requires unstable `const_fn_transmute` ([PR#75085](https://github.com/rust-lang/rust/pull/75085)).

Part of #76205
2020-09-01 18:24:41 -07:00
Tyler Mandry
17fa7339e9
Rollup merge of #76201 - denisvasilik:intra-doc-links-core-panic, r=kennytm
Move to intra-doc links for library/core/src/panic.rs

Helps with #75080.

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

Known issues:

* Link from `core` to `std` (#74481):

    [`set_hook`]
    [`String`]
2020-09-01 18:24:39 -07:00
Tyler Mandry
34c8b7a92c
Rollup merge of #76099 - camelid:patch-8, r=jyn514
Add info about `!` and `impl Trait`

Fixes #76094.

@rustbot modify labels: T-doc C-enhancement
2020-09-01 18:24:29 -07:00
Tyler Mandry
7c1c7de85f
Rollup merge of #76088 - hbina:add_example, r=LukasKalbertodt
Add more examples to lexicographic cmp on Iterators.

Given two arrays of T1 and T2, the most important rule of lexicographical comparison is that two arrays
of equal length will be compared until the first difference occured.

The examples provided only focuses on the second rule that says that the
shorter array will be filled with some T2 that is less than every T1.
Which is only possible because of the first rule.
2020-09-01 18:24:27 -07:00
Tyler Mandry
383da5e1e6
Rollup merge of #74880 - chrisduerr:fix_matches, r=dtolnay
Add trailing comma support to matches macro
2020-09-01 18:24:23 -07:00
Camelid
54a4fd1eb9
Minor improvements
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-01 17:38:16 -07:00
Camelid
e5c17bff35 Clean up header in iter docs for for loops 2020-09-01 15:48:39 -07:00
Denis Vasilik
07cd4c8778 Use intra-doc links 2020-09-01 23:59:00 +02:00
Christiaan Dirkx
0c77257e56 Make all remaining methods of std::net::Ipv4Addr const
Makes the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature:
 - `is_global`
 - `is_reserved`
 - `is_broadcast`
 - `to_ipv6_compatible`
 - `to_ipv6_mapped`

This results in all methods of `Ipv4Addr` being const.

Also adds tests for these methods in a const context.
2020-09-01 23:55:17 +02:00
Leonora Tindall
d0af12560c Rename and expose LoopState as ControlFlow 2020-09-01 16:02:09 -05:00
CDirkx
a43dd4f401 Change implementation of Ipv6Addr::is_unspecified and is_loopback from matches! to u128 comparison
Done because `matches!` doesn't optimize well with array comparisons
2020-09-01 21:05:26 +02:00
Denis Vasilik
3510c56887 Improve readability 2020-09-01 19:56:32 +02:00
CDirkx
ee9e48bafc Make methods unstable const under const_ipv4 2020-09-01 19:50:01 +02:00
Denis Vasilik
e7d074392e Use intra-doc links 2020-09-01 19:20:15 +02:00
CDirkx
b31cc8f83e Make all methods of std::net::Ipv6Addr const
Make the following methods of `std::net::Ipv6Addr` unstable const under the `const_ipv6` feature:
- `segments`
- `is_unspecified`
- `is_loopback`
- `is_global` (unstable)
- `is_unique_local`
- `is_unicast_link_local_strict`
- `is_documentation`
- `multicast_scope`
- `is_multicast`
- `to_ipv4_mapped`
- `to_ipv4`

Changed the implementation of `is_unspecified` and `is_loopback` to use a `match` instead of `==`.

Part of #76205
2020-09-01 19:00:20 +02:00
Denis Vasilik
b639cb1e46
Enhance wording
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-01 18:16:34 +02:00
Denis Vasilik
9c7fb6c447 Use intra-doc links 2020-09-01 17:35:56 +02:00
Jon Gjengset
8b55360f70
Will land in 1.48, not 1.47 2020-09-01 09:50:32 -04:00
Jon Gjengset
010891f8b8
Merge branch 'master' into stabilize-vecdeque-make_contiguous 2020-09-01 09:49:42 -04:00
CDirkx
ea5dc0909e Make some Ordering methods const
Constify the following methods of `core::cmp::Ordering`:
 - `reverse`
 - `then`

Stabilizes these methods as const under the `const_ordering` feature.
Also adds a test for these methods in a const context.

Possible because of #49146 (Allow `if` and `match` in constants).
2020-09-01 15:44:00 +02:00
mental
0f301e8bb4 Removed [inline] and copied over comments from Arc::new_cyclic 2020-09-01 09:46:48 +01:00
bors
d9cd4a33f5 Auto merge of #76047 - Dylan-DPC:rename/maybe, r=RalfJung
rename get_{ref, mut} to assume_init_{ref,mut} in Maybeuninit

References #63568

Rework with comments addressed from #66174

Have replaced most of the occurrences I've found, hopefully didn't miss out anything

r? @RalfJung

(thanks @danielhenrymantilla for the initial work on this)
2020-09-01 05:41:22 +00:00
Camelid
55637f5669
Break line at 100 characters 2020-08-31 19:44:21 -07:00
Camelid
913354b846
Improve assert! section in bool docs 2020-08-31 19:41:27 -07:00
Camelid
c4c058c716 Improve wording
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-31 19:33:08 -07:00
Camelid
cdd6f11012 Remove empty comment 2020-08-31 19:33:08 -07:00
Camelid
e13a70122d Redefine Debug instead of importing it
This reverts commit 7e2548fe69.

Now I know why it was redefined: it seems like it's potentially because
of the orphan rule. Here are the error messages:

error[E0119]: conflicting implementations of trait `std::fmt::Debug` for type `!`:
 --> src/primitive_docs.rs:236:1
  |
6 | impl Debug for ! {
  | ^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `core`:
          - impl std::fmt::Debug for !;

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
 --> src/primitive_docs.rs:236:1
  |
6 | impl Debug for ! {
  | ^^^^^^^^^^^^^^^-
  | |              |
  | |              `!` is not defined in the current crate
  | impl doesn't use only types from inside the current crate
  |
  = note: define and implement a trait or new type instead
2020-08-31 19:33:08 -07:00
Tyler Mandry
9d435d2543
Rollup merge of #76172 - ecstatic-morse:revert-75463, r=RalfJung
Revert #75463

This was approved by me prematurely. It needs T-libs approval. Sorry @CDirkx.

r? @RalfJung
2020-08-31 19:18:29 -07:00
Tyler Mandry
c307e90daa
Rollup merge of #76139 - CDirkx:cow-is-borrowed, r=ecstatic-morse
Make `cow_is_borrowed` methods const

Constify the following methods of `alloc::borrow::Cow`:
 - `is_borrowed`
 - `is_owned`

Analogous to the const methods `is_some` and `is_none` for Option, and `is_ok` and `is_err` for Result.

These methods are still unstable under `cow_is_borrowed`.
Possible because of #49146 (Allow if and match in constants).

Tracking issue: #65143
2020-08-31 19:18:21 -07:00
Tyler Mandry
b675824493
Rollup merge of #75945 - pickfire:patch-7, r=jyn514
Use `env::func()`, not 'the function env::func' in docs for std::env

Follow up of https://github.com/rust-lang/rust/pull/75629

r? @jyn514
2020-08-31 19:18:13 -07:00
bors
45f638bd86 Auto merge of #75979 - lzutao:seprate-tests, r=Mark-Simulacrum
Move `#[cfg(test)]` modules into separate files to save recompiling the `std` crate

Implements an accepted proposal: https://github.com/rust-lang/compiler-team/issues/344

Some notes for reviewers:
* `mod tests` nested in `mod foo` in `mod bar`, I move `foo` to a new file, `tests` is a new file in foo: For example library/std/src/sys/sgx/abi/tls.rs
* `mod test` (not `mod tests`) also is moved.
* `mod benches` are moved.
* `mod tests` is placed before any `use` statements: The topic is discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Code.20Style.20process
* Some files in cloudabi was changed too. But I notice copyright banners in those files, should we ping cloudabi people?
* I formatted files after moving tests around. I think that may make it easier to review :p .
* Some files don't need `ignore-tidy-filelength` anymore.
2020-08-31 20:03:33 +00:00
Dylan MacKenzie
4404cc5bc7 Revert #75463
This was approved by me prematurely. It needs T-libs approval.
2020-08-31 10:22:14 -07:00
bors
897ef3a0ec Auto merge of #75936 - sdroege:chunks-exact-construction-bounds-check, r=nagisa
Get rid of bounds check in slice::chunks_exact() and related function…

…s during construction

LLVM can't figure out in

    let rem = self.len() % chunk_size;
    let len = self.len() - rem;
    let (fst, snd) = self.split_at(len);

and

    let rem = self.len() % chunk_size;
    let (fst, snd) = self.split_at(rem);

that the index passed to split_at() is smaller than the slice length and
adds a bounds check plus panic for it.

Apart from removing the overhead of the bounds check this also allows
LLVM to optimize code around the ChunksExact iterator better.
2020-08-31 15:55:13 +00:00
Lzu Tao
a74d4e4889 Link to slice pattern in array docs 2020-08-31 14:53:02 +00:00
DPC
943911cc8b the one left behind 2020-08-31 14:57:12 +02:00
Arkadiusz Piekarz
814245779c Update tracking issue for const_caller_location 2020-08-31 14:38:15 +02:00
bors
3b4797cb59 Auto merge of #76153 - matklad:rollup-vlblfup, r=matklad
Rollup of 9 pull requests

Successful merges:

 - #75969 (Switch to intra-doc links in core/src/{convert,iter}/mod.rs)
 - #76023 (Liballoc extend use intra doc link)
 - #76033 (Add missing hyphen)
 - #76052 (GH-66816:  Remove disable attr before return)
 - #76055 (Keep doc standard for Vec DrainFilter)
 - #76058 (Use assertions on Vec doc)
 - #76069 (Use explicit intra-doc link in path for Vec resize)
 - #76117 (Update README.md)
 - #76134 (Update MinGW instructions to include ninja)

Failed merges:

r? @ghost
2020-08-31 11:01:40 +00:00
Aleksey Kladov
13c4f04561
Rollup merge of #76069 - pickfire:patch-16, r=jyn514
Use explicit intra-doc link in path for Vec resize

r? @jyn514
2020-08-31 12:51:53 +02:00
Aleksey Kladov
d829a5bcb1
Rollup merge of #76058 - pickfire:patch-11, r=jyn514
Use assertions on Vec doc

Clarify what the state of Vec after with_capacity on doc.

r? @jyn514
2020-08-31 12:51:51 +02:00
Aleksey Kladov
af1f46cf99
Rollup merge of #76055 - pickfire:patch-9, r=jyn514
Keep doc standard for Vec DrainFilter

r? @jyn514
2020-08-31 12:51:49 +02:00
Aleksey Kladov
6ce3243995
Rollup merge of #76033 - camelid:patch-7, r=Dylan-DPC
Add missing hyphen

reference counted pointer -> reference-counted pointer

@rustbot modify labels: T-doc
2020-08-31 12:51:45 +02:00
Aleksey Kladov
e59eb4e0fa
Rollup merge of #76023 - pickfire:patch-4, r=jyn514
Liballoc extend use intra doc link

Superseeds https://github.com/rust-lang/rust/pull/75729/commits

r? @jyn514
2020-08-31 12:51:42 +02:00
Aleksey Kladov
c6017142a3
Rollup merge of #75969 - nixphix:docs/mod, r=jyn514
Switch to intra-doc links in core/src/{convert,iter}/mod.rs

Partial fix for #75080

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

r? @jyn514

couldn't fix these

```rust
     ../../std/string/struct.String.html
     ../../std/primitive.never.html
     ../../std/sync/mpsc/struct.TryIter.html
```
2020-08-31 12:51:40 +02:00
bors
8bfe289886 Auto merge of #75932 - Amjad50:intra-doc-core-slice, r=jyn514
Use intra-doc links for `core/src/slice.mod.rs`

partial help in #75080

r? @jyn514

- most are using primitive types links, which cannot be used with intra links at the moment
- also `std` cannot be referenced in any link, `std::ptr::NonNull` and `std::slice` could not be referenced
2020-08-31 09:09:37 +00:00
bors
e98f0632bb Auto merge of #75082 - Aaron1011:feature/proc-macro-backtrace, r=petrochenkov
Add `-Z proc-macro-backtrace` to allow showing proc-macro panics

Fixes #75050

Previously, we would unconditionally suppress the panic hook during
proc-macro execution. This commit adds a new flag
`-Z proc-macro-backtrace`, which allows running the panic hook for
easier debugging.
2020-08-31 03:19:05 +00:00
CDirkx
fbb3673331 Make more Ipv4Addr methods const
Constify the following methods of `std::net::Ipv4Addr`:
 - `octets`
 - `is_loopback`
 - `is_private`
 - `is_link_local`
 - `is_shared`
 - `is_ietf_protocol_assignment`
 - `is_benchmarking`
 - `is_multicast`
 - `is_documentation`

Also insta-stabilizes these methods as const.

Possible because of the stabilization of const integer arithmetic and control flow.
2020-08-31 05:09:20 +02:00
Lzu Tao
a4e926daee std: move "mod tests/benches" to separate files
Also doing fmt inplace as requested.
2020-08-31 02:56:59 +00:00
Aaron Hill
d9208665b5
Add -Z proc-macro-backtrace to allow showing proc-macro panics
Fixes #75050

Previously, we would unconditionally suppress the panic hook during
proc-macro execution. This commit adds a new flag
-Z proc-macro-backtrace, which allows running the panic hook for
easier debugging.
2020-08-30 22:17:24 -04:00
CDirkx
af24bdbd96 Make cow_is_borrowed methods const
Constify the following methods of `alloc::borrow::Cow`:
 - `is_borrowed`
 - `is_owned`

These methods are still unstable under `cow_is_borrowed`.
Possible because of #49146 (Allow if and match in constants).

Tracking issue: #65143
2020-08-31 03:43:47 +02:00
bors
92290d1631 Auto merge of #75463 - CDirkx:ordering-const, r=CDirkx
Make some Ordering methods const

Constify the following methods of `core::cmp::Ordering`:
 - `reverse`
 - `then`

Possible because of #49146 (Allow `if` and `match` in constants).

Tracking issue:  #76113
2020-08-31 01:28:42 +00:00
DPC
6d35f8475f fix 2020-08-31 02:27:38 +02:00
CDirkx
12f4624f71 Update since to correct release
`const_ordering` will stabilize in version 1.48.0
2020-08-30 23:59:37 +02:00
CDirkx
89fc3fb93b Stabilize feature const_ordering 2020-08-30 23:48:54 +02:00
Alexis Bourget
6b75e3d11b Move to Arc::clone(&x) over x.clone() in library/core 2020-08-30 22:14:17 +02:00
Sebastian Dröge
8d3cf9237d Improve documentation of slice::get_unchecked() / split_at_unchecked()
Thanks to Ivan Tham, who gave the majority of these suggestions during
their review.
2020-08-30 23:13:47 +03:00
Sebastian Dröge
d08996ac54 Get rid of bounds check in slice::chunks_exact() and related functions during construction
LLVM can't figure out in

    let rem = self.len() % chunk_size;
    let len = self.len() - rem;
    let (fst, snd) = self.split_at(len);

and

    let rem = self.len() % chunk_size;
    let (fst, snd) = self.split_at(rem);

that the index passed to split_at() is smaller than the slice length and
adds a bounds check plus panic for it.

Apart from removing the overhead of the bounds check this also allows
LLVM to optimize code around the ChunksExact iterator better.
2020-08-30 23:13:47 +03:00
Sebastian Dröge
30dc32b10e Add (non-public) slice::split_at_unchecked() and split_at_mut_unchecked()
These are unsafe variants of the non-unchecked functions and don't do
any bounds checking.

For the time being these are not public and only a preparation for the
following commit. Making it public and stabilization can follow later
and be discussed in https://github.com/rust-lang/rust/issues/76014 .
2020-08-30 23:13:46 +03:00
Alexis Bourget
81e85ce76d Move to Arc::clone(&x) over x.clone() in library/std 2020-08-30 21:59:43 +02:00
Lukas Kalbertodt
d7afe2a223
Fix tests using FixedSizeArray methods (which are now shadowed) 2020-08-30 21:08:18 +02:00
Lukas Kalbertodt
104a02301c
Add [T; N]::as_[mut_]slice
These methods are like the ones on `std::array::FixedSizeArray`
and in the crate `arraytools`.
2020-08-30 21:08:17 +02:00
Camelid
37ea97cc10
Explain why the 0 is a u32 2020-08-30 11:43:16 -07:00
Camelid
7e2548fe69
Import Debug instead of redefining it 2020-08-30 11:39:45 -07:00
CDirkx
5fac991bf6 Add unstable const_ordering feature, and some tests. 2020-08-30 19:40:00 +02:00
Andy Russell
98232ece14
fix broken trait method links 2020-08-30 12:04:43 -04:00
Prabakaran Kumaresshan
523fea4d14 revert Some(Item) link 2020-08-30 19:19:20 +05:30
Ivan Tham
1d017eb6a4
Fix env doc vars_os broken link 2020-08-30 21:19:21 +08:00
DPC
b3d7b7bdcb update fixmes 2020-08-30 14:43:52 +02:00
Prabakaran Kumaresshan
7ea4c28af2 add i32::MAX link 2020-08-30 17:07:50 +05:30
Amjad Alsharafi
300a0072a2 Fix intra-doc path resolution problem in library/alloc/src/slice.rs
`alloc::slice` uses `core::slice` functions, documentation are copied
from there and the links as well without resolution. `crate::ptr...`
cannot be resolved in `alloc::slice`, but `ptr` itself is imported in
both `alloc::slice` and `core::slice`, so we used that instead.
2020-08-30 15:22:27 +08:00
Camelid
bd3196282b
other branch -> else branch 2020-08-29 20:53:40 -07:00
Camelid
80dcad9e5b
Be more specific about polymorphic return types
I no longer say "polymorphic" since it's a bit ambiguous here.
2020-08-29 20:52:09 -07:00
Camelid
26eab6a0d5
Specify 0 of type u32 2020-08-29 20:48:53 -07:00
Camelid
0d9a2abe69
It's only an issue without an impl Trait for ! 2020-08-29 20:41:36 -07:00
Camelid
fd985e29dd
cannot have divergence -> cannot diverge 2020-08-29 20:35:58 -07:00
Ivan Tham
00cf550c2b Env use shorter intra-doc links in path
vars() rather than vars function

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

Use [xxx()] rather than the [xxx] function

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

Env text representation of function intra-doc link

Suggested by @jyn514

Link join_paths in env doc for parity

Change xxx to env::xxx for lib env doc

Add link requsted by @jyn514

Fix doc build with same link

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

Fix missing intra-doc link

Fix added whitespace in doc

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

Add brackets for `join_paths`

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

Use unused link join_paths

Removed same link for join_paths

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

Remove unsed link join_paths
2020-08-30 11:16:06 +08:00
Camelid
4aae781407 Add info about ! and impl Trait 2020-08-29 19:59:22 -07:00
Ivan Tham
20a68666d8
Try removing [prim@reference] 2020-08-30 09:17:22 +08:00
Prabakaran Kumaresshan
01d95f241b resolve comments 2020-08-30 05:40:47 +05:30
Prabakaran Kumaresshan
8a92718b64 Switch to intra-doc links in core/src/{convert,iter}/mod.rs 2020-08-30 05:40:47 +05:30
Dylan DPC
11193ca202
Rollup merge of #76029 - denisvasilik:intra-doc-links-core-atomic, r=kennytm
Move to intra-doc links for library/core/src/sync/atomic.rs

Helps with #75080.

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

Known issues:

* Link from core to std:

    [`Arc`]
	[`std:🧵:yield_now`]
	[`std:🧵:sleep`]
	[`std::sync::Mutex`]
2020-08-30 01:43:59 +02:00
Dylan DPC
96e0bc7b6b
Rollup merge of #75990 - rylev:arm-fastfail, r=alexcrichton
Add __fastfail for Windows on arm/aarch64

Fixes #73215
2020-08-30 01:43:54 +02:00
Dylan DPC
9225aabef4
Rollup merge of #75917 - poliorcetics:intra-doc-core-nonnull, r=jyn514
Move to intra doc links for core::ptr::non_null

Helps with #75080.

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

r? @jyn514
2020-08-30 01:43:50 +02:00
Dylan DPC
75d6b109c2
Rollup merge of #75874 - pickfire:patch-3, r=jyn514
Shorten liballoc doc intra link while readable

r? @jyn514

Do you want to reviews these sort of pull requests in the future? I might send a few of them while reading vec code.
2020-08-30 01:43:41 +02:00
Dylan DPC
d17db64b8d
Rollup merge of #75852 - camelid:patch-3, r=jyn514
Switch to intra-doc links in `core::hash`

Part of #75080.

@rustbot modify labels: A-intra-doc-links T-doc T-rustdoc
2020-08-30 01:43:39 +02:00
Dylan DPC
027b2f1e06
Rollup merge of #75832 - kofls:intradoc-fix, r=jyn514
Move to intra-doc links for wasi/ext/fs.rs, os_str_bytes.rs…

…, primitive_docs.rs & poison.rs

Partial fix for #75080

r? @jyn514
2020-08-30 01:43:37 +02:00
Hanif Bin Ariffin
cc3b2f9e1d Add more examples to lexicographic cmp on Iterators.
The most important rule of lexicographical comparison is that two arrays
of equal length will be compared until the first difference occured.

The examples provided only focuses on the second rule that says that the
shorter array will be filled with some T2 that is less than every T.
Which is only possible because of the first rule.
2020-08-29 19:01:41 -04:00
DPC
ea800d529a fix tests 2020-08-29 17:25:14 +02:00
Ivan Tham
2d1ab83834
Remove empty vec assertion flow distrupt
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-29 23:07:40 +08:00
Ivan Tham
be8b5eb529
Reuse description from drain_filter
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-29 22:39:34 +08:00
Ivan Tham
237c5005d6
Use explicit intra-doc link in path for Vec resize 2020-08-29 20:40:05 +08:00
Ivan Tham
7148412100
Vec slice example fix style and show type elision 2020-08-29 18:57:49 +08:00
Ivan Tham
bb5e79cbd1
Link vec doc to & reference
It is not always obvious that people could see the docs for `&`
especially for beginners, it also helps learnability.
2020-08-29 18:47:11 +08:00
Ivan Tham
12b4cf8c6c
Use assertions on Vec doc
Clarify what the state of Vec after with_capacity on doc.
2020-08-29 18:38:18 +08:00
Ryan Levick
d931e97402 Explicitly look for 'thumb-mode' before using __fastfail on 'arm' 2020-08-29 12:30:49 +02:00
Ivan Tham
ba4c498816
Add more info for Vec Drain doc
See its documentation for more
2020-08-29 18:25:17 +08:00
Ivan Tham
d727442f2d
Remove brackets in drain filter docs 2020-08-29 18:23:29 +08:00
Ivan Tham
d504d553f1
Keep doc standard for Vec DrainFilter 2020-08-29 18:21:47 +08:00
Ivan Tham
c7e428e862
Liballoc vec doc use associated function
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-29 16:13:05 +08:00
mental
42fb27001e
typo
Co-authored-by: Andrew Hickman <andrew.hickman1@sky.com>
2020-08-29 07:39:03 +01:00
bors
360a372f2c Auto merge of #75877 - vigoux:master, r=Amanieu
Update compiler-builtins

Update the compiler-builtins dependency to include latest changes.

This allows for `aarch64-unknown-linux-musl` to pass all tests.

Fixes #57820 and fixes #46651
2020-08-29 01:48:40 +00:00
DPC
5e208efaa8 rename get_{ref, mut} to assume_init_{ref,mut} in Maybeuninit 2020-08-29 02:13:02 +02:00
bors
7b1dd61bda Auto merge of #72808 - Lucretiel:line-writer-reimpl, r=Amanieu
Substantial refactor to the design of LineWriter

# Preamble

This is the first in a series of pull requests designed to move forward with https://github.com/rust-lang/rust/issues/60673 (and the related [5 year old FIXME](ea7181b5f7/src/libstd/io/stdio.rs (L459-L461))), which calls for an update to `Stdout` such that it can be block-buffered rather than line-buffered under certain circumstances (such as a `tty`, or a user setting the mode with a function call). This pull request refactors the logic `LineWriter` into a `LineWriterShim`, which operates on a `BufWriter` by mutable reference, such that it is easy to invoke the line-writing logic on an existing `BufWriter` without having to construct a new `LineWriter`.

Additionally, fixes #72721

## A note on flushing

Because the word **flush** tends to be pretty overloaded in this discussion, I'm going to use the word **unbuffered** to refer to a `BufWriter` sending its data to the wrapped writer via `write`, without calling `flush` on it, and I'll be using **flushed** when referring to sending data via flush, which recursively writes the data all the way to the final sink.

For example, given a `T = BufWriter<BufWriter<File>>`, saying that `T` **unbuffers** its data means that it is sent to the inner `BufWriter`, but not necessarily to the `File`, whereas saying that `T` **flushes** its data means that causes it (via `Write::flush`) to be delivered all the way to `File`.

# Goals

Once it became clear (for reasons described below) that the best way to approach this would involve refactoring `LineWriter` to work more directly on `BufWriter`'s internals, I established the following design goals for the refactor:

- Do not duplicate logic with `BufWriter`. It's great at buffering and then unbuffering data, so use the existing logic as much as possible.
- Minimize superfluous copying of data into `BufWriter`'s buffer.
- Eliminate calls to `BufWriter::flush` and instead do the same thing as `BufWriter::write`, which is to only write to the wrapped writer (rather than flushing all the way down to the final data sink).
- Uphold the "at-most 1 write of new data" convention of `Write::write`
- Minimize or eliminate dropping errors (that is, eliminate the parts of the old design that threw away errors because `write` *must* report if any bytes were written)
- As much as possible, attempt to fully flush completed lines, and *not* flush partial lines. One of the advantages of this design is that, so long as we don't encounter lines larger than the `BufWriter`'s capacity, partial lines will never be unbuffered, while completed lines will *always* be unbuffered (with subsequent calls to `LineWriter::write` retrying failed writes before processing new data.

# Design

There are two major & related parts of the design.

First, a new internal stuct, `LineWriterShim`, is added. This struct implements all of the actual logic of line-writing in a `Write` implementation, but it only operates on an `&mut BufWriter`. This means that this shim can be constructed on-the-fly to apply line writing logic to an existing `BufWriter`. This is in fact how `LineWriter` has been updated to operate, and it is also how `Stdout` is being updated in my [development branch](https://github.com/Lucretiel/rust/tree/stdout-block-buffer) to switch which mode it wants to use at runtime.

[An example of how this looks in practice](f24f272df6/src/libstd/io/stdio.rs (L479-L484)
)

The second major part of the design that the line-buffering logic, implemented in `LineWriterShim`, has been updated to work slightly more directly on the internals of `BufWriter`. Mostly it makes us of the public interface—particularly `buffer()` and `get_mut()`—but it also controls the flushing of the buffer with `flush_buf` rather than `flush`, and it writes to the buffer infallibly with a new `write_to_buffer` method. This has several advantages:

- Data no longer has to round trip through the `BufWriter`'s buffer. If the user provides a complete line, that line is written directly to the inner writer (after ensuring the existing buffer is flushed).
- The conventional contract of `write`—that at-most 1 attempt to write new data is made—is much more cleanly upheld, because we don't have to perform fallible flushes and perform semi-complicated logic of trying to pretend errors at different stages didn't happen. Instead, after attempting to write lines directly to the buffer, we can infallibly add trailing data to the buffer without allowing any attempts to continue writing it to the `inner` writer.
- Perhaps most importantly, `LineWriter` *no longer performs a full flush on every line.* This makes its behavior much more consistent with `BufWriter`, which unbuffers data to its inner writer, without trying to flush it all the way to the final device. Previously, `LineWriter` had no choice but to use `flush` to ensure that the lines were unbuffered, but by writing directly to `inner` via `get_mut()` (when appropriate), we can use a more correct behavior.

## New(ish) line buffering logic

The logic for line writing has been cleaned up, as described above. It now follows this algorithm for `write`, with minor adjustments for `write_all` and `write_vectored`:

- Does our input data contain a newline?
    - If no:
        - simply use the regular `BufWriter::write` to write it; this will append it to the buffer and/or flush it as necessary based on how full the buffer is and how much input data there is.
        - additionally, if the current buffer ends with `'\n'`, attempt to immediately flush it with `flush_buf` before calling `BufWriter::write` This reproduces the old `needs_flush` behavior and ensures completed lines are flushed as soon as possible. The reason we only check if the buffer *ends* with `'\n'` is discussed later.
    - If yes:
        - First, `flush_buf`
        - Then use `bufwriter.get_mut().write()` to write the input data directly to the underlying writer, up to the last newline. Make at most one attempt at this.
        - If it errors, return the error
        - If it succeeds with a full write, add the remaining data (between the last newline and the end of the input) to the buffer. In order to uphold the "at-most 1 attempt to write new data" convention, no attempts are made to write this data to the inner writer (though obviously a subsequent write may immediately flush it, e.g., if it totally filled the buffer's capacity.
        - If it only partially succeeds, buffer the data only up to the last newline. We do this to try to avoid writing partial lines to the inner writer where possible (that is, whenever the lines are shorter than the total buffer capacity).

While it was not my intention for this behavior to diverge from this existing `LineWriter` algorithm, this updated design emerged very naturally once `LineWriter` wasn't burdened with having to only operate via `BufWriter::flush`. There essentially two main changes to observable behavior:

- `flush` is no longer used to unbuffer lines. The are only written to the writer wrapped by `LineWriter`; this inner writer might do its own buffering. This change makes `LineWriter` consistent with the behavior of `BufWriter`. This is probably the most obvious user-visible change; it's the one I most expect to provoke issue reports, if any are provoked.
- Unless a line exceeds the capacity of the buffer, partial lines are not unbuffered (without the user manually calling flush). This is a less surprising behavior, and is enabled because `LineWriter` now has more precise control of what data is buffered and when it is unbuffered. I'd be surprised if anyone is relying on `LineWriter` unbuffering or flushing *partial* lines that are shorter than the capacity, so I'm not worried about this one.

None of these changes are inconsistent with any published documentation of `LineWriter`. Nonetheless, like all changes with user-facing behavior changes, this design will obviously have to be very carefully scrutinized.

# Alternative designs and design rationalle

The initial goal of this project was to provide a way for the `LineWriter` logic to be operable directly on a `BufWriter`, so that the updated `Stdout` doesn't need to do something convoluted like `enum { BufWriter, LineWriter }` (which ends up being ~~impossible~~ difficult to transition between states after being constructed). The design went through several iterations before arriving at the current draft.

The major first version simply involved adding methods like `write_line_buffered` to `BufWriter`; these would contain the actual logic of line-buffered writing, and would additionally have the advantages (described above) of operating directly on the internals of `BufWriter`. The idea was that `LineWriter` would simply call these methods, and the updated `Stdout` would use either `BufWriter::write` or `BufWriter::write_line_buffered`, depending on what mode it was in.

The major issue with this design is that it loses the ability to take advantage of the `io::Write` trait, which provides several useful default implementations of the various io methods, such as `write_fmt` and `write_all`, just using the core methods. For this reason, the `write_line_buffered` design was retained, but moved into a separate struct called `LineWriterShim` which operates on an `&mut LineWriter`. As part of this move, the logic was lightly retooled to not touch the innards of `BufWriter` directly, but instead to make use of the unexported helper methods like `flush_buf`.

The other design evolutions were mostly related to answering questions like "how much data should be buffered", "how should partial line writes be handled", etc. As much as possible I tried to answer these by emulating the current `LineWriter` logic (which, for example, retries partial line writes on subsequent calls to `write`) while still meeting the refactor design goals.

# Next steps

~Currently, this design fails a few `LineWriter` tests, mostly because they expect `LineWriter` to *fully* flush its content. There are also some changes to the way that `LineWriter` buffers data *after* writing completed lines, aimed at ensuring that partial lines are not unbuffered prematurely. I want to make sure I fully understand the intent behind these tests before I either update the test or update this design so that they pass.~

However, in the meantime I wanted to get this published so that feedback could start to accumulate on it. There's a lot of errata around how I arrived at this design that didn't really fit in this overlong document, so please ask questions about anything that confusing or unclear and hopefully I can explain more of the rationale that led to it.

# Test updates

This design required some tests to be updated; I've research the intent behind these tests (mostly via `git blame`) and updated them appropriately. Those changes are cataloged here.

- `test_line_buffer_fail_flush`: This test was added as a regression test for #32085, and is intended to assure that an errors from `flush` aren't propagated when preceded by a successful `write`. Because type of issue is no longer possible, because `write` calls `buffer.get_mut().write()` instead of `buffer.write(); buffer.flush();`, I'm simply removing this test entirely. Other, similar error invariants related to errors during write-retrying are handled in other test cases.
- `erroneous_flush_retried`: This test was added as a regression test for #37807, and was intended to ensure that flush-retrying (via `needs_flush`) and error-ignoring were being handled correctly (ironically, this issue was caused by the flush-error-ignoring, above). Half of that issue is not possible by design with this refactor, because we no longer make fallible i/o calls that might produce errors we have to ignore after unbuffering lines. The `should_flush` behavior is captured by checking for a trailing newline in the `LineWriter` buffer; this test now checks that behavior.
- `line_vectored`: changes here were pretty minor, mostly related to when partial lines are or aren't written. The old implementation of `write_vectored` used very complicated logic to precisely determine the location of the last newline and precisely write up to that point; this required doing several consecutive fallible writes, with all the complex error handling or ignoring issues that come with it. The updated design does at-most one write of a subset of total buffers (that is, it doesn't split in the middle of a buffer), even if that means writing partial lines. One of the major advantages of the new design is that the underlying vectored write operation on the device can be taken advantage of, even with small writes, so long as they include a newline; previously these were unconditionally buffered then written.
- `line_vectored_partial_and_errors`: Pretty similiar to `line_vectored`, above; this test is for basic error recovery in `write_vectored` for vectored writes. As previously discussed, the mocked behavior being tested for (errors ignored under certain circumstances) no occurs, so I've simplified the test while doing my best to retain its spirit.
2020-08-28 23:41:57 +00:00
Camelid
7be129e53a
Add missing hyphen
reference counted pointer -> reference-counted pointer
2020-08-28 09:29:06 -07:00
Ryan Levick
9e2228d2d0 Back to opcode for 32 bit ARM __fastfail 2020-08-28 17:40:56 +02:00
Denis Vasilik
c7571e6040 Use intra-doc links for bool 2020-08-28 17:30:05 +02:00
Denis Vasilik
4bbed52320 Use intra-doc links 2020-08-28 17:24:47 +02:00
Ivan Tham
2d6ab122b7
Liballoc extend use intra doc link 2020-08-28 19:33:53 +08:00
Ryan Levick
8bcc4d6178 Switch to asm! macro and use brk instruction on ARM 2020-08-28 11:22:21 +02:00
Pietro Albini
35496c2667
Rollup merge of #75998 - richkadel:llvm-coverage-map-gen-6b.1, r=wesleywiser
Add InstrProfilingPlatformFuchsia.c to profiler_builtins

All other Platform files included in `llvm-project/compiler-rt` were
present, except Fuchsia.

Now that there is a functional end-to-end version of
`-Zinstrument-coverage`, I need to start building and testing
coverage-enabled Rust programs on Fuchsia, and this file is required.

r? @tmandry
FYI, @wesleywiser
2020-08-28 10:24:11 +02:00
Pietro Albini
0f1ffa85d1
Rollup merge of #75967 - aticu:blackbox_typo, r=Dylan-DPC
Fix typo in `std::hint::black_box` docs
2020-08-28 10:24:04 +02:00
Pietro Albini
e027b57e40
Rollup merge of #75955 - camelid:intra-doc-links-for-future-and-dec2flt, r=jyn514
Use intra-doc links in `core::future::future` and `core::num::dec2flt`

Part of #75080.

@rustbot modify labels: A-intra-doc-links T-doc
2020-08-28 10:24:02 +02:00
Pietro Albini
cbe3aef559
Rollup merge of #75946 - pickfire:patch-8, r=jyn514
Error use explicit intra-doc link and fix text

Follow up of https://github.com/rust-lang/rust/pull/75629

r? @jyn514
2020-08-28 10:24:00 +02:00
Pietro Albini
be1b304ea4
Rollup merge of #75943 - elichai:2020-align_offset-docs, r=RalfJung
Fix potential UB in align_offset doc examples

Currently it takes a pointer only to the first element in the array, this changes the code to take a pointer to the whole array.
miri can't catch this right now because it later calls `x.len()` which re-tags the pointer for the whole array.

https://github.com/rust-lang/miri/issues/1526#issuecomment-680897144
2020-08-28 10:23:59 +02:00
Pietro Albini
521b2054b6
Rollup merge of #75927 - camelid:intra-doc-links-for-core-macros, r=jyn514
Use intra-doc links in `core::macros`

Part of #75080.

Also cleaned up some things.

@rustbot modify labels: A-intra-doc-links T-doc T-rustdoc
2020-08-28 10:23:55 +02:00
Thomas Vigouroux
392478c29e Update compiler-builtins
Fixes #57820 and #46651
2020-08-28 09:02:39 +02:00
Amjad Alsharafi
6aae4a2fe6 Used intra-doc links for ptr#safety occurrences 2020-08-28 11:52:04 +08:00
Amjad Alsharafi
a04e12002a Used intra-doc links for NonNull::dangling() occurrences 2020-08-28 11:52:04 +08:00
Amjad Alsharafi
8e33137159 Fixes intra-doc same scope links 2020-08-28 11:52:03 +08:00
Amjad Alsharafi
91e4aaa736 Use intra-doc links for core/src/slice.mod.rs
- most are using primitive types links, which cannot be used with intra
  links at the moment
- also `std` cannot be referenced in any link
2020-08-28 11:52:03 +08:00
Nathan West
c91e764d51 Once again, x.py tidy 2020-08-27 22:55:58 -04:00
Nathan West
d2d8bcb50e Typo fixes 2020-08-27 22:49:16 -04:00
Camelid
39cd184606
Remove unnecessary intra-doc link
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-27 19:42:23 -07:00
Nathan West
017ed5a579 Improvements to LineWriter::write_all
`LineWriter::write_all` now only emits a single write when writing a
newline when there's already buffered data.
2020-08-27 22:32:28 -04:00
bors
41aaa90c67 Auto merge of #70212 - Amanieu:catch_foreign, r=Mark-Simulacrum
Abort when foreign exceptions are caught by catch_unwind

Prior to this PR, foreign exceptions were not caught by catch_unwind, and instead passed through invisibly. This represented a painful soundness hole in some libraries ([take_mut](https://github.com/Sgeo/take_mut/blob/master/src/lib.rs#L37)), which relied on `catch_unwind` to handle all possible exit paths from a closure.

With this PR, foreign exceptions are now caught by `catch_unwind` and will trigger an abort since catching foreign exceptions is currently UB according to the latest proposals by the FFI unwind project group.

cc @rust-lang/wg-ffi-unwind
2020-08-28 01:20:17 +00:00
Amanieu d'Antras
239f833ed1 Abort when catch_unwind catches a foreign exception 2020-08-27 21:08:30 +01:00
Camelid
f0722c06a7 Switch to intra-doc links in core::hash 2020-08-27 12:09:50 -07:00