Commit Graph

1643 Commits

Author SHA1 Message Date
Shahar Or (mightyiam) badf4afdd5 core::global_allocator docs link to std::alloc::GlobalAlloc 2020-09-29 14:39:44 +07:00
hyd-dev a2526b416f
Use `rtassert!` instead of `assert!` from the child process after fork() in std::sys::unix::process::Command::spawn()
`assert!` panics on failure, which is not signal-safe.
2020-09-29 15:16:46 +08:00
kadmin 3f1d2aadd1 Use more efficient scheme for display u128/i128
Add zero padding

Add benchmarks for fmt u128

This tests both when there is the max amount of work(all characters used)
And least amount of work(1 character used)
2020-09-28 20:38:38 +00:00
Jacob Hughes 5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
Ralf Jung a966f54bbb
Rollup merge of #77288 - RalfJung:miri-macos, r=Amanieu
fix building libstd for Miri on macOS

Fixes a Miri regression introduced by https://github.com/rust-lang/rust/pull/75295
Cc @tmiasko @Amanieu
2020-09-28 18:39:47 +02:00
Ralf Jung aba966a592
Rollup merge of #77194 - pickfire:patch-7, r=withoutboats
Add doc alias for iterator fold

fold is known in python and javascript as reduce,
not sure about inject but it was written in doc there.

This was my first confusion when coming into rust, I somehow cannot find where is reduce, sometimes I still forget that it is known as `fold`.
2020-09-28 18:39:46 +02:00
Ralf Jung 85a59d40f1
Rollup merge of #77170 - ecstatic-morse:const-fn-ptr, r=oli-obk
Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`

`rustc_allow_const_fn_ptr` was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need a bespoke attribute.

Now this functionality is gated under `const_fn_fn_ptr_basics` (how concise!), and `#[allow_internal_unstable(const_fn_fn_ptr_basics)]` replaces `#[rustc_allow_const_fn_ptr]`. `const_fn_fn_ptr_basics` allows function pointer types to appear in the arguments and locals of a `const fn` as well as function pointer casts to be performed inside a `const fn`. Both of these were allowed in constants and statics already. Notably, this does **not** allow users to invoke function pointers in a const context. Presumably, we will use a nicer name for that (`const_fn_ptr`?).

r? @oli-obk
2020-09-28 18:39:44 +02:00
Ralf Jung 734c57d45c
Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad
UI to unit test for those using Cell/RefCell/UnsafeCell

Helps with #76268.

I'm working on all files using `Cell` and moving them to unit tests when possible.

r? @matklad
2020-09-28 18:39:39 +02:00
Lzu Tao d4772014d9 Prefer asm! in std - all in sgx module 2020-09-28 13:08:34 +00:00
bors 1d5a865b2f Auto merge of #77282 - glaubitz:sparc-linux, r=nagisa
Add missing definitions required by the sparc-unknown-linux-gnu target

This PR adds a few missing definitions required by sparc-unknown-linux-target which were discovered during build tests.
2020-09-28 10:37:41 +00:00
Tim Diekmann c22d896b9b Change `AllocRef::by_ref` to take `&self` instead of `&mut self` 2020-09-28 10:42:29 +02:00
Ralf Jung dc8414b607 fix building libstd for Miri on macOS 2020-09-28 10:32:05 +02:00
Joe Richey 37f795697c
libary: Forward compiler-builtins "mem" feature
This fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/53

Now users will be able to do:
```
cargo build -Zbuild-std=core -Zbuild-std-features=compiler-builtins-mem
```
and correctly get the Rust implemenations for `memcpy` and friends.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-27 20:31:06 -07:00
John Paul Adrian Glaubitz d25b0364e1 library/std: Set OS raw type definitions for sparc-unknown-linux-gnu 2020-09-28 00:39:57 +02:00
John Paul Adrian Glaubitz d9de08d65c library/std/sys_common: Define MIN_ALIGN for sparc-unknown-linux-gnu 2020-09-28 00:39:57 +02:00
John Paul Adrian Glaubitz 1fefba5e0b library/{panic_,}unwind: Add definitions for sparc-unknow-linux-gnu 2020-09-28 00:39:57 +02:00
Tomasz Miąsko 7d98d2207a Reopen standard streams when they are closed on Unix
The syscalls returning a new file descriptors generally use
lowest-numbered file descriptor not currently opened, without any
exceptions for those corresponding to the standard streams.

Previously when any of standard streams has been closed before starting
the application, operations on std::io::{stderr,stdin,stdout} objects
were likely to operate on other logically unrelated file resources
opened afterwards.

Avoid the issue by reopening the standard streams when they are closed.
2020-09-27 22:55:43 +02:00
Dylan MacKenzie 3cbd17fcc6 Remove `rustc_allow_const_fn_ptr`
This was a hack to work around the lack of an escape hatch for the "min
`const fn`" checks in const-stable functions. Now that we have co-opted
`allow_internal_unstable` for this purpose, we no longer need the
bespoke attribute.
2020-09-27 10:46:41 -07:00
Dylan MacKenzie 1ff143191c Add a feature gate for basic function pointer use in `const fn` 2020-09-27 10:46:41 -07:00
Joshua Nelson 406584621a Use relative links instead of intra-doc links
Previously, `BTreeMap` tried to link to `crate::collections`, intending
for the link to go to `std/collections/index.html`. But `BTreeMap` is
defined in `alloc`, so after the fix in the previous commit, the links
instead went to `alloc/collections/index.html`, which has almost no
information.

This changes it to link to `index.html`, which only works when viewing
from `std::collections::BTreeMap`, the most common place to visit the
docs. Fixing it to work from anywhere would require the docs for
`std::collections` to be duplicated in `alloc::collections`, which in
turn would require HashMap to be `alloc` for intra-doc links to work
(https://github.com/rust-lang/rust/issues/74481).
2020-09-27 11:28:13 -04:00
bors 1d216fef3e Auto merge of #77259 - dgbo:master, r=kennytm
update stdarch submodule

This commit update the src/stdarch submodule, we primarily want to include [https://github.com/rust-lang/stdarch/pull/918](url) which provides prefetch hints for aarch64. This PR could deliver ~20% performance gain on our aarch64 server in Filecoin. Wish this could be used as soon as possible.

Thanks.
2020-09-27 15:14:55 +00:00
Mara Bos de597fca40 Optimize set_{panic,print}(None). 2020-09-27 16:04:25 +02:00
Mara Bos ed3ead013f Relax memory ordering of LOCAL_STREAMS and document it. 2020-09-27 16:04:25 +02:00
Mara Bos 07fd17f701 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.
2020-09-27 16:04:25 +02:00
Dániel Buga 89b8a97aea Refactor memchr to allow optimization 2020-09-27 15:10:48 +02:00
Mara Bos 0b73fd7105 Move thread parker to sys_common. 2020-09-27 12:28:58 +02:00
Mara Bos 4301b5c1cc Add notes about memory ordering to futex parker implementation. 2020-09-27 11:56:43 +02:00
Mara Bos 485f882d77 Check conversion from Duration to timespec in futex_wait. 2020-09-27 11:56:43 +02:00
Mara Bos 2cf0f64722 Move linux-specific futex code into `sys` module. 2020-09-27 11:56:43 +02:00
Mara Bos 568d9696e9 Fix warning. 2020-09-27 11:56:43 +02:00
Mara Bos f18f93d44c Mark unpark() as #[inline]. 2020-09-27 11:56:43 +02:00
Mara Bos ec13df4ec4 Add fast futex-based thread parker for Linux. 2020-09-27 11:56:42 +02:00
Mara Bos 1464fc3a0c Move thread parker to a separate module. 2020-09-27 11:56:42 +02:00
Mara Bos 6f6336b4a1 Split sys_common::Mutex in StaticMutex and MovableMutex.
The (unsafe) Mutex from sys_common had a rather complicated interface.
You were supposed to call init() manually, unless you could guarantee it
was neither moved nor used reentrantly.

Calling `destroy()` was also optional, although it was unclear if 1)
resources might be leaked or not, and 2) if destroy() should only be
called when `init()` was called.

This allowed for a number of interesting (confusing?) different ways to
use this Mutex, all captured in a single type.

In practice, this type was only ever used in two ways:

1. As a static variable. In this case, neither init() nor destroy() are
   called. The variable is never moved, and it is never used
   reentrantly. It is only ever locked using the LockGuard, never with
   raw_lock.

2. As a Boxed variable. In this case, both init() and destroy() are
   called, it will be moved and possibly used reentrantly.

No other combinations are used anywhere in `std`.

This change simplifies things by splitting this Mutex type into
two types matching the two use cases: StaticMutex and MovableMutex.

The interface of both new types is now both safer and simpler. The first
one does not call nor expose init/destroy, and the second one calls
those automatically in its new() and Drop functions. Also, the locking
functions of MovableMutex are no longer unsafe.
2020-09-27 10:05:56 +02:00
Dong Bo 2e64ff9e6a fix redundant delarations of const_fn_transmute 2020-09-27 15:13:32 +08:00
Dong Bo 653fa5a7e6 update stdarch submodule 2020-09-27 13:41:08 +08:00
bors c9e5e6a53a Auto merge of #77154 - fusion-engineering-forks:lazy-stdio, r=dtolnay
Remove std::io::lazy::Lazy in favour of SyncOnceCell

The (internal) std::io::lazy::Lazy was used to lazily initialize the stdout and stdin buffers (and mutexes). It uses atexit() to register a destructor to flush the streams on exit, and mark the streams as 'closed'. Using the stream afterwards would result in a panic.

Stdout uses a LineWriter which contains a BufWriter that will flush the buffer on drop. This one is important to be executed during shutdown, to make sure no buffered output is lost. It also forbids access to stdout afterwards, since the buffer is already flushed and gone.

Stdin uses a BufReader, which does not implement Drop. It simply forgets any previously read data that was not read from the buffer yet. This means that in the case of stdin, the atexit() function's only effect is making stdin inaccessible to the program, such that later accesses result in a panic. This is uncessary, as it'd have been safe to access stdin during shutdown of the program.

---

This change removes the entire io::lazy module in favour of SyncOnceCell. SyncOnceCell's fast path is much faster (a single atomic operation) than locking a sys_common::Mutex on every access like Lazy did.

However, SyncOnceCell does not use atexit() to drop the contained object during shutdown.

As noted above, this is not a problem for stdin. It simply means stdin is now usable during shutdown.

The atexit() call for stdout is moved to the stdio module. Unlike the now-removed Lazy struct, SyncOnceCell does not have a 'gone and unusable' state that panics. Instead of adding this again, this simply replaces the buffer with one with zero capacity. This effectively flushes the old buffer *and* makes any writes afterwards pass through directly without touching a buffer, making print!() available during shutdown without panicking.

---

In addition, because the contents of the SyncOnceCell are no longer dropped, we can now use `&'static` instead of `Arc` in `Stdout` and `Stdin`. This also saves two levels of indirection in `stdin()` and `stdout()`, since Lazy effectively stored a `Box<Arc<T>>`, and SyncOnceCell stores the `T` directly.
2020-09-27 04:50:46 +00:00
Eric Huss c297e20e03 Add accessors to Command. 2020-09-26 18:58:38 -07:00
Jonas Schievink bb416f3a59
Rollup merge of #77184 - pickfire:patch-4, r=kennytm
Rust vec bench import specific rand::RngCore

Using `RngCore` import for side effects is clearer than `*` which may bring it unnecessary more stuff than needed, it is also more explicit doing so.

@pickfire change `LEN = 16384` (and pos) and `once` instead of `[0].iter()` after this.

@rustbot modify labels: +C-cleanup +A-testsuite
2020-09-27 01:53:22 +02:00
Jonas Schievink 5926c43743
Rollup merge of #77167 - fusion-engineering-forks:fix-fixme-min-max-sign-test, r=nagisa
Fix FIXME in core::num test: Check sign of zero in min/max tests.

r? nagisa

@rustbot modify labels: +C-cleanup
2020-09-27 01:53:20 +02:00
Jonas Schievink 9ab95c36e2
Rollup merge of #76917 - GuillaumeGomez:map-missing-code-examples, r=Dylan-DPC
Add missing code examples on HashMap types

r? @Dylan-DPC
2020-09-27 01:53:13 +02:00
Stein Somers 3e485d7cf5 BTreeMap: keep an eye out on the size of the main components 2020-09-26 20:07:48 +02:00
Ralf Jung 0a19836a81
Rollup merge of #77181 - GuillaumeGomez:add-pointer-alias, r=jyn514,pickfire
Add doc alias for pointer primitive
2020-09-26 12:58:28 +02:00
Ralf Jung 3b544e73ae
Rollup merge of #77122 - ecstatic-morse:const-fn-arithmetic, r=RalfJung,oli-obk
Add `#![feature(const_fn_floating_point_arithmetic)]`

cc #76618

This is a template for splitting up `const_fn` into granular feature gates. I think this will make it easier, both for us and for users, to track stabilization of each individual feature. We don't *have* to do this, however. We could also keep stabilizing things out from under `const_fn`.

cc @rust-lang/wg-const-eval
r? @oli-obk
2020-09-26 12:58:20 +02:00
Ralf Jung 31fd0ad69f
Rollup merge of #77076 - GuillaumeGomez:missing-code-examples-slice-iter, r=Dylan-DPC
Add missing code examples on slice iter types

r? @Dylan-DPC
2020-09-26 12:58:15 +02:00
Ralf Jung 1e62382a4f
Rollup merge of #75454 - ltratt:option_optimisation_guarantees, r=dtolnay
Explicitly document the size guarantees that Option makes.

Triggered by a discussion on wg-unsafe-code-guidelines about which layouts of `Option<T>` one can guarantee are optimised to a single pointer.

CC @RalfJung
2020-09-26 12:58:12 +02:00
Guillaume Gomez 21ee1716ee Add doc alias for pointer primitive 2020-09-26 11:21:24 +02:00
bors fd15e6180d Auto merge of #70743 - oli-obk:eager_const_to_pat_conversion, r=eddyb
Fully destructure constants into patterns

r? `@varkor`

as discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/constants.20in.20patterns/near/192789924

we should probably crater it once reviewed
2020-09-26 06:44:28 +00:00
Lzu Tao dce7248a39 Remove unneeded tidy comment 2020-09-26 05:20:53 +00:00
Lzu Tao 37cd79cd32 Gather all ZST structs of str together 2020-09-26 05:20:53 +00:00
Lzu Tao 653b5bf18c Move functions converting bytes to str to new mod 2020-09-26 05:20:53 +00:00
Lzu Tao 90c813a0f0 Move utf-8 validating helpers to new mod 2020-09-26 05:20:53 +00:00
Lzu Tao 5f0d724e29 Move str's impl of iterations to new mod 2020-09-26 05:20:51 +00:00
Lzu Tao 5b533fccf3 Move traits implementation of str to new mod
Also move FromStr trait
2020-09-26 05:04:58 +00:00
Lzu Tao d31ca4fc8e Move Utf8Error to new mod 2020-09-26 05:04:58 +00:00
bors 9e1c436178 Auto merge of #74225 - poliorcetics:std-thread-unsafe-op-in-unsafe-fn, r=joshtriplett
Std/thread: deny unsafe op in unsafe fn

Partial fix of #73904.

This encloses `unsafe` operations in `unsafe fn` in `libstd/thread`.
`@rustbot` modify labels: F-unsafe-block-in-unsafe-fn
2020-09-26 03:54:00 +00:00
Mara Bos f289468045 Stabilize slice_ptr_range.
Closes #65807.
2020-09-26 00:25:32 +02:00
bors 043f6d747c Auto merge of #77201 - matthewjasper:rename-get-unchecked, r=spastorino
Rename Iterator::get_unchecked

Closes #76479

r? `@pnkfelix`
2020-09-25 21:44:26 +00:00
Alexis Bourget a61b9638bb review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
Guillaume Gomez 980e1ff40f Add missing examples for Fd traits 2020-09-25 21:20:42 +02:00
Guillaume Gomez 187162e991 Add missing code examples on slice iter types 2020-09-25 21:17:22 +02:00
Matthew Jasper 04a0b1d087 Rename Iterator::get_unchecked
It's possible for method resolution to pick this method over a lower
priority stable method,  causing compilation errors. Since this method
is permanently unstable, give it a name that is very unlikely to be used
in user code.
2020-09-25 19:52:01 +01:00
Matthew Jasper 323a27967a Improve <vec::IntoIter>::get_unchecked` safety comment 2020-09-25 19:46:06 +01:00
Jonas Schievink d72b7cc329
Rollup merge of #77189 - pickfire:patch-5, r=Mark-Simulacrum
Remove extra space from vec drawing
2020-09-25 19:42:54 +02:00
Jonas Schievink a7bdf851cf
Rollup merge of #77176 - austinkeeley:intrinsics-documentatation-error, r=jyn514
Removing erroneous semicolon in transmute documentation

There is a semicolon in the example code that causes the expected value to not be returned.
2020-09-25 19:42:50 +02:00
Jonas Schievink 1149b308cd
Rollup merge of #77097 - fusion-engineering-forks:slice-ptr-range-const-fn, r=oli-obk
Make [].as_[mut_]ptr_range() (unstably) const.

Gated behind `const_ptr_offset`, as suggested by https://github.com/rust-lang/rust/issues/65807#issuecomment-697229404

This also marks `[].as_mut_ptr()` as const, because it's used by `as_mut_ptr_range`. I gated it behind the same feature, because I figured it's not worth adding a separate tracking issue for const `as_mut_ptr`.
2020-09-25 19:42:39 +02:00
Jonas Schievink e8dc07c242
Rollup merge of #77005 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BtreeMap: refactoring around edges

Parts chipped off a more daring effort, that the btree benchmarks judge to be performance-neutral.

r? @Mark-Simulacrum
2020-09-25 19:42:31 +02:00
Jonas Schievink 1b8c939a8d
Rollup merge of #76973 - lzutao:unstably-const-assume, r=oli-obk
Unstably allow assume intrinsic in const contexts

Not sure much about this usage because there are concerns
about [blocking  optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic
in inline functions.
But since Oli suggested in https://github.com/rust-lang/rust/issues/76960#issuecomment-695772221,
here we are.

[1]: https://github.com/rust-lang/rust/pull/54995#issuecomment-429302709
[2]: https://github.com/rust-lang/rust/issues/49572#issuecomment-589615423
2020-09-25 19:42:29 +02:00
Jonas Schievink a835af174c
Rollup merge of #76932 - fusion-engineering-forks:condvar-promise, r=sfackler
Relax promises about condition variable.

For quite a while now, there have been plans to at some point use parking_lot or some other more efficient implementation of mutexes and condition variables. Right now, Mutex and CondVar both Box the 'real' mutex/condvar inside, to give it a stable address. This was done because implementations like pthread and Windows critical sections may not be moved. More efficient implementations based on futexes, WaitOnAddress, Windows SRW locks, parking_lot, etc. may be moved (while not borrowed), so wouldn't need boxing.

However, not boxing them (which would be great goal to achieve), breaks a promise std currently makes about CondVar. CondVar promises to panic when used with different mutexes, to ensure consistent behaviour on all platforms. To this check, a mutex is considered 'the same' if the address of the 'real mutex' in the Box is the same. This address doesn't change when moving a `std::mutex::Mutex` object, effectively giving it an identity that survives moves of the Mutex object. If we ever switch to a non-boxed version, they no longer carry such an identity, and this check can no longer be made.

Four options:
1. Always box mutexes.
2. Add a `MutexId` similar to `ThreadId`. Making mutexes bigger, and making it hard to ever have a `const fn new` for them.
3. Making the requirement of CondVar stricter: panic if the Mutex object itself moved.
4. Making the promise of CondVar weaker: don't promise to panic.

1, 2, and 3 seem like bad options. This PR updates the documentation for 4.
2020-09-25 19:42:28 +02:00
Dylan MacKenzie 6a52c09440 Add new feature gate to standard library 2020-09-25 10:38:21 -07:00
Ivan Tham ea0065ad4f
Reposition iterator doc alias reduce before inline 2020-09-26 00:05:37 +08:00
Ivan Tham 1994cee61a
Add alias for iterator fold
fold is known in python and javascript as reduce,
not sure about inject but it was written in doc there.
2020-09-26 00:04:34 +08:00
follower e4943ac811
Link to documentation-specific guidelines.
Changed because it's not obvious how to get from the previously used URL to the documentation-specific content.

This is partly because the original URL was previously changed to point to different content:

 * https://github.com/rust-lang/rust/pull/74037/files#diff-242481015141f373dcb178e93cffa850L88

 * 3f6928f1f6 (diff-6a3371457528722a734f3c51d9238c13L12)
2020-09-26 03:26:45 +12:00
Ivan Tham 606ed2a076
Remove extra space from vec drawing 2020-09-25 23:20:22 +08:00
Ivan Tham 939fd37643
Rust vec bench import specific rand::RngCore 2020-09-25 22:19:28 +08:00
Stein Somers 55fa8afe94 BTreeMap: various tweaks 2020-09-25 11:29:39 +02:00
Stein Somers 3965524570 BTreeMap: introduce edge methods similar to those of keys and values 2020-09-25 11:29:38 +02:00
Stein Somers 1e64d98761 BTreeMap: refactor correct_childrens_parent_links 2020-09-25 11:29:38 +02:00
Austin Keeley 1d3717d17c Removing erroneous semicolon 2020-09-25 00:03:59 -04:00
Jonas Schievink fc4dc5f162
Rollup merge of #77164 - fusion-engineering-forks:no-more-funny-underscores, r=Mark-Simulacrum
Remove workaround for deref issue that no longer exists.

The double underscores were used to work around issue #12808, which was solved in 2016.
2020-09-25 02:29:51 +02:00
Jonas Schievink dc4f39c43f
Rollup merge of #77079 - poliorcetics:more-self-in-docs, r=jyn514
Use `Self` in docs when possible

Fixes #76542.

I used `rg '\s*//[!/]\s+fn [\w_]+\(&?self, ' .` in `library/` to find instances, I found some with that and some by manually checking.

@rustbot modify labels: C-enhancement T-doc
2020-09-25 02:29:42 +02:00
Jonas Schievink 09b0bd6022
Rollup merge of #77074 - lcnr:array-from-ref, r=SimonSapin
add array::from_ref

mirrors the methods in `std::slice` with the same name.

I guess this method previously didn't exist as there was close to no reason to create an array of size `1`.
This will change due to const generics in the near future.
2020-09-25 02:29:39 +02:00
Jonas Schievink 862faea4be
Rollup merge of #77050 - follower:patch-1, r=oli-obk
Typo fix: "satsify" -> "satisfy"
2020-09-25 02:29:37 +02:00
Jonas Schievink 67bcf04bdb
Rollup merge of #77044 - pickfire:patch-4, r=jyn514
Liballoc bench vec use mem take not replace
2020-09-25 02:29:35 +02:00
Jonas Schievink 452c86e3e1
Rollup merge of #76978 - duckymirror:mpsc-from-doc, r=jyn514
Documented From impls in std/sync/mpsc/mod.rs

This is for #51430.

r? @steveklabnik
2020-09-25 02:29:34 +02:00
Jonas Schievink 88e3693570
Rollup merge of #76304 - CDirkx:const-ip, r=ecstatic-morse
Make delegation methods of `std::net::IpAddr` unstably const

Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature:
 - `is_unspecified`
 - `is_loopback`
 - `is_global`
 - `is_multicast`

Also adds a test for these methods in a const context.

Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const ([PR#76205](https://github.com/rust-lang/rust/pull/76142) and [PR#76206](https://github.com/rust-lang/rust/pull/76206)), and the recent stabilization of const control flow.

Part of #76205

r? @ecstatic-morse
2020-09-25 02:29:30 +02:00
Mara Bos 74952b9f21 Fix FIXME in core::num test: Check sign of zero in min/max tests. 2020-09-24 22:29:32 +02:00
Mara Bos 13dc237037 Remove workaround for deref issue that no longer exists.
The double underscores were used to work around issue #12808, which was
solved in 2016.
2020-09-24 20:50:09 +02:00
Mara Bos 6f9c1323a7 Call ReentrantMutex::init() in stdout(). 2020-09-24 19:25:21 +02:00
Mara Bos 45700a9d58 Drop use of Arc from Stdin and Stdout. 2020-09-24 19:09:33 +02:00
Mara Bos bab15f773a Remove std::io::lazy::Lazy in favour of SyncOnceCell
The (internal) std::io::lazy::Lazy was used to lazily initialize the
stdout and stdin buffers (and mutexes). It uses atexit() to register a
destructor to flush the streams on exit, and mark the streams as
'closed'. Using the stream afterwards would result in a panic.

Stdout uses a LineWriter which contains a BufWriter that will flush the
buffer on drop. This one is important to be executed during shutdown,
to make sure no buffered output is lost. It also forbids access to
stdout afterwards, since the buffer is already flushed and gone.

Stdin uses a BufReader, which does not implement Drop. It simply forgets
any previously read data that was not read from the buffer yet. This
means that in the case of stdin, the atexit() function's only effect is
making stdin inaccessible to the program, such that later accesses
result in a panic. This is uncessary, as it'd have been safe to access
stdin during shutdown of the program.

---

This change removes the entire io::lazy module in favour of
SyncOnceCell. SyncOnceCell's fast path is much faster (a single atomic
operation) than locking a sys_common::Mutex on every access like Lazy
did.

However, SyncOnceCell does not use atexit() to drop the contained object
during shutdown.

As noted above, this is not a problem for stdin. It simply means stdin
is now usable during shutdown.

The atexit() call for stdout is moved to the stdio module. Unlike the
now-removed Lazy struct, SyncOnceCell does not have a 'gone and
unusable' state that panics. Instead of adding this again, this simply
replaces the buffer with one with zero capacity. This effectively
flushes the old buffer *and* makes any writes afterwards pass through
directly without touching a buffer, making print!() available during
shutdown without panicking.
2020-09-24 18:18:48 +02:00
Lzu Tao 382d7243a7 move test to intergrated test in library/core 2020-09-24 14:46:57 +00:00
bors 7b240a1262 Auto merge of #77083 - KodrAus:revert/const-type-id, r=RalfJung
revert const_type_id stabilization

This reverts #72488, which is currently on beta and scheduled to stabilize in `1.47.0`, based on https://github.com/rust-lang/rust/pull/75923#issuecomment-696676511

It turns out we might not be quite ready to stabilize `TypeId` in const contexts before having a chance to rework its internals. Since `TypeId` is a bit of an oddity we want to be careful about how those internals are currently being relied on while making changes. That will be easier to do without having to also consider compile-time contexts.

r? `@eddyb`
2020-09-24 00:43:09 +00:00
Ashley Mannix 0e2db57754 update tracking issue for const_type_id 2020-09-24 09:00:04 +10:00
bors c35177582b Auto merge of #77102 - Dylan-DPC:rollup-2jfrg3u, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #76898 (Record `tcx.def_span` instead of `item.span` in crate metadata)
 - #76939 (emit errors during AbstractConst building)
 - #76965 (Add cfg(target_has_atomic_equal_alignment) and use it for Atomic::from_mut.)
 - #76993 (Changing the alloc() to accept &self instead of &mut self)
 - #76994 (fix small typo in docs and comments)
 - #77017 (Add missing examples on Vec iter types)
 - #77042 (Improve documentation for ToSocketAddrs)
 - #77047 (Miri: more informative deallocation error messages)
 - #77055 (Add #[track_caller] to more panicking Cell functions)

Failed merges:

r? `@ghost`
2020-09-23 22:34:44 +00:00
Bastian Kauschke 5b3016134f use array::from_ref for slices 2020-09-23 21:56:23 +02:00
Christiaan Dirkx 947536fca0 Make delegation methods of `std::net::IpAddr` unstable const
Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature:
- `is_unspecified`
- `is_loopback`
- `is_global`
- `is_multicast`

Also adds a test for these methods in a const context.

Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const, and the recent stabilization of const control flow.

Part of #76205
2020-09-23 21:33:39 +02:00
bors a6008fac97 Auto merge of #77090 - rust-lang:revert-76110-convert-openoptions-cint, r=dtolnay
Revert "Function to convert OpenOptions to c_int"

Reverts rust-lang/rust#76110. This broke Rust's stability guarantees.

Closes https://github.com/rust-lang/rust/issues/77089.

r? `@joshtriplett`
2020-09-23 13:19:18 +00:00
Dylan DPC c3c03f2f05
Rollup merge of #77055 - est31:more_track_caller, r=Mark-Simulacrum
Add #[track_caller] to more panicking Cell functions

Continuation of #74526

Adds the #[track_caller] attribute to almost all panicking Cell
functions. The ones that borrow two Cells in their function
body are spared, because the panic location helps pinpoint
which of the two borrows failed. You'd need to have
full debuginfo and backtraces enabled together with column
info in order to be able to discern the cases.
Column info in debuginfo is only available on non-Windows platforms.
2020-09-23 14:54:15 +02:00
Dylan DPC 049ba0c6f0
Rollup merge of #77042 - imbolc:patch-2, r=kennytm
Improve documentation for ToSocketAddrs

I little clarification
2020-09-23 14:54:11 +02:00
Dylan DPC b76343643d
Rollup merge of #77017 - GuillaumeGomez:vec-missing-examples-iter, r=Dylan-DPC
Add missing examples on Vec iter types

r? @Dylan-DPC
2020-09-23 14:54:10 +02:00
Dylan DPC a40d79c9fb
Rollup merge of #76993 - blitzerr:alloc-ref, r=Amanieu
Changing the alloc() to accept &self instead of &mut self

Fixes: [#55](https://github.com/rust-lang/wg-allocators/issues/55)

This is the first cut. It only makes the change for `alloc` method.
2020-09-23 14:54:06 +02:00
Dylan DPC eaaf5d7e38
Rollup merge of #76965 - fusion-engineering-forks:fix-atomic-from-mut, r=Amanieu
Add cfg(target_has_atomic_equal_alignment) and use it for Atomic::from_mut.

Fixes some platform-specific problems with #74532 by using the actual alignment of the types instead of hardcoding a few `target_arch`s.

r? @RalfJung
2020-09-23 14:54:04 +02:00
Bastian Kauschke ed97b42105 add tracking issue 2020-09-23 13:48:21 +02:00
Mara Bos 631c688350 Make [].as_[mut_]ptr_range() (unstably) const. 2020-09-23 11:09:10 +02:00
blitzerr 2b19b14cec a few more &mut self -> self changes 2020-09-22 21:04:31 -07:00
Joshua Nelson 15f08d6ddf
Revert "Function to convert OpenOptions to c_int" 2020-09-22 23:07:30 -04:00
Ashley Mannix 9b2c8d866e revert const_type_id stabilization
This reverts commit e3856616ee.
2020-09-23 09:40:51 +10:00
Alexis Bourget ec4e9cd12a Use Self in alloc 2020-09-23 00:31:37 +02:00
Alexis Bourget 87a5dec4db Use Self more in core in doc when possible 2020-09-23 00:16:16 +02:00
Alexis Bourget b6e72837fd Use Self more in core/src/cmp.rs 2020-09-22 23:36:08 +02:00
Bastian Kauschke 179f63dafc add array from_ref 2020-09-22 21:35:43 +02:00
sharnoff 8a011b5da2 minor doc changes, attribute orderings 2020-09-22 19:34:05 +01:00
Dylan MacKenzie 110e59e70e Update library functions with stability attributes
This may not be strictly minimal, but all unstable functions also need a
`rustc_const_unstable` attribute.
2020-09-22 10:05:58 -07:00
Imbolc 4622ceb5e0
Update library/std/src/net/addr.rs
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-22 19:09:35 +03:00
Imbolc 5ab714fdfe
Update library/std/src/net/addr.rs
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-22 19:09:27 +03:00
est31 05c3a2b07d Add #[track_caller] to more panicking Cell functions
Continuation of #74526

Adds the #[track_caller] attribute to almost all panicking Cell
functions. The ones that borrow two Cells in their function
body are spared, because the panic location helps pinpoint
which of the two borrows failed. You'd need to have
full debuginfo and backtraces enabled together with column
info in order to be able to discern the cases.
Column info is only available on non-Windows platforms.
2020-09-22 15:34:22 +02:00
blitzerr 3ffd403c6b removing &mut self for other methods of AllocRef 2020-09-22 06:22:02 -07:00
bors e0bc267512 Auto merge of #76110 - FedericoPonzi:convert-openoptions-cint, r=JoshTriplett
Function to convert OpenOptions to c_int

Fixes: #74943
The creation_mode and access_mode function were already available in the OpenOptions struct, but currently private. I've added a new free functions to unix/fs.rs which takes the OpenOptions, and returns the c_int to be used as parameter for the `open` call.
2020-09-22 13:02:02 +00:00
Guillaume Gomez 143557ec56 Add missing examples on Vec iter types 2020-09-22 13:47:06 +02:00
Federico Ponzi 2f5192280f
enable unstable open_options_ext_as_flags feature in doc comments 2020-09-22 09:54:36 +01:00
follower 0082d201f1
Typo fix: "satsify" -> "satisfy" 2020-09-22 20:54:07 +12:00
Ivan Tham 4a6bc77a01
Liballoc bench vec use mem take not replace 2020-09-22 14:26:15 +08:00
Imbolc 2a40b63662
Update addr.rs
I little clarification
2020-09-22 09:15:53 +03:00
ecstatic-morse 537ede465f
Rollup merge of #76655 - CDirkx:const-pin, r=ecstatic-morse
Make some methods of `Pin` unstable const

Make the following methods unstable const under the `const_pin` feature:
- `new`
- `new_unchecked`
- `into_inner`
- `into_inner_unchecked`
- `get_ref`
- `into_ref`
- `get_mut`
- `get_unchecked_mut`

Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`.

Also adds tests for these methods in a const context.

Tracking issue: #76654

r? @ecstatic-morse
2020-09-21 20:40:49 -07:00
ecstatic-morse 65bdf79da3
Rollup merge of #76275 - FedericoPonzi:immutable-write-impl-73836, r=dtolnay
Implementation of Write for some immutable ref structs

Fixes  #73836
2020-09-21 20:40:44 -07:00
ecstatic-morse 4f3697b4b8
Rollup merge of #76150 - matklad:droporder, r=withoutboats
Don't recommend ManuallyDrop to customize drop order

See
https://internals.rust-lang.org/t/need-for-controlling-drop-order-of-fields/12914/21
for the discussion.

TL;DR: ManuallyDrop is unsafe and footguny, but you can just ask the compiler to do all the work for you by re-ordering declarations.

Specifically, the original example from the docs is much better written as

```rust
struct Peach;
struct Banana;
struct Melon;
struct FruitBox {
    melon: Melon,
    // XXX: mind the relative drop order of the fields below
    peach: Peach,
    banana: Banana,
}
```
2020-09-21 20:40:41 -07:00
ecstatic-morse 11f7bfab91
Rollup merge of #72734 - pickfire:liballoc, r=KodrAus
Reduce duplicate in liballoc reserve error handling

Not sure if it affects compilation time.
2020-09-21 20:40:37 -07:00
blitzerr 219003bd2e replaced cell::update with cell::[g|s]et 2020-09-21 16:55:07 -07:00
blitzerr 7e443a1ffc Added feature flag to use cell_update 2020-09-21 16:43:36 -07:00
blitzerr d9d02fa168 Changing the alloc() to accept &self instead of &mut self 2020-09-21 16:43:36 -07:00
Alexis Bourget d01bd19573 Fix missing unsafe block for target arch wasm32 2020-09-21 23:09:12 +02:00
Alexis Bourget 3afadaad4f Fix accordingly to review 2020-09-21 22:37:30 +02:00
Alexis Bourget 5d29954b2f Improve some SAFETY comments following suggestions 2020-09-21 22:37:30 +02:00
Alexis Bourget a83b79ec31 Finished documenting all unsafe op inside unsafe fn 2020-09-21 22:37:30 +02:00
Alexis Bourget 8c9cb06c2e Deny unsafe op in unsafe fns without the unsafe keyword, first part for std/thread 2020-09-21 22:37:29 +02:00
bors fb1dc34a83 Auto merge of #77003 - joshtriplett:remove-duplicate-link-libraries, r=Mark-Simulacrum
Remove duplicated library links between std and libc

The libc crate is already responsible for linking in the appropriate
libraries, and std doing the same thing results in duplicated library
names on the linker command line. Removing this duplication slightly
reduces linker time, and makes it simpler to adjust the set or order of
linked libraries in one place (such as to add static linking support).
2020-09-21 19:52:13 +00:00
Alexis Bourget 5be843fc54 Move format-ref-cell test 2020-09-21 21:50:27 +02:00
Alexis Bourget f6a4189d05 Move vec-cycle-wrapped test 2020-09-21 21:50:27 +02:00
Alexis Bourget 6bc0357dad Move vec-cycle test 2020-09-21 21:50:27 +02:00
Alexis Bourget 275eed7eb1 Move vec-slice-drop test 2020-09-21 21:50:27 +02:00
Alexis Bourget 8904921c1d Move array cycle test 2020-09-21 21:50:26 +02:00
Alexis Bourget ac39debeba Move panic safety traits tests 2020-09-21 21:50:26 +02:00
Alexis Bourget ed52c7bb75 Move deref-lval test 2020-09-21 21:50:26 +02:00
Alexis Bourget 949c96660c move format! interface tests 2020-09-21 21:50:26 +02:00
Alexis Bourget 85b2d9bf6f fmt 2020-09-21 21:50:26 +02:00
Alexis Bourget fc152cd67e move 'test zip ...' tests 2020-09-21 21:50:26 +02:00
Alexis Bourget af44a2a857 move 'cell does not clone' test 2020-09-21 21:50:25 +02:00
Alexis Bourget f69c5aa428 Move more tests using Cell to unit tests 2020-09-21 21:50:19 +02:00
Erik Hofmayer 16eee2a04a Applied review comments 2020-09-21 21:31:01 +02:00
Alexis Bourget 8aae1eee94 Move cell exterior test into library unit tests 2020-09-21 21:28:33 +02:00
Mara Bos 5d6f1a1e32 Move `use align_of` in atomic.rs into the places where it is used. 2020-09-21 20:44:45 +02:00
Mara Bos 7a04ff6c33 Gate Atomic::from_mut on cfg(target_has_atomic_equal_alignment).
Instead of a few hardcoded cfg(target_arch = ..) like before.
2020-09-21 20:43:44 +02:00
Mara Bos 668225d157 Revert "Revert adding Atomic::from_mut."
This reverts commit 5ef1db3622.
2020-09-21 20:43:44 +02:00
Ralf Jung fb3cb14af6
Rollup merge of #77009 - est31:dogfood_total_cmp, r=lcnr
Dogfood total_cmp in the test crate
2020-09-21 15:30:49 +02:00
Ralf Jung 4547ebb3fb
Rollup merge of #76983 - ssomers:btree_extra_test, r=Mark-Simulacrum
BTreeMap: extra testing & fixed comments

r? @Mark-Simulacrum
2020-09-21 15:30:46 +02:00
Ralf Jung 4b362bbbb6
Rollup merge of #76981 - pickfire:patch-5, r=Mark-Simulacrum
liballoc bench use imported path Bencher

test is already in scope, no need to use the full path
2020-09-21 15:30:44 +02:00
Ralf Jung b0c2eab66a
Rollup merge of #76967 - fusion-engineering-forks:revert-atomic-from-mut, r=kodrAus
Revert adding Atomic::from_mut.

This reverts #74532, which made too many assumptions about platforms, breaking some things.

Will need to be added later with a better way of gating on proper alignment, without hardcoding cfg(target_arch)s.

---

To be merged if fixing from_mut (#76965) takes too long.

r? @ghost
2020-09-21 15:30:41 +02:00
Ralf Jung ae4b677aa8
Rollup merge of #76521 - tavianator:fix-pthread-getattr-destroy, r=Amanieu
Fix segfault if pthread_getattr_np fails

glibc [destroys][1] the passed pthread_attr_t if pthread_getattr_np()
fails.  Destroying it again leads to a segfault.  Fix it by only
destroying it on success for glibc.

[1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_getattr_np.c;h=ce437205e41dc05653e435f6188768cccdd91c99;hb=HEAD#l205
2020-09-21 15:30:37 +02:00
Aleksey Kladov 60b102de06 Don't recommend ManuallyDrop to customize drop order
See
https://internals.rust-lang.org/t/need-for-controlling-drop-order-of-fields/12914/21
for the discussion.

TL;DR: ManuallyDrop is unsafe and footguny, but you can just ask the
compiler to do all the work for you by re-ordering declarations.
2020-09-21 14:00:04 +02:00
Guillaume Gomez be3d8e5d6c Add missing code examples on HashMap types 2020-09-21 13:32:03 +02:00
est31 9172e277f8 Dogfood total_cmp in the test crate 2020-09-21 12:15:30 +02:00
Ralf Jung f957aeef9f
Rollup merge of #76959 - est31:write, r=oli-obk
Replace write_fmt with write!

Latter is simpler
2020-09-21 10:40:41 +02:00
Ralf Jung 048866bd6b
Rollup merge of #76958 - est31:ns, r=oli-obk
Replace manual as_nanos and as_secs_f64 reimplementations
2020-09-21 10:40:39 +02:00
Ralf Jung b670b86353
Rollup merge of #76936 - danielhenrymantilla:unsafecell_get_mut, r=RalfJung
Add non-`unsafe` `.get_mut()` for `Unsafecell`

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

As discussed in: https://internals.rust-lang.org/t/add-non-unsafe-get-mut-for-unsafecell/12407

  - ### [Rendered documentation](https://modest-dubinsky-1f9f47.netlify.app/core/cell/struct.unsafecell)

This PR tries to move the sound `&mut UnsafeCell<T> -> &mut T` projection that all the "downstream" constructions were already relying on, up to the root abstraction, where it rightfully belongs, and officially blessing it.

  - this **helps reduce the amount of `unsafe` snippets out there** (_c.f._, the second commit of this PR: 09503fd1b3)

The fact that this getter is now expose for `UnsafeCell<T>` itself, will also help convey the idea that **`UnsafeCell` is not magical _w.r.t._ `&mut` accesses**, contrary to what some people incorrectly think.

  - Even the standard library itself at some point had such a confusion, _c.f._ this comment where there is a mention of multi-threaded (and thus _shared_) access despite dealing with exclusive references over unique ownership: 59fb88d061/library/core/src/cell.rs (L498-L499)

r? @RalfJung
2020-09-21 10:40:37 +02:00
Ralf Jung 9e2ebf31dd
Rollup merge of #76868 - poliorcetics:intra-doc-std-sync, r=jyn514
Finish moving to intra doc links for std::sync

Helps with #75080.

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

r? @jyn514
2020-09-21 10:40:33 +02:00
Ralf Jung 5031242606
Rollup merge of #76867 - poliorcetics:intra-doc-core-iter, r=jyn514
Use intra-doc links in core/src/iter when possible

Helps with #75080.

I also updated lots of links to use `fn()` instead of `fn` when possible.

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

r? @jyn514
2020-09-21 10:40:32 +02:00
Ralf Jung c3abb82908
Rollup merge of #76135 - CDirkx:const-option, r=dtolnay,oli-obk
Stabilize some Option methods as const

Stabilize the following methods of `Option` as const:
 - `is_some`
 - `is_none`
 - `as_ref`

These methods are currently const under the unstable feature `const_option` (tracking issue: #67441).
I believe these methods to be eligible for stabilization because of the stabilization of #49146 (Allow if and match in constants) and the trivial implementations, see also:  [PR#75463](https://github.com/rust-lang/rust/pull/75463).

Related: #76225
2020-09-21 10:40:26 +02:00
Josh Triplett f9457fb809 Remove duplicated library links between std and libc
The libc crate is already responsible for linking in the appropriate
libraries, and std doing the same thing results in duplicated library
names on the linker command line. Removing this duplication slightly
reduces linker time, and makes it simpler to adjust the set or order of
linked libraries in one place (such as to add static linking support).
2020-09-21 01:37:15 -07:00
Federico Ponzi 0acb0ed184
Update library/std/src/process.rs
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-09-21 08:12:40 +01:00
Federico Ponzi 88a29e630c
Updates stability attributes to the current nightly version 2020-09-21 08:52:59 +02:00
bors a409a233e0 Auto merge of #75974 - SkiFire13:peekmut-opt-sift, r=LukasKalbertodt
Avoid useless sift_down when std::collections::binary_heap::PeekMut is never mutably dereferenced

If `deref_mut` is never called then it's not possible for the element to be mutated without internal mutability, meaning there's no need to call `sift_down`.

This could be a little improvement in cases where you want to mutate the biggest element of the heap only if it satisfies a certain predicate that needs only read access to the element.
2020-09-21 05:31:01 +00:00
bors 0f9f0b384a Auto merge of #76295 - mati865:remove-mmx, r=Amanieu,oli-obk
Remove MMX from Rust

Follow-up to https://github.com/rust-lang/stdarch/pull/890
This removes most of MMX from Rust (tests pass with small changes), keeping stable `is_x86_feature_detected!("mmx")` working.
2020-09-21 00:43:26 +00:00
Christiaan Dirkx 4f859fbcfc Move const tests for `Option` to `library\core`
Part of #76268
2020-09-20 22:42:14 +02:00
CDirkx 9486f72879 Stabilize some Option methods as const
Stabilize the following methods of `Option` as const:
 - `is_some`
 - `is_none`
 - `as_ref`

Possible because of stabilization of #49146 (Allow if and match in constants).
2020-09-20 22:42:14 +02:00
Stein Somers 37ec045850 BTreeMap: extra testing unveiling mistakes in future PR 2020-09-20 20:07:05 +02:00
Ivan Tham d99bb9d31c
liballoc bench use imported path Bencher
test is already in scope, no need to use the full path
2020-09-21 00:46:40 +08:00
Alexis Bourget aaddcdb0d0 Fix nits 2020-09-20 18:37:05 +02:00
Daniel Henry-Mantilla 5886c38112 Replace unneeded `unsafe` calls to `.get()` with calls to `.get_mut()` 2020-09-20 18:06:03 +02:00
Daniel Henry-Mantilla 8169989507 Add non-`unsafe` `.get_mut()` for `UnsafeCell`
Update the tracking issue number

Updated the documentation for `UnsafeCell`

Address review comments

Address more review comments + minor changes
2020-09-20 18:05:31 +02:00
Alexis Bourget 08b85a6fc8 use iter:: before free functions 2020-09-20 18:04:12 +02:00
bors 81e02708f1 Auto merge of #76975 - RalfJung:rollup-s2wiuqr, r=RalfJung
Rollup of 15 pull requests

Successful merges:

 - #76732 (Add docs for `BasicBlock`)
 - #76832 (Let backends define custom targets)
 - #76866 (Remove unused feature gates from library/ crates)
 - #76875 (Move to intra-doc links in library/alloc/src/collections/binary_heap.rs)
 - #76876 (Move to intra-doc links in collections/btree/map.rs and collections/linked_list.rs)
 - #76877 (Move to intra-doc links in collections/vec_deque.rs and collections/vec_deque/drain.rs)
 - #76878 (Move the version number to a plaintext file)
 - #76883 (README.md: Remove prompts from code blocks)
 - #76887 (Add missing examples on HashSet iter types)
 - #76890 (use matches!() macro for simple if let conditions)
 - #76891 (don't take `TyCtxt` by reference)
 - #76910 (transmute: use diagnostic item)
 - #76924 (Add tracking issue for feature(unix_socket_peek))
 - #76926 (BTreeMap: code readability tweaks)
 - #76940 (Don't allow implementing trait directly on type-alias-impl-trait)

Failed merges:

r? `@ghost`
2020-09-20 15:12:40 +00:00
Hoe Hao Cheng 3c582db8cb Implement as_ne_bytes for floats and integers 2020-09-20 22:20:06 +08:00
Tim Vermeulen ecacc7534b Add advance_by and advance_back_by 2020-09-20 16:14:43 +02:00
Lzu Tao 4387480dea Add unstably const support for assume intrinsic 2020-09-20 14:00:40 +00:00
Ralf Jung 0a4eb2c31d
Rollup merge of #76926 - ssomers:btree_cleanup_1, r=Mark-Simulacrum
BTreeMap: code readability tweaks

Gathered over the past months

r? @Mark-Simulacrum
2020-09-20 15:52:07 +02:00
Ralf Jung dfae12fa0b
Rollup merge of #76924 - rijenkii:patch-1, r=oli-obk
Add tracking issue for feature(unix_socket_peek)

Feature was added in #73761
2020-09-20 15:52:06 +02:00
Ralf Jung 7ff17c13bc
Rollup merge of #76910 - lcnr:foreign-item-like, r=oli-obk
transmute: use diagnostic item

closes #66075, we now have no remaining uses of `match_def_path`  in the compiler while some uses still remain in `clippy`.

cc @RalfJung
2020-09-20 15:52:04 +02:00
Ralf Jung f24d279084
Rollup merge of #76887 - GuillaumeGomez:hashset-iter-types-examples, r=Dylan-DPC
Add missing examples on HashSet iter types
2020-09-20 15:51:59 +02:00
Ralf Jung ad9ea71e7f
Rollup merge of #76877 - denisvasilik:intra-doc-links-alloc-vec-deque, r=jyn514
Move to intra-doc links in collections/vec_deque.rs and collections/vec_deque/drain.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 15:51:54 +02:00
Ralf Jung 39412011a1
Rollup merge of #76876 - denisvasilik:intra-doc-links-alloc, r=jyn514
Move to intra-doc links in collections/btree/map.rs and collections/linked_list.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 15:51:53 +02:00
Ralf Jung 61a754832e
Rollup merge of #76875 - denisvasilik:intra-doc-links-alloc-binary-heap, r=jyn514
Move to intra-doc links in library/alloc/src/collections/binary_heap.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 15:51:51 +02:00
Ralf Jung bea0ae700e
Rollup merge of #76866 - est31:master, r=lcnr
Remove unused feature gates from library/ crates

Removes some unused feature gates from library crates. It's likely not a complete list as I only tested a subset for which it's more likely that it is unused.
2020-09-20 15:51:50 +02:00
Erik Hofmayer 3f0f40904c Documented From impls in std/sync/mpsc/mod.rs 2020-09-20 15:50:44 +02:00
Lzu Tao 3e08354fb0 Correct file path after some restructures in compiler 2020-09-20 13:48:16 +00:00
Mateusz Mikuła 5de2c95e6e Remove MMX from Rust 2020-09-20 15:13:11 +02:00
bors b873fa6d42 Auto merge of #76136 - CDirkx:const-result, r=dtolnay
Stabilize some Result methods as const

Stabilize the following methods of Result as const:
 - `is_ok`
 - `is_err`
 - `as_ref`

A test is also included, analogous to the test for `const_option`.

These methods are currently const under the unstable feature `const_result` (tracking issue: #67520).
I believe these methods to be eligible for stabilization because of the stabilization of #49146 (Allow if and match in constants) and the trivial implementations, see also: [PR#75463](https://github.com/rust-lang/rust/pull/75463) and [PR#76135](https://github.com/rust-lang/rust/pull/76135).

Note: these methods are the only methods currently under the `const_result` feature, thus this PR results in the removal of the feature.

Related: #76225
2020-09-20 13:07:11 +00:00
Without Boats 35b30e29bf try again to appease tidy 2020-09-20 14:38:59 +02:00
Without Boats 3fe279fc65 spend another CI build to delete a double newline 2020-09-20 14:04:23 +02:00
Without Boats acc136ce0a fix typos 2020-09-20 13:32:49 +02:00
Oliver Scherer b2532a8730 Implement destructuring for all aggregates and for references 2020-09-20 13:28:18 +02:00
Without Boats 82f5928ca6 Make RawFd implement the RawFd traits 2020-09-20 13:21:42 +02:00
Mara Bos 5ef1db3622 Revert adding Atomic::from_mut.
This made too many assumptions about platforms, breaking some things.

Will need to be added later with a better way of gating on proper
alignment, without hardcoding cfg(target_arch)s.
2020-09-20 12:54:37 +02:00
Ralf Jung e5be14c272
Rollup merge of #76871 - RalfJung:miri-panic-abort, r=dtolnay
support panic=abort in Miri

This is needed for https://github.com/rust-lang/miri/issues/1058 on Windows: we cannot run the inline-assembly versions of `abort`, so fall back to the intrinsic (which Miri supports).
2020-09-20 12:08:36 +02:00
Ralf Jung 70f55a78a3
Rollup merge of #76853 - denisvasilik:intra-doc-links-core-wake, r=jyn514
Use intra-doc links in library/core/src/task/wake.rs

Helps with #75080.

@rustbot modify labels: T-doc, A-intra-doc-links
2020-09-20 12:08:34 +02:00
Ralf Jung 6d0890ec83
Rollup merge of #76845 - Amjad50:fix-intra-docs-links, r=jyn514
Use intra docs links in core::{ascii, option, str, pattern, hash::map}

Partial fix for #75080

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

r? @jyn514
2020-09-20 12:08:33 +02:00
Ralf Jung a8151840ef
Rollup merge of #76840 - poliorcetics:intra-doc-core-sync-and-future, r=jyn514
Move to intra doc links in core/src/future

Helps with #75080.

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

r? @jyn514
2020-09-20 12:08:31 +02:00
Ralf Jung c124d4363d
Rollup merge of #76827 - lcnr:array_windows-docs, r=jonas-schievink
fix array_windows docs

r? @Dylan-DPC
2020-09-20 12:08:27 +02:00
Ralf Jung df4e4ef2b9
Rollup merge of #76823 - RalfJung:black-box-warn, r=joshtriplett
black_box: silence unused_mut warning when building with cfg(miri)
2020-09-20 12:08:24 +02:00
Ralf Jung f5e19a355a
Rollup merge of #76722 - ssomers:btree_send_sync, r=Mark-Simulacrum
Test and fix Send and Sync traits of BTreeMap artefacts

Fixes #76686.

I'm not quite sure what all this implies. E.g. comparing with the definitions for `NodeRef` in node.rs,  maybe an extra bound `T: 'a` is useful for something. The test compiles on stable/beta (apart from `drain_filter`) so I bet `Sync` is equally desirable.

r? @Mark-Simulacrum
2020-09-20 12:08:12 +02:00
est31 4bc0e55ac4 Replace write_fmt with write!
Latter is simpler
2020-09-20 10:35:23 +02:00
est31 cebbd9fcd3 Use as_nanos in bench.rs and base.rs 2020-09-20 10:16:01 +02:00
est31 562422ecf7 Remove some unused features from alloc core and std 2020-09-20 04:29:11 +02:00
Giacomo Stevanato ca15e9d8a1 Fix time complexity in BinaryHeap::peek_mut docs 2020-09-20 01:12:02 +02:00
Giacomo Stevanato af1e3633f7 Set sift=true only when PeekMut yields a mutable reference 2020-09-20 01:12:02 +02:00
Giacomo Stevanato 924cd135b6 Added benchmarks for BinaryHeap 2020-09-20 01:12:02 +02:00
Denis Vasilik f9fa649545 Use intra-doc links 2020-09-19 23:30:52 +02:00
bors f68e08933d Auto merge of #76929 - ssomers:btree_cleanup_2, r=Mark-Simulacrum
BTreeMap: wrap node's raw parent pointer in NonNull

Now that the other `*const` (root) is gone, seemed like a small step forward.

r? `@Mark-Simulacrum`
2020-09-19 19:15:06 +00:00
Stein Somers 0661b0a36d BTreeMap: wrap node's raw parent pointer in NonNull 2020-09-19 19:02:42 +02:00
Mara Bos 26d6081f1d Relax promises about condition variable.
This allows for futex or thread parking based implementations in the
future.
2020-09-19 18:48:39 +02:00
Stein Somers c6a8cfbde8 BTreeMap: code readability tweaks 2020-09-19 17:08:43 +02:00
Lzu Tao a50ec5f144 Remove outdated ignored tidy comment 2020-09-19 15:01:51 +00:00
Lzu Tao 3ee724e610 Move (u)int_impl macros to their own files 2020-09-19 15:01:49 +00:00
rijenkii a60f97849b
Add tracking issue for feature(unix_socket_peek) 2020-09-19 21:55:01 +07:00
Lzu Tao a54584319e Move dummy integer modules (like core::u32) to shells dir 2020-09-19 14:54:20 +00:00
Lzu Tao 550939f654 Move error structs to new mod 2020-09-19 14:54:20 +00:00
Lzu Tao 7125a481ce Move Wrapping<T> definition to wrapping mod 2020-09-19 14:54:20 +00:00
Lzu Tao baecad9c39 Move NonZero* to its file 2020-09-19 14:54:20 +00:00
Ralf Jung b4c3f409af
Rollup merge of #76798 - alistair23:alistair/rv32-linux, r=jyn514
Build fixes for RISC-V 32-bit Linux support

This fixes build issues with the 32-bit RISC-V port.
2020-09-19 11:47:56 +02:00
Ralf Jung 46bb884cf3
Rollup merge of #76525 - fusion-engineering-forks:string-drain, r=dtolnay
Add as_str() to string::Drain.

Vec's Drain recently [had its `.as_slice()` stabilized](https://github.com/rust-lang/rust/pull/72584), but String's Drain was still missing the analogous `.as_str()`. This adds that.

Also improves the Debug implementation, which now shows the remaining data instead of just `"Drain { .. }"`.
2020-09-19 11:47:47 +02:00
Ralf Jung fef3324043
Rollup merge of #76492 - fusion-engineering-forks:int-bits, r=dtolnay
Add associated constant `BITS` to all integer types

Recently I've regularly come across this snippet (in a few different crates, including `core` and `std`):
```rust
std::mem::size_of<usize>() * 8
```

I think it's time for a `usize::BITS`.
2020-09-19 11:47:45 +02:00
Ralf Jung 1720fd94e8
Rollup merge of #76434 - RalfJung:black-box, r=Mark-Simulacrum
do not inline black_box when building for Miri

We cannot do the assembly trick in Miri, but let's at least make sure MIR inlining does not circumvent the black_box.

Also use black_box instead of local optimization barriers in a few const tests.
2020-09-19 11:47:43 +02:00
Ralf Jung 67fa7b78a4
Rollup merge of #76400 - pickfire:patch-5, r=dtolnay
Clean up vec benches bench_in_place style
2020-09-19 11:47:41 +02:00
Ralf Jung bac2f39350
Rollup merge of #76310 - scottmcm:array-try_from-vec, r=dtolnay
Add `[T; N]: TryFrom<Vec<T>>` (insta-stable)

This is very similar to the [existing](https://doc.rust-lang.org/nightly/std/convert/trait.TryFrom.html#impl-TryFrom%3CBox%3C%5BT%5D%3E%3E) `Box<[T; N]>: TryFrom<Box<[T]>>`, but allows avoiding the `shrink_to_fit` if you have a vector and not a boxed slice.

Like the slice equivalents of this, it fails if the length of the vector is not exactly `N`.
This uses `Vec<T>` as the `Error` type to return the input, like how the `Rc<[T]> -> Rc<[T; N]>` (and Arc) ones also reflect the input directly in the error type.

```rust
#[stable(feature = "array_try_from_vec", since = "1.47.0")]
impl<T, const N: usize> TryFrom<Vec<T>> for [T; N] {
    type Error = Vec<T>;
    fn try_from(mut vec: Vec<T>) -> Result<[T; N], Vec<T>>;
}
```

Inspired by this zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/APIs.20for.20getting.20stuff.20from.20a.20Vec.20by.20owned/near/209048103
2020-09-19 11:47:39 +02:00
Ralf Jung 44be933ff7
Rollup merge of #73963 - hellow554:unsafe_path, r=Mark-Simulacrum
deny(unsafe_op_in_unsafe_fn) in libstd/path.rs

The libstd/path.rs part of #73904 . Wraps the two calls to an unsafe fn Initializer::nop() in an unsafe block.
2020-09-19 11:47:31 +02:00
Bastian Kauschke 39f125918d cfg bootstrap 2020-09-19 11:33:11 +02:00
Bastian Kauschke 4debbdc6b9 transmute: use diagnostic item 2020-09-19 11:33:11 +02:00
Mara Bos 15eb638dc9 Add tracking issue number for string_drain_as_str. 2020-09-19 08:23:23 +02:00
Mara Bos 1bfe5efe8f Add tracking issue number for int_bits_const. 2020-09-19 08:14:41 +02:00
Mara Bos 1e2dba1e7c Use `T::BITS` instead of `size_of::<T> * 8`. 2020-09-19 06:54:42 +02:00
Mara Bos 5c30a16fa0 Add example/test to <int types>::BITS. 2020-09-19 06:50:45 +02:00
Mara Bos 3f68ae47df Add `BITS` associated constant to all integer types. 2020-09-19 06:50:45 +02:00
bors c6ab8e5fe0 Auto merge of #76787 - lzutao:slice_iters_new, r=lcnr
Using <Iter>::new instead of exposing internal fields

As requested in https://github.com/rust-lang/rust/pull/76311#discussion_r487685126
2020-09-18 23:38:17 +00:00
Guillaume Gomez 28588e5df1 Add missing examples on HashSet iter types 2020-09-18 20:09:31 +02:00
dylni f055b0bb08 Rename method to `assert_len` 2020-09-18 13:55:03 -04:00
Christiaan Dirkx e3c6e46168 Make some methods of `Pin<&mut T>` unstable const
Make the following methods unstable const under the `const_pin` feature:
- `into_ref`
- `get_mut`
- `get_unchecked_mut`
2020-09-18 19:23:50 +02:00
dylni eb63168e00 Fix doctests 2020-09-18 13:05:54 -04:00
dylni 1095dcab96 Fix links 2020-09-18 12:39:10 -04:00
dylni 1ff7da6551 Move `slice::check_range` to `RangeBounds` 2020-09-18 12:17:51 -04:00
Denis Vasilik 719c40cb5a
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:44 +02:00
Denis Vasilik 62e0ee1ba0
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:35 +02:00
Denis Vasilik ec7225feac
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:23 +02:00
Denis Vasilik 2230d8d14c
Update library/alloc/src/collections/binary_heap.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 16:45:13 +02:00
Ralf Jung 0810c3ef19 support panic=abort in Miri 2020-09-18 13:15:54 +02:00
Denis Vasilik 49c8fcb47e Use intra-doc links 2020-09-18 12:38:37 +02:00
Denis Vasilik 4af1b90b41 Move to intra-doc links 2020-09-18 12:38:25 +02:00
Alexis Bourget b534d9f6e1 Fix broken link 2020-09-18 12:32:23 +02:00
Alexis Bourget 982ec0d0c9 Fix broken link 2020-09-18 11:14:36 +02:00
Alexis Bourget bffd2111f7 Finish moving to intra doc links for std::sync 2020-09-18 11:09:36 +02:00
Denis Vasilik bdb039d10b Use intra-doc links 2020-09-18 10:50:04 +02:00
Lzu Tao b65937031d inline inner function of inlining methods 2020-09-18 08:36:21 +00:00
Lzu Tao 53d5261c69 Move unsafe code of slice `new` function of their Iterator structs
Init false state in Split* constructors
2020-09-18 08:36:21 +00:00
Poliorcetics 4c92b3dc7d
Apply suggestions from code review
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-18 09:52:35 +02:00
Alexis Bourget 4675a3104b Use intra-doc links in core/src/iter when possible 2020-09-18 09:51:26 +02:00
est31 baafc71f1f Remove unused libc feature gate
Libc isn't used by alloc.
And std and panic_* use libc from crates.io now,
which isn't feature gated.
2020-09-18 08:59:43 +02:00
bors a0925fba74 Auto merge of #76790 - ssomers:btree_slice_slasher_returns, r=Mark-Simulacrum
BTreeMap: avoid slices even more

Epilogue to #73971: it seems the compiler is unable to realize that creating a slice and `get_unchecked`-ing one element is a simple fetch. So try to spell it out for the only remaining but often invoked case.

Also, the previous code doesn't seem fair game to me, using `get_unchecked` to reach beyond the end of a slice. Although the local function `slice_insert` also does that.

r? `@Mark-Simulacrum`
2020-09-18 05:47:00 +00:00
Amjad Alsharafi 878dfa6718 Fixed intra-docs links in library/std/src/collections/hash/map.rs 2020-09-18 07:50:22 +08:00
Amjad Alsharafi 3323a26144 Fixed some intra-docs links in library/core 2020-09-18 07:49:29 +08:00
Denis Vasilik 8e9ad31178 Use intra-doc links 2020-09-17 22:43:13 +02:00
bors f3c923a13a Auto merge of #76645 - fusion-engineering-forks:windows-lock, r=kennytm
Small cleanups in Windows Mutex.

 - Move `held` into the boxed part, since the SRW lock implementation does not use this. This makes the Mutex 50% smaller.
 - Use `Cell` instead of `UnsafeCell` for `held`, such that `.replace()` can be used.
 - Add some comments.
 - Avoid creating multiple `&mut`s to the critical section object in `ReentrantMutex`.
2020-09-17 19:23:58 +00:00
Alexis Bourget 76ec3f8d2b Move to intra doc links in core/src/future 2020-09-17 17:25:06 +02:00
Alistair Francis 3d1b6d6cc2 library/unwind: Add missing )
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-17 07:10:10 -07:00
Ralf Jung 1dd3df6738 black_box: silence unused_mut warning when building with cfg(miri) 2020-09-17 14:39:31 +02:00
Lzu Tao 9fe9c6da3e Using <Iter>::new instead of exposing internal fields 2020-09-17 09:58:26 +00:00
Bastian Kauschke 764d307963
docs `array` -> `slice`
Co-authored-by: est31 <est31@users.noreply.github.com>
2020-09-17 10:30:28 +02:00
Bastian Kauschke 5f58e00ca5 fix array_windows docs 2020-09-17 09:53:19 +02:00
Alistair Francis 57b2da808c library/unwind: Consolidate RV32 and RV64
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 15:19:32 -07:00
Alistair Francis fd76268166 library/panic_unwind: Consolidate RV32 and RV64
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 14:31:42 -07:00
Tyler Mandry d3c63213a0
Rollup merge of #76778 - pickfire:patch-7, r=jonas-schievink
Simplify iter fuse struct doc
2020-09-16 12:24:28 -07:00
Tyler Mandry 273267c9ee
Rollup merge of #76759 - yoshuawuyts:fix-future-pending-ready-stabilization-label, r=Dylan-DPC
Fix stabilization marker for future_readiness_fns

Updated the rustc version in which this will be stabilized from `1.47.0 -> 1.48.0`. Fixes https://github.com/rust-lang/rust/pull/74328#issuecomment-692133125. Ref #70921.

r? @Dylan-DPC
2020-09-16 12:24:21 -07:00
Tyler Mandry ab207743af
Rollup merge of #76758 - adamlesinski:clone_clock, r=tmandry
[fuchsia] Propagate the userspace UTC clock

On Fuchsia, spawning a subprocess does not automatically
clone all of the parent process' capabilities. UTC time on
Fuchsia is managed by a top-level userspace clock capability
that is cloned and passed to subprocesses.

This change ensures that any Rust subprocess gets access to the
UTC clock, if the parent had access to it. This is critical for
tests, which on Fuchsia, use panic=abort and spawn subprocesses
per test.
2020-09-16 12:24:19 -07:00
Tyler Mandry ab78ca92f3
Rollup merge of #76747 - GuillaumeGomez:more-missing-libcore-code-examples, r=Mark-Simulacrum
Add missing code examples in libcore
2020-09-16 12:24:16 -07:00
Tyler Mandry 153fb91d37
Rollup merge of #76721 - camelid:intra-doc-links-for-core-mem, r=jyn514
Use intra-doc links in `core::mem`

Part of #75080.

Last one for now!

---

@rustbot modify labels: A-intra-doc-links T-doc
2020-09-16 12:24:08 -07:00
Tyler Mandry 23a677787e
Rollup merge of #75026 - JulianKnodt:array_windows, r=Amanieu
Add array_windows fn

This mimicks the functionality added by array_chunks, and implements a const-generic form of
`windows`. It makes egregious use of `unsafe`, but by necessity because the array must be
re-interpreted as a slice of arrays, and unlike array_chunks this cannot be done by casting the
original array once, since each time the index is advanced it needs to move one element, not
`N`.

I'm planning on adding more tests, but this should be good enough as a premise for the functionality.
Notably: should there be more functions overwritten for the iterator implementation/in general?

~~I've marked the issue as #74985 as there is no corresponding exact issue for `array_windows`, but it's based of off `array_chunks`.~~

Edit: See Issue #75027 created by @lcnr for tracking issue

~~Do not merge until I add more tests, please.~~

r? @lcnr
2020-09-16 12:24:03 -07:00
Mara Bos 0bb96e7490 Avoid creating `&mut`s in Windows ReentrantMutex. 2020-09-16 21:16:32 +02:00
Mara Bos 3fadc603ab Don't use `mut` in Windows Mutex. 2020-09-16 21:09:53 +02:00
Federico Ponzi 70292d4506
Sets as_flags as unstable 2020-09-16 19:40:44 +02:00
Alistair Francis 0f3ccbd662 library/unwind: Add support for RISC-V 32-bit
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 08:45:49 -07:00
Alistair Francis cf075355da library/std: sys_common: Add support for RISC-V 32-bit
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 08:45:08 -07:00
Alistair Francis cd066c9deb library/std: raw: Add support for RISC-V 32-bit
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 08:44:35 -07:00
Alistair Francis 84fe26c4d3 library/std: linux: Add support for RISC-V 32-bit
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 08:43:54 -07:00
Alistair Francis de0d55cb3c library/panic_unwind: Add UNWIND_DATA_REG for RISC-V 32-bit
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2020-09-16 08:42:55 -07:00
kadmin f240abc1dc Add array window fn
Updated issue to #75027

Update to rm oob access

And hopefully fix docs as well

Fixed naming conflict in test

Fix test which used 1-indexing

Nth starts from 0, woops

Fix a bunch of off by 1 errors

See https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=757b311987e3fae1ca47122969acda5a

Add even more off by 1 errors

And also write `next` and `next_back` in terms of `nth` and `nth_back`.

Run fmt

Fix forgetting to change fn name in test

add nth_back test & document unsafe

Remove as_ref().unwrap()
Documented occurrences of unsafe, noting what invariants are maintained
2020-09-16 14:52:20 +00:00
Dylan DPC 9524fffce3
Rollup merge of #76707 - pickfire:patch-4, r=jonas-schievink
Simplify iter flatten struct doc
2020-09-16 12:34:23 +02:00
Dylan DPC d1b050476d
Rollup merge of #76669 - lzutao:core_asm, r=Amanieu
Prefer asm! over llvm_asm! in core

Replace llvm_asm! with asm! in core.

x86 asm compare (in somecases I replaced generic type with String).
* https://rust.godbolt.org/z/59eEMv
* https://rust.godbolt.org/z/v78s6q
* https://rust.godbolt.org/z/7qYY41
2020-09-16 12:34:11 +02:00
Lzu Tao 4dc4e9f671 Fix black_box bug detected by Amanieu
Co-authored-by: Amanieu <amanieu@gmail.com>
2020-09-16 09:25:54 +00:00
Ralf Jung 9d0a265b6c
Rollup merge of #76662 - RalfJung:lib-test-miri, r=Mark-Simulacrum
Fix liballoc test suite for Miri

Mostly, fix the regression introduced by https://github.com/rust-lang/rust/pull/75207 that caused slices (i.e., references) to be created to invalid memory or memory that has aliasing pointers that we want to keep valid. @dylni  this changes the type of `check_range` to only require the length, not the full reference to the slice, which indeed is all the information this function requires.

Also reduce the size of a test introduced in https://github.com/rust-lang/rust/pull/70793 to make it not take 3 minutes in Miri.

This makes https://github.com/RalfJung/miri-test-libstd work again.
2020-09-16 08:25:02 +02:00
Ralf Jung 17015cd5af
Rollup merge of #76534 - notriddle:doc-comments, r=jyn514
Add doc comments for From impls

https://github.com/rust-lang/rust/issues/51430
2020-09-16 08:24:56 +02:00
Ralf Jung 3a4de42a8d
Rollup merge of #76369 - ayushmishra2005:move_various_str_tests_library, r=jyn514
Move Various str tests in library

Moved various string ui  tests in library  as a part of #76268

r? @matklad
2020-09-16 08:24:54 +02:00
Ralf Jung c1a74a3c28
Rollup merge of #76366 - ayushmishra2005:arith_tests_in_library, r=jyn514
Add Arith Tests in Library

Added Arith Tests library as a part of #76268

r? @matklad
2020-09-16 08:24:52 +02:00
Ralf Jung 22dd07d555
Rollup merge of #76335 - CDirkx:const-duration, r=ecstatic-morse
Make all methods of `Duration` unstably const

Make the following methods of `Duration` unstable const under `duration_const_2`:
 - `from_secs_f64`
 - `from_secs_f32`
 - `mul_f64`
 - `mul_f32`
 - `div_f64`
 - `div_f32`

This results in all methods of `Duration` being (unstable) const.

Moved the tests to `library` as part of #76268.

Possible because of #72449, which made the relevant `f32` and `f64` methods const.

Tracking issue: #72440

r? @ecstatic-morse
2020-09-16 08:24:50 +02:00
Ralf Jung 19a62db492
Rollup merge of #76262 - howard0su:patch-1, r=cramertj
Use inline(never) instead of cold

inline(never) is better way to avoid optimizer to inline the function instead of cold.
2020-09-16 08:24:49 +02:00
Ralf Jung fd86705a20
Rollup merge of #76062 - pickfire:patch-13, r=jyn514
Vec slice example fix style and show type elision
2020-09-16 08:24:46 +02:00
Ralf Jung 73858d01c3
Rollup merge of #76056 - pickfire:patch-10, r=jyn514
Add more info for Vec Drain doc

See its documentation for more
2020-09-16 08:24:40 +02:00
Lzu Tao 87666e5bce Prefer asm! over llvm_asm! in core 2020-09-16 04:47:46 +00:00
Ivan Tham 1dc4f8560f
Simplify iter fuse struct doc 2020-09-16 11:45:15 +08:00
Dylan DPC 69ac07608e
Rollup merge of #76198 - CDirkx:const-ordering, r=dtolnay
Make some Ordering methods const

Resubmission of [PR#75463](https://github.com/rust-lang/rust/pull/75463) as per [PR#76172](https://github.com/rust-lang/rust/pull/76172).

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

Insta-stabilizes these methods as const under the `const_ordering` feature, as their implementation is a trivial match and the recent stabilization of #49146 (Allow `if` and `match` in constants).
Note: the `const_ordering` feature has never actually been used as these methods have not been `#[rustc_const_unstable]`.

Tracking issue:  #76113
2020-09-16 01:30:42 +02:00
Dylan DPC c9105185de
Rollup merge of #75882 - pickfire:patch-6, r=jyn514
Use translated variable for test string

Test should be educative, added english translation and pronounciation.
2020-09-16 01:30:36 +02:00
Dylan DPC 034af08e14
Rollup merge of #75749 - ehuss:consolidate-sys, r=alexcrichton
Consolidate some duplicate code in the sys modules.

This consolidates some modules which were duplicated throughout the sys module. The intent is to make it easier to update and maintain this code. This mainly affects the wasi, sgx, and "unsupported" targets.

I explicitly skipped hermit, cloudabi, and vxworks. These tier-3 targets have copied large sections of the sys tree. I don't think they should have, but I don't want to put effort into changing them. It also doesn't help that there aren't any scripts or instructions for building them.

There are still sections of duplicate code here and there, but this PR covers the easy parts where entire modules are the same.
2020-09-16 01:30:34 +02:00
Dylan DPC fa4cfeb597
Rollup merge of #75304 - Aaron1011:feature/diag-deref-move-out, r=estebank
Note when a a move/borrow error is caused by a deref coercion

Fixes #73268

When a deref coercion occurs, we may end up with a move error if the
base value has been partially moved out of. However, we do not indicate
anywhere that a deref coercion is occuring, resulting in an error
message with a confusing span.

This PR adds an explicit note to move errors when a deref coercion is
involved. We mention the name of the type that the deref-coercion
resolved to, as well as the `Deref::Target` associated type being used.
2020-09-16 01:30:32 +02:00
Dylan DPC fb9bb2b5ca
Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-Simulacrum
Detect overflow in proc_macro_server subspan

* Detect overflow in proc_macro_server subspan
* Add tests for overflow in Vec::drain
* Add tests for overflow in String / VecDeque operations using ranges
2020-09-16 01:30:30 +02:00
Dylan DPC 4f0c245429
Rollup merge of #73955 - hellow554:unsafe_process, r=Mark-Simulacrum
deny(unsafe_op_in_unsafe_fn) in libstd/process.rs

The libstd/process.rs part of #73904 . Wraps the two calls to an unsafe fn Initializer::nop() in an unsafe block.

Will have to wait for #73909 to be merged, because of the feature in the libstd/lib.rs
2020-09-16 01:30:28 +02:00
Stein Somers 378b64392f BTreeMap: avoid slices even more 2020-09-16 01:10:44 +02:00
Ralf Jung 7d67546a6a hopefully fix rustdoc links 2020-09-15 23:46:26 +02:00
Ralf Jung c528d24196 fix slice::check_range aliasing problems 2020-09-15 23:14:41 +02:00
Yoshua Wuyts 143e4e975b Fix stabilization marker for future_readiness_fns
Moved it from 1.47.0 -> 1.48.0, which is the correct release for this to stabilize in
2020-09-15 23:12:08 +02:00
Ralf Jung d888725fba reduce size of test_from_iter_specialization_with_iterator_adapters test in Miri 2020-09-15 23:03:07 +02:00
Adam Lesinski fafb2e9de7 [fuchsia] Propagate the userspace UTC clock
On Fuchsia, spawning a subprocess does not automatically
clone all of the parent process' capabilities. UTC time on
Fuchsia is managed by a top-level userspace clock capability
that is cloned and passed to subprocesses.

This change ensures that any Rust subprocess gets access to the
UTC clock, if the parent had access to it. This is critical for
tests, which on Fuchsia, use panic=abort and spawn subprocesses
per test.
2020-09-15 13:54:46 -07:00
bors 07ece44a42 Auto merge of #73166 - jethrogb:stdarch, r=Amanieu
Update stdarch

This PR **changes the public signature** of the following functions in `core::arch::{x86, x86_64}`:
```patch
-pub unsafe fn _mm256_extract_epi8(a: __m256i, imm8: i32) -> i8
+pub unsafe fn _mm256_extract_epi8(a: __m256i, imm8: i32) -> i32
-pub unsafe fn _mm256_extract_epi16(a: __m256i, imm8: i32) -> i16
+pub unsafe fn _mm256_extract_epi16(a: __m256i, imm8: i32) -> i32
```

This change is desired so that these signatures
* are similar to those of the 128-bit versions `_mm_extract_epi8` and `_mm_extract_epi16`
* match the Intel definitions for the intrinsics
  * [RFC 2325](https://github.com/rust-lang/rfcs/blob/master/text/2325-stable-simd.md) specifies that the exact vendor function signatures should be used

A [crater run](https://github.com/rust-lang/rust/pull/73166#issuecomment-667230319) revealed only a single breakage. The [vektor crate](https://github.com/AdamNiederer/vektor/blob/master/src/x86/avx2.rs#L2436-L2472) copied the incorrect signatures in `core` exactly to their own crate. The functions don't seem to be used by anyone anywhere.

Actual breakage is not expected, since due to the nature of the functions, users would generally write `_mm256_extract_epi8(...) as u8` or `_mm256_extract_epi16(...) as u16`.

See https://github.com/rust-lang/stdarch/pull/868/. Note that the changes from that stdarch PR have already partially landed in core after https://github.com/rust-lang/stdarch/pull/878/. This PR is now only about the remaining changes.
2020-09-15 19:04:40 +00:00
bors a874956d94 Auto merge of #75148 - joechrisellis:master, r=Amanieu
Implementation of peer credentials for Unix sockets

The code in `ucred.rs` is based on the work done in [PR 13](https://github.com/tokio-rs/tokio-uds/pull/13) in the tokio-uds repository on GitHub.

This commit is effectively a port to the stdlib, so credit to Martin Habovštiak (`@Kixunil)` and contributors for the meat of this work. 🥇

Happy to make changes as needed. 🙂
2020-09-15 17:05:57 +00:00
Guillaume Gomez 2a5a6b42ec Add missing code examples in libcore 2020-09-15 18:18:04 +02:00
Jubilee Young 797cb9526a Fix to libstd test 2020-09-15 08:47:20 -07:00
Jethro Beekman 0122e08dae Update stdarch 2020-09-15 17:26:20 +02:00
Jubilee Young 247b73939a Move Wrapping<T> ui tests into library 2020-09-15 07:15:59 -07:00
Eric Huss 25cca07ea0 Consolidate wasi::process and unsupported::process 2020-09-15 07:01:13 -07:00
Eric Huss cfb955da6f Consolidate wasi alloc with unix alloc. 2020-09-15 07:01:13 -07:00
Eric Huss 5a4098ed0f Consolidate byte-identical modules. 2020-09-15 07:01:07 -07:00
bors 4c1966f97e Auto merge of #76311 - lzutao:split_core-slice, r=lcnr
Split `core::slice` to smaller mods

Unfortunately the `#[lang = "slice"]` is too big (3003 lines), I cannot split it further.

Note for reviewer:
* I split to multiple commits for easier reviewing, but I could git squash them all to one if requested.
* Recommend pulling this change locally and using advanced git diff viewer or this command:
  ```
  git show --reverse --color-moved=dimmed-zebra master..
  ```

---

I split core/slice/mod.rs to these modules:

* `ascii`: For operations on `[u8]`.
* `cmp`: For comparison operations on `[T]`, like PartialEq and SliceContains impl.
* `index`: For indexing operations like Index/IndexMut and SliceIndex.
* `iter`: For Iterator definitions and implementation on `[T]`.
  - `macros`: For iterator! and forward_iterator! macros.
* `raw`: For free function to create `&[T]` or `&mut [T]` from pointer + length or a reference.

The heapsort wrapper in mod.rs is removed in favor of reexport from `sort::heapsort`.
2020-09-15 12:15:59 +00:00
Stein Somers 176956c115 Test and fix Sync & Send traits of BTreeMap artefacts 2020-09-15 13:46:35 +02:00
Ivan Tham 1f572b0349
Vec doc use elision as code rather than comment 2020-09-15 14:41:43 +08:00
bors 6cae28165f Auto merge of #76682 - richkadel:vec-take, r=Mark-Simulacrum
Optimize behavior of vec.split_off(0) (take all)

Optimization improvement to `split_off()` so the performance meets the
intuitively expected behavior when `at == 0`, avoiding the current behavior
of copying the entire vector.

The change honors documented behavior that the original vector's
"previous capacity unchanged".

This improvement better supports the pattern for building and flushing a
buffer of elements, such as the following:

```rust
    let mut vec = Vec::new();
    loop {
        vec.push(something);
        if condition_is_met {
            process(vec.split_off(0));
        }
    }
```

`Option` wrapping is the first alternative I thought of, but is much
less obvious and more verbose:

```rust
    let mut capacity = 1;
    let mut vec: Option<Vec<Stuff>> = None;
    loop {
        vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something);
        if condition_is_met {
            capacity = vec.capacity();
            process(vec.take().unwrap());
        }
    }
```

Directly using `mem::replace()` (instead of  calling`split_off()`) could work,
but `mem::replace()` is a more advanced tool for Rust developers, and in
this case, I believe developers would assume the standard library should
be sufficient for the purpose described here.

The benefit of the approach to this change is it does not change the
existing API contract, but improves the peformance of `split_off(0)` for
`Vec`, `String` (which delegates `split_off()` to `Vec`), and any other
existing use cases.

This change adds tests to validate the behavior of `split_off()` with
regard to capacity, as originally documented, and confirm that behavior
still holds, when `at == 0`.

The change is an implementation detail, and does not require a
documentation change, but documenting the new behavior as part of its
API contract may benefit future users.

(Let me know if I should make that documentation update.)

Note, for future consideration:

I think it would be helpful to introduce an additional method to `Vec`
(if not also to `String`):

```
    pub fn take_all(&mut self) -> Self {
        self.split_off(0)
    }
```

This would make it more clear how `Vec` supports the pattern, and make
it easier to find, since the behavior is similar to other `take()`
methods in the Rust standard library.

r? `@wesleywiser`
FYI: `@tmandry`
2020-09-15 05:01:17 +00:00
bors 715e9340a1 Auto merge of #74532 - fusion-engineering-forks:atomic-from-mut, r=KodrAus
Add Atomic*::from_mut.

The atomic equivalent of [`Cell::from_mut`](https://doc.rust-lang.org/stable/std/cell/struct.Cell.html#method.from_mut).
2020-09-15 02:09:34 +00:00
Camelid 58310ce94b Use intra-doc links in `core::mem` 2020-09-14 15:14:21 -07:00
bors bb0067c75e Auto merge of #76278 - jethrogb:jb/sgx-rwlock-init-test, r=Mark-Simulacrum
Improve SGX RWLock initializer test

r? `@eddyb`

This addresses https://github.com/pnkfelix/rust/pull/1#discussion_r374239895

Fixes https://github.com/fortanix/rust-sgx/issues/213
2020-09-14 18:04:18 +00:00
Ivan Tham 5112f879ff
Remove flatten doc intra-doc links 2020-09-15 00:35:48 +08:00
Ivan Tham b88155160c
Simplify iter flatten struct doc 2020-09-14 21:08:08 +08:00
Lzu Tao 6655ad7ed8 Removed outdated comments 2020-09-14 09:35:54 +00:00
Lzu Tao f2976ab2d6 Move ascii to new module 2020-09-14 09:35:54 +00:00
Lzu Tao fbad684e2f move indexing impl to new mod 2020-09-14 09:35:54 +00:00
Lzu Tao bcd18f977b Move free functions to a new module 2020-09-14 09:35:54 +00:00
Lzu Tao f376443b8f Move iterator impls to a new module 2020-09-14 09:35:54 +00:00
Joe Ellis 68ff495afa Fix peer credentials for Android 2020-09-14 10:31:56 +01:00
Joe Ellis 72eef6168f Conditionally compile peer credentials feature for supported platforms 2020-09-14 10:31:56 +01:00
Joe Ellis fa697dfa81 Add documentation to public fields of UCred struct 2020-09-14 10:31:56 +01:00
Joe Ellis 7c20be387b Move Unix peer credentials tests to their own file 2020-09-14 10:31:56 +01:00
Joe Ellis 40a830321d Add pid as an option to UCred struct
Currently, PID will be populated for Linux, and set to None for BSDs.
2020-09-14 10:31:56 +01:00
Joe Ellis cbcf3877b5 Use `u32::MAX` instead of `u32::max_value`
Co-authored-by: lzutao <taolzu@gmail.com>
2020-09-14 10:31:56 +01:00
Joe Ellis be2637aba7 Add basic test for Unix peer credentials 2020-09-14 10:31:56 +01:00
Joe Ellis a9ec61db17 Remove use of `MaybeUninit` in `ucred.rs`
We can simply init the struct directly. There is no real need to use
uninit memory here.
2020-09-14 10:31:56 +01:00
Joe Ellis ed20eff92b Implementation of peer credentials for Unix sockets
The code in `ucred.rs` is based on the work done in PR 13 in the
tokio-uds repository on GitHub. Link below for reference:

    https://github.com/tokio-rs/tokio-uds/pull/13

Credit to Martin Habovštiak (GitHub username Kixunil) and contributors
for this work!
2020-09-14 10:31:44 +01:00