Commit graph

1510 commits

Author SHA1 Message Date
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
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
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