Commit Graph

1643 Commits

Author SHA1 Message Date
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
Guillaume Gomez d069c7e928 Stabilize doc_alias feature 2020-09-14 11:03:47 +02:00
Rich Kadel 79aa9b15d7 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 method leaves 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 applying `mem::replace()` could work, but `mem::` functions are
typically a last resort, when a developer is actively seeking better
performance than the standard library provides, for example.

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.
2020-09-13 14:32:29 -07:00
Jonas Schievink fe716d0447
Rollup merge of #76677 - RalfJung:stable-pointers, r=jonas-schievink
note that test_stable_pointers does not reflect a stable guarantee

Just to be sure...
2020-09-13 20:21:24 +02:00
Jonas Schievink 305d63c2a4
Rollup merge of #76665 - RalfJung:slice-from-raw, r=sfackler
slice::from_raw_parts: explicitly mention that data must be initialized

This reflects the status quo, until the discussion in https://github.com/rust-lang/unsafe-code-guidelines/issues/77 reaches a conclusion.
2020-09-13 20:21:19 +02:00
Jonas Schievink 11a63bcdde
Rollup merge of #76663 - pickfire:patch-7, r=jonas-schievink
Simplify iter chain struct doc
2020-09-13 20:21:17 +02:00
Jonas Schievink e460f8508e
Rollup merge of #76651 - nicholasbishop:bishop-remove-windows-note, r=Mark-Simulacrum
Remove Windows details from Unix and VmWorks symlink() docstrings

This note is not relevant to other operating systems.
2020-09-13 20:21:16 +02:00
Jonas Schievink f9b9467866
Rollup merge of #76640 - fusion-engineering-forks:synconcecell-drop, r=matklad
Simplify SyncOnceCell's `take` and `drop`.

Prevents copies by using `assume_init_read` and `assume_init_drop`.
2020-09-13 20:21:13 +02:00
Jonas Schievink 148b24f796
Rollup merge of #76629 - pickfire:patch-4, r=jonas-schievink
Simplify iter zip struct doc
2020-09-13 20:21:11 +02:00
Jonas Schievink e5389a4a34
Rollup merge of #76527 - fusion-engineering-forks:cleanup-uninit, r=jonas-schievink
Remove internal and unstable MaybeUninit::UNINIT.

Looks like it is no longer necessary, as `uninit_array()` can be used instead in the few cases where it was needed.

(I wanted to just add `#[doc(hidden)]` to remove clutter from the documentation, but looks like it can just be removed entirely.)
2020-09-13 20:21:09 +02:00
Ralf Jung 71a5c464d1 note that test_stable_pointers does not reflect a stable guarantee 2020-09-13 18:55:08 +02:00
Mara Bos 9914c3beed Supress unused_macros error on architectures with no atomics. 2020-09-13 18:34:27 +02:00
Mara Bos 3be40b22c8 Fix AtomicPtr::from_mut align check: Avoid generic arg in const expr.
See #76200.
2020-09-13 14:09:10 +02:00
Mara Bos 458aaba084 Add Atomic*::from_mut.
The atomic equivalent of Cell::from_mut.
2020-09-13 14:08:52 +02:00
Ralf Jung 46767b1665 slice::from_raw_parts: explicitly mention that data must be initialized 2020-09-13 14:02:01 +02:00
Ivan Tham 20a2e095ec
Simplify iter chain struct doc 2020-09-13 19:20:57 +08:00
Christiaan Dirkx 8f27e3cb1b 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`

Also adds tests for these methods in a const context.

Tracking issue: #76654
2020-09-13 01:55:34 +02:00
Nicholas Bishop 2eeb8f18eb Remove Windows details from Unix and VmWorks symlink() docstrings
This note is not relevant to other operating systems.
2020-09-12 15:50:28 -04:00
Mara Bos 1016deb592 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.
2020-09-12 20:50:17 +02:00
bors 989190874f Auto merge of #76538 - fusion-engineering-forks:check-useless-unstable-trait-impl, r=lcnr
Warn for #[unstable] on trait impls when it has no effect.

Earlier today I sent a PR with an `#[unstable]` attribute on a trait `impl`, but was informed that this attribute has no effect there. (comment: https://github.com/rust-lang/rust/pull/76525#issuecomment-689678895, issue: https://github.com/rust-lang/rust/issues/55436)

This PR adds a warning for this situation. Trait `impl` blocks with `#[unstable]` where both the type and the trait are stable will result in a warning:

```
warning: An `#[unstable]` annotation here has no effect. See issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information.
   --> library/std/src/panic.rs:235:1
    |
235 | #[unstable(feature = "integer_atomics", issue = "32976")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

---

It detects three problems in the existing code:

1. A few `RefUnwindSafe` implementations for the atomic integer types in `library/std/src/panic.rs`. Example:
d92155bf6a/library/std/src/panic.rs (L235-L236)
2. An implementation of `Error` for `LayoutErr` in `library/std/srd/error.rs`:
d92155bf6a/library/std/src/error.rs (L392-L397)
3. `From` implementations for `Waker` and `RawWaker` in `library/alloc/src/task.rs`. Example:
d92155bf6a/library/alloc/src/task.rs (L36-L37)

Case 3 interesting: It has a bound with an `#[unstable]` trait (`W: Wake`), so appears to have much effect on stable code. It does however break similar blanket implementations. It would also have immediate effect if `Wake` was implemented for any stable type. (Which is not the case right now, but there are no warnings in place to prevent it.) Whether this case is a problem or not is not clear to me. If it isn't, adding a simple `c.visit_generics(..);` to this PR will stop the warning for this case.
2020-09-12 18:01:33 +00:00
CAD97 3d07108d36 Add tests for weak into/from raw 2020-09-12 10:38:33 -05:00
CAD97 9d9903c5a5 Allow Weak::as_ptr and friends for unsized T 2020-09-12 10:38:33 -05:00
CAD97 5e7406c956 Adjust sync::Weak::from_raw to support unsized T 2020-09-12 10:38:32 -05:00
CAD97 0c61ce2cf0 ?Sized bounds for rc::Weak::as_ptr and friends 2020-09-12 10:38:22 -05:00
CAD97 728938346b Adjust rc::Weak::from_raw to support unsized T 2020-09-12 10:27:43 -05:00
Mara Bos aa68aaa8e1 Mark Once::new as #[inline].
Without this, it was not inlined in SyncOnceCell::into_inner(), causing
unecessary checks and dead code.
2020-09-12 17:11:47 +02:00
Christiaan Dirkx 73e0a56dde Make all methods of `Duration` 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.

Also adds tests for these methods in a const context, moved the test to `library` as part of #76268.

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

Tracking issue: #72440
2020-09-12 15:14:58 +02:00
bors 85109afee9 Auto merge of #76561 - Thomasdezeeuw:iov-constant-limits, r=Amanieu
Use IOV_MAX and UIO_MAXIOV constants in limit vectored I/O

Also updates the libc dependency to 0.2.77 (from 0.2.74) as the
constants were only recently added.

Related #68042, #75005

r? `@Amanieu` (also reviewed #75005)
2020-09-12 12:06:12 +00:00
Mara Bos 8a261a2b34 Simplify SyncOnceCell's `take` and `drop`. 2020-09-12 14:00:38 +02:00
Ralf Jung 0ed4bc5993
Rollup merge of #76615 - GuillaumeGomez:missing-examples-binary-ops, r=jyn514
Add missing examples on binary core traits

r? @jyn514
2020-09-12 10:43:24 +02:00
Ralf Jung 2477f070fc
Rollup merge of #76583 - CDirkx:os-doc, r=jonas-schievink
Update `std::os` module documentation.

Adds missing descriptions for the modules `std::os::linux::fs` and `std::os::windows::io`.
Also adds punctuation for consistency with other descriptions.
2020-09-12 10:43:20 +02:00
Ralf Jung a49451c805
Rollup merge of #76530 - carbotaniuman:fix-rc, r=RalfJung
Eliminate mut reference UB in Drop impl for Rc<T>

This changes `self.ptr.as_mut()` with `get_mut_unchecked` which
does not use an intermediate reference.  Arc<T> already handled this
case properly.

Fixes #76509
2020-09-12 10:43:18 +02:00
Ralf Jung c20356e96b
Rollup merge of #76484 - fusion-engineering-forks:maybe-uninit-drop, r=RalfJung
Add MaybeUninit::assume_init_drop.

`ManuallyDrop`'s documentation tells the user to use `MaybeUninit` instead when handling uninitialized data. However, the main functionality of `ManuallyDrop` (`drop`) is not available directly on `MaybeUninit`. Adding it makes it easier to switch from one to the other.

I re-used the `maybe_uninit_extra` feature and tracking issue number (#63567), since it seems very related. (And to avoid creating too many features tracking issues for `MaybeUninit`.)
2020-09-12 10:43:17 +02:00
Ralf Jung 7344f930c0
Rollup merge of #76114 - marmeladema:duration-saturating-ops, r=shepmaster
Add saturating methods for `Duration`

In some project, I needed a `saturating_add` method for `Duration`. I implemented it myself but i thought it would be a nice addition to the standard library as it matches closely with the integers types.

3 new methods have been introduced and are gated by the new `duration_saturating_ops` unstable feature:
* `Duration::saturating_add`
* `Duration::saturating_sub`
* `Duration::saturating_mul`

If have left the tracking issue to `none` for now as I want first to understand if those methods would be acceptable at all. If agreed, I'll update the PR with the tracking issue.

Further more, to match the behavior of integers types, I introduced 2 associated constants:
* `Duration::MIN`: this one is somehow a duplicate from `Duration::zero()` method, but at the time this method was added, `MIN` was rejected as it was considered a different semantic (see https://github.com/rust-lang/rust/pull/72790#issuecomment-636511743).
* `Duration::MAX`

Both have been gated by the already existing unstable feature `duration_constants`, I can introduce a new unstable feature if needed or just re-use the `duration_saturating_ops`.

We might have to decide whether:
* `MIN` should be replaced by `ZERO`?
* associated constants over methods?
2020-09-12 10:43:08 +02:00
Ivan Tham b1e481d712
Simplify iter zip struct doc 2020-09-12 13:35:03 +08:00
bors 8b6838b6e1 Auto merge of #75021 - cuviper:array_chunks_mut, r=scottmcm
Add `slice::array_chunks_mut`

This follows `array_chunks` from #74373 with a mutable version, `array_chunks_mut`. The implementation is identical apart from mutability. The new tests are adaptations of the `chunks_exact_mut` tests, plus an inference test like the one for `array_chunks`.

I reused the unstable feature `array_chunks` and tracking issue #74985, but I can separate that if desired.

r? `@withoutboats`
cc `@lcnr`
2020-09-12 03:59:46 +00:00
bors 94a7ea271f Auto merge of #74328 - yoshuawuyts:stabilize-future-readiness-fns, r=sfackler
Stabilize core::future::{pending,ready}

This PR stabilizes `core::future::{pending,ready}`, tracking issue https://github.com/rust-lang/rust/issues/70921.

## Motivation

These functions have been on nightly for three months now, and have lived as part of the futures ecosystem for several years. In that time these functions have undergone several iterations, with [the `async-std` impls](https://docs.rs/async-std/1.6.2/async_std/future/index.html) probably diverging the most (using `async fn`, which in hindsight was a mistake).

It seems the space around these functions has been _thoroughly_ explored over the last couple of years, and the ecosystem has settled on the current shape of the functions. It seems highly unlikely we'd want to make any further changes to these functions, so I propose we stabilize.

## Implementation notes

This stabilization PR was fairly straightforward; this feature has already thoroughly been reviewed by the libs team already in https://github.com/rust-lang/rust/pull/70834. So all this PR does is remove the feature gate.
2020-09-12 02:13:28 +00:00
bors 12c10e34a4 Auto merge of #73951 - pickfire:liballoc-intoiter, r=Mark-Simulacrum
Liballoc intoiter refactor
2020-09-11 23:52:03 +00:00
Guillaume Gomez bb9ce7cb01 Add missing examples on binary core traits 2020-09-11 23:43:37 +02:00
Thomas de Zeeuw c394624471 Ignore unnecessary unsafe warnings
This is a work-around for a libc issue:
https://github.com/rust-lang/libc/issues/1888.
2020-09-11 19:12:06 +02:00
rijenkii 64b8fd7920 Add `peek` and `peek_from` to `UnixStream` and `UnixDatagram` 2020-09-11 20:07:08 +07:00
carbotaniuman b729368d4e Address review comments 2020-09-11 07:25:28 -05:00
Mara Bos 471fb622aa Allow unstable From impl for [Raw]Waker. 2020-09-11 13:36:45 +02:00
Mara Bos cf8e5d1bc9 Mark Error impl for LayoutErr as stable.
This impl was effectively stable. #[unstable] had no effect here,
since both Error and LayoutErr were already stable.

This effectively became stable as soon as LayoutErr became stable, which
was in 1.28.0.
2020-09-11 13:36:15 +02:00
Mara Bos f6fbf669ab Mark RefUnwindSafe impls for stable atomic types as stable.
These impls were effectively stable. #[unstable] had no effect here,
since both RefUnwindSafe and these types were already stable.

These effectively became stable as soon as the types became stable,
which was in 1.34.0.
2020-09-11 13:36:15 +02:00
Federico Ponzi ec7f9b927f
Deduplicates io::Write implementations 2020-09-11 11:39:31 +02:00
Nathan West 96229f0240 move buffered.rs to mod.rs 2020-09-10 23:48:22 -04:00
Nathan West a020142805 Refactor io/buffered.rs into submodules 2020-09-10 23:39:55 -04:00
Christiaan Dirkx 954361a3d4 Update `std::os` module documentation.
Adds missing descriptions for the modules std::os::linux::fs and std::os::windows::io.
Also adds punctuation for consistency with other descriptions.
2020-09-11 04:05:19 +02:00
Aaron Hill d18b4bb7a7
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-10 20:56:20 -04:00
bors ee04f9a4da Auto merge of #74437 - ssomers:btree_no_root_in_noderef, r=Mark-Simulacrum
BTreeMap: move up reference to map's root from NodeRef

Since the introduction of `NodeRef` years ago, it also contained a mutable reference to the owner of the root node of the tree (somewhat disguised as *const). Its intent is to be used only when the rest of the `NodeRef` is no longer needed. Moving this to where it's actually used, thought me 2 things:
- Some sort of "postponed mutable reference" is required in most places that it is/was used, and that's exactly where we also need to store a reference to the length (number of elements) of the tree, for the same reason. The length reference can be a normal reference, because the tree code does not care about tree length (just length per node).
- It's downright obfuscation in `from_sorted_iter` (transplanted to #75329)
- It's one of the reasons for the scary notice on `reborrow_mut`, the other one being addressed in #73971.

This does repeat the raw pointer code in a few places, but it could be bundled up with the length reference.

r? `@Mark-Simulacrum`
2020-09-10 23:29:57 +00:00
Tyler Mandry 044f7179ba
Rollup merge of #76568 - GuillaumeGomez:add-missing-examples, r=jyn514
Add missing examples on core traits' method

Linked to #76450.

r? @jyn514
2020-09-10 12:20:15 -07:00
Thomas de Zeeuw f7b6ace029 Use IOV_MAX and UIO_MAXIOV constants in limit vectored I/O
Also updates the libc dependency to 0.2.77 (from 0.2.74) as the
constants were only recently added.
2020-09-10 16:27:28 +02:00
Guillaume Gomez d7a9707051 Add missing examples on core traits' method 2020-09-10 14:34:43 +02:00
Tyler Mandry 8bf03c3f62
Rollup merge of #76543 - ssomers:btree_cleanup_4, r=Mark-Simulacrum
Document btree's unwrap_unchecked

#74693's second wind
2020-09-09 21:02:36 -07:00
Tyler Mandry d013e60ad4
Rollup merge of #76497 - camelid:intra-doc-links-for-core-ptr, r=jyn514
Use intra-doc links in `core::ptr`

Part of #75080.

The only link that I did not change is a link to a function on the
`pointer` primitive because intra-doc links for the `pointer` primitive
don't work yet (see #63351).

---

@rustbot modify labels: A-intra-doc-links T-doc
2020-09-09 21:02:33 -07:00
Tyler Mandry fa56cf537f
Rollup merge of #76458 - mbrubeck:hash_drain_filter, r=Amanieu
Add drain_filter method to HashMap and HashSet

Add `HashMap::drain_filter` and `HashSet::drain_filter`, implementing part of rust-lang/rfcs#2140.  These new methods are unstable.  The tracking issue is #59618.

The added iterators behave the same as `BTreeMap::drain_filter` and `BTreeSet::drain_filter`, except their iteration order is arbitrary.  The unit tests are adapted from `alloc::collections::btree`.

This branch rewrites `HashSet` to be a wrapper around `hashbrown::HashSet` rather than `std::collections::HashMap`.
 (Both are themselves wrappers around `hashbrown::HashMap`, so the in-memory representation is the same either way.)  This lets `std` re-use more iterator code from `hashbrown`.  Without this change, we would need to duplicate much more code to implement `HashSet::drain_filter`.

This branch also updates the `hashbrown` crate to version 0.9.0.  Aside from changes related to the `DrainFilter` iterators, this version only changes features that are not used in libstd or rustc.  And it updates `indexmap` to version 1.6.0, whose only change is compatibility with `hashbrown` 0.9.0.
2020-09-09 21:02:27 -07:00
Stein Somers f42dac0ce0 Document btree's unwrap_unchecked 2020-09-10 00:25:59 +02:00
Tyler Mandry c18fa460a4
Rollup merge of #76504 - Flying-Toast:master, r=lcnr
Capitalize safety comments
2020-09-09 15:06:00 -07:00
Tyler Mandry 342b406285
Rollup merge of #76493 - moonheart08:unique-quick, r=jyn514
Remove a stray ignore-tidy-undocumented-unsafe

There were no undocumented unsafe blocks in the file. This shouldn't require any special review.
2020-09-09 15:05:59 -07:00
Tyler Mandry 0d20cf8568
Rollup merge of #76481 - moonheart08:vec_deque_constify, r=sfackler
Convert repetitive target_pointer_width checks to const solution.

Simply a quick code tidying change. Not sure if more needs to be said.
2020-09-09 15:05:56 -07:00
Stein Somers 2b54ab880c BTreeMap: pull the map's root out of NodeRef 2020-09-10 00:02:54 +02:00
Camelid 884a1b4b9b Fix anchor links
#safety -> self#safety
2020-09-09 13:42:57 -07:00
Michael Howell 8b0d0a0cad Add documentation for `impl<T> From<BinaryHeap<T>> for Vec<T>` 2020-09-09 11:53:24 -07:00
Michael Howell d85db82960 Add documentation for `impl<T> From<T> for Poll<T>` 2020-09-09 11:51:19 -07:00
carbotaniuman bb57c9f91c Format 2020-09-09 13:44:22 -05:00
carbotaniuman 8f43fa0989 Add WeakInner<'_> and have Weak::inner() return it
This avoids overlapping a reference covering the data field,
which may be changed due in concurrent conditions. This fully
fixed the UB mainfested with `new_cyclic`.
2020-09-09 13:39:48 -05:00
Mara Bos 829019d404 Disable AsRef implementations for String's Drain.
Since trait implementations cannot be unstable, we should only add them
when the as_str feature gets stabilized. Until then, only `.as_str()` is
available (behind a feature gate).
2020-09-09 19:57:57 +02:00
bors d92155bf6a Auto merge of #73971 - ssomers:slice_slasher, r=Mark-Simulacrum
BTreeMap mutable iterators should not take any reference to visited nodes during iteration

Fixes #73915, overlapping mutable references during BTreeMap iteration

r? `@RalfJung`
2020-09-09 17:40:46 +00:00
carbotaniuman 493c037699 Eliminate mut reference UB in Drop impl for Rc<T>
This changes `self.ptr.as_mut()` with `get_mut_unchecked` which
does not use an intermediate reference.  Arc<T> already handled this
case properly.
2020-09-09 12:14:18 -05:00
Mara Bos f2a32909e0 Mark AsRef impls for String's Drain as stable.
Trait implementations effectively can't be #[unstable].
2020-09-09 19:10:06 +02:00
Mara Bos 43c7a9b72b Fix broken doc links in MaybeUninit. 2020-09-09 18:56:16 +02:00
Mara Bos a94b2cb034 Add safety docs about T's invariants in MaybeUninit::assume_init_drop. 2020-09-09 18:55:36 +02:00
Mara Bos 4506d26cf3 Remove internal and unstable MaybeUninit::UNINIT.
Looks like it is no longer necessary, as uninit_array() can be used
instead in the few cases where it was needed.
2020-09-09 18:38:10 +02:00
Mara Bos f5bb523e94 Add AsRef<[u8]> for String's Drain. 2020-09-09 18:07:27 +02:00
Mara Bos 673284058b Show remaining data in string::Drain's Debug impl. 2020-09-09 17:50:55 +02:00
Mara Bos daa62d9081 Add as_str() and AsRef to string::Drain. 2020-09-09 17:50:55 +02:00
Tavian Barnes a684153f29 Only call pthread_attr_destroy() after getattr_np() succeeds on all libcs
The calling convention of pthread_getattr_np() is to initialize the
pthread_attr_t, so _destroy() is only necessary on success (and _init()
isn't necessary beforehand).  On the other hand, FreeBSD wants the
attr_t to be initialized before pthread_attr_get_np(), and therefore it
should always be destroyed afterwards.
2020-09-09 11:10:43 -04:00
Tavian Barnes a06edda3ad 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-09 10:21:50 -04:00
Stein Somers 8158d5623e BTreeMap: avoid aliasing by avoiding slices 2020-09-09 08:58:02 -04:00
Ralf Jung 7889373730 make as_leaf return a raw pointer, to reduce aliasing assumptions 2020-09-09 08:38:34 -04:00
Mara Bos a14efd1d0a Rename MaybeUninit::read to assume_init_read. 2020-09-09 11:27:42 +02:00
Mara Bos 656a17b44d Rename MaybeUninit::drop to assume_init_drop. 2020-09-09 11:27:09 +02:00
Flying-Toast 2799aec6ab Capitalize safety comments 2020-09-08 22:37:18 -04:00
Flying-Toast c66789d572 Capitalize safety comments 2020-09-08 22:26:44 -04:00
Camelid d24026bb6d Fix broken link
`write` is ambiguous because there's also a macro called `write`.

Also removed unnecessary and potentially confusing link to a function in
its own docs.
2020-09-08 19:24:57 -07:00
Matt Brubeck fb1fab5a67 Tests for HashMap/HashSet::drain_filter 2020-09-08 17:24:28 -07:00
Matt Brubeck 49aef963d3 Add HashMap::drain_filter and HashSet::drain_filter
Implements #59618.
2020-09-08 17:24:28 -07:00
Matt Brubeck ebd15e790a Implement HashSet in terms of hashbrown::HashSet 2020-09-08 17:24:23 -07:00
Matt Brubeck 15ccdeb224 Update to hashbrown 0.9 2020-09-08 17:23:26 -07:00
Dylan DPC 87302a297c
Rollup merge of #76162 - abrausch:documentation-fix-duration_since, r=jyn514
Make duration_since documentation more clear
2020-09-09 01:35:10 +02:00
Camelid 325acefee4 Use intra-doc links in `core::ptr`
The only link that I did not change is a link to a function on the
`pointer` primitive because intra-doc links for the `pointer` primitive
don't work yet (see #63351).
2020-09-08 14:36:36 -07:00
Alexander Brausch 98231bfb95 Make duration_since documentation more clear 2020-09-08 23:27:24 +02:00
moonheart08 0aaf56f5fc Remove a stray ignore-tidy-undocumented-unsafe
There were no undocumented unsafe blocks in the file.
2020-09-08 15:00:47 -05:00
Braden Nelson e02952c0cc
Update library/alloc/src/collections/vec_deque.rs
Replace lshift with multiply

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-09-08 13:11:08 -05:00
Mara Bos caef83282b Fix doc comment on MaybeUninit::drop. 2020-09-08 19:34:23 +02:00
Mara Bos 75e471ade9 Add MaybeUninit::drop.
ManuallyDrop's documentation tells the user to use MaybeUninit instead
when handling uninitialized data. However, the main functionality of
ManuallyDrop (drop) was not available directly on MaybeUninit. Adding it
makes it easier to switch from one to the other.
2020-09-08 19:01:05 +02:00
moonheart08 c3c84ad027 Convert MAXIMUM_ZST_CAPACITY to be calculated in a
const instead of multiple target_pointer_width checks.
2020-09-08 10:35:35 -05:00
marmeladema b869aa5f31 Add saturating methods for `Duration` 2020-09-08 00:42:56 +01:00
bors 9fe551ae49 Auto merge of #74366 - t-rapp:tr-bufreader-pos, r=LukasKalbertodt
Implement Seek::stream_position() for BufReader

Optimization over `BufReader::seek()` for getting the current position without flushing the internal buffer.

Related to #31100. Based on the code in #70577.
2020-09-07 11:09:41 +00:00
Ralf Jung caeb5544ec do not inline black_box when building for Miri 2020-09-07 11:31:37 +02:00