Commit graph

789 commits

Author SHA1 Message Date
Jonas Schievink
18ac26d1c5
Rollup merge of #77409 - pickfire:patch-6, r=GuillaumeGomez
Add example for iter chain struct

r? @GuillaumeGomez
2020-10-02 20:27:06 +02:00
Jonas Schievink
2a09c184c0
Rollup merge of #77405 - timvermeulen:iter_advance_by_tracking_issue, r=scottmcm
Add tracking issue of iter_advance_by feature
2020-10-02 20:27:04 +02:00
Ivan Tham
ddd19866a7
Clean up on example doc fixes for ptr::copy
Follow up of #77385
2020-10-02 14:44:01 +08:00
Yuki Okushi
2e749ab5a4
Rollup merge of #77385 - scottmcm:fix-77220, r=jyn514
Improve the example for ptr::copy

Fixes #77220
2020-10-02 08:25:22 +09:00
Yuki Okushi
9eaf536c32
Rollup merge of #77111 - fusion-engineering-forks:stabilize-slice-ptr-range, r=dtolnay
Stabilize slice_ptr_range.

This has been unstable for almost a year now. Time to stabilize?

Closes #65807.

@rustbot modify labels: +T-libs +A-raw-pointers +A-slice +needs-fcp
2020-10-02 08:25:13 +09:00
Waffle
076514c8a8 add str::SplitInclusive::as_str method
This commit entroduces `core::str::SplitInclusive::as_str` method similar to
`core::str::Split::as_str`, but under different gate -
"str_split_inclusive_as_str" (this is done so because `SplitInclusive` is
itself unstable).
2020-10-01 23:40:42 +03:00
Waffle
4747215d77 add str::{SplitN, RSplitN, SplitTerminator, RSplitTerminator}::as_str methods
This commit entroduce 4 methods smililar to `Split::as_str` all under the same
gate "str_split_as_str".
2020-10-01 23:08:15 +03:00
Waffle
0b923d3ca0 add str::{Split,RSplit}::as_str methods
This commit introduses 2 methods under "str_split_as_str" gate with common
signature of `&Split<'a, _> -> &'a str'`. Both of them work like
`Chars::as_str` - return unyield part of the inner string.
2020-10-01 22:53:15 +03:00
Michael Howell
cd159fd7f9 Uplift drop-bounds lint from clippy 2020-10-01 12:06:33 -07:00
bors
8fe73e80d7 Auto merge of #76971 - bugadani:issue-75659, r=Amanieu
Refactor memchr to allow optimization

Closes #75659

The implementation already uses naive search if the slice if short enough, but the case is complicated enough to not be optimized away. This PR refactors memchr so that it exists early when the slice is short enough.

Codegen-wise, as shown in #75659, memchr was not inlined previously so the only way I could find to test this is to check if there is no memchr call. Let me know if there is a more robust solution here.
2020-10-01 18:16:02 +00:00
Ivan Tham
aea3f8dbc9
Remove trailing whitespace in iter chain doc 2020-10-02 01:21:36 +08:00
Ivan Tham
676e4f193c
Add example for iter chain struct 2020-10-02 00:45:19 +08:00
Tim Vermeulen
4404c1afae Add tracking issue 2020-10-01 16:52:22 +02:00
scottmcm
e58f3d352d
Things are only moved if non-copy 2020-10-01 07:04:20 +00:00
Scott McMurray
20202da09e Improve the example for ptr::copy
Fixes #77220
2020-09-30 20:00:09 -07:00
bors
b218b952f8 Auto merge of #77381 - Dylan-DPC:rollup-0sr6p5p, r=Dylan-DPC
Rollup of 12 pull requests

Successful merges:

 - #76909 (Add Iterator::advance_by and DoubleEndedIterator::advance_back_by)
 - #77153 (Fix recursive nonterminal expansion during pretty-print/reparse check)
 - #77202 (Defer Apple SDKROOT detection to link time.)
 - #77303 (const evaluatable: improve `TooGeneric` handling)
 - #77305 (move candidate_from_obligation_no_cache)
 - #77315 (Rename AllocErr to AllocError)
 - #77319 (Stable hashing: add comments and tests concerning platform-independence)
 - #77324 (Don't fire `const_item_mutation` lint on writes through a pointer)
 - #77343 (Validate `rustc_args_required_const`)
 - #77349 (Update cargo)
 - #77360 (References to ZSTs may be at arbitrary aligned addresses)
 - #77371 (Remove trailing space in error message)

Failed merges:

r? `@ghost`
2020-10-01 01:12:41 +00:00
Dylan DPC
70740b1b82
Rollup merge of #77315 - exrook:rename-allocerror, r=joshtriplett
Rename AllocErr to AllocError

Implements rust-lang/wg-allocators#57
2020-10-01 02:13:39 +02:00
Dylan DPC
8bd4ed9f95
Rollup merge of #76909 - timvermeulen:advance_by, r=Amanieu
Add Iterator::advance_by and DoubleEndedIterator::advance_back_by

This PR adds the iterator method

```rust
fn advance_by(&mut self, n: usize) -> Result<(), usize>
```

that advances the iterator by `n` elements, returning `Ok(())` if this succeeds or `Err(len)` if the length of the iterator was less than `n`.

Currently `Iterator::nth` is the method to override for efficiently advancing an iterator by multiple elements at once. `advance_by` is superior for this purpose because
- it's simpler to implement: instead of advancing the iterator and producing the next element you only need to advance the iterator
- it composes better: iterators like `Chain` and `FlatMap` can implement `advance_by` in terms of `advance_by` on their inner iterators, but they cannot implement `nth` in terms of `nth` on their inner iterators (see #60395)
- the default implementation of `nth` can trivially be implemented in terms of `advance_by` and `next`, which this PR also does

This PR also adds `DoubleEndedIterator::advance_back_by` for all the same reasons.

I'll make a tracking issue if it's decided this is worth merging. Also let me know if anything can be improved, this went through several iterations so there might very well still be room for improvement (especially in the doc comments). I've written overrides of these methods for most iterators that already override `nth`/`nth_back`, but those still need tests so I'll add them in a later PR.

cc @cuviper @scottmcm @Amanieu
2020-10-01 02:13:29 +02:00
bors
9bb55dc864 Auto merge of #76325 - lzutao:split-core-str, r=Amanieu
Split core/str/mod.rs to smaller files

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:
  ```bash
  git show --reverse --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space master..
  ```

---

I split `core/str/mod.rs` to these modules:

* `converts`: Contains helper functions to convert from bytes to str.
* `error`: For error structs like Utf8Error.
* `iter`: For iterators of many str methods.
* `traits`: For indexing operations and build in traits on str.
* `validations`: For functions validating utf8 --- This name is awkward, maybe utf8.rs is better.
2020-09-30 23:04:16 +00:00
bors
0d97f7a968 Auto merge of #77289 - TimDiekmann:alloc-ref-by-ref, r=Amanieu
Change `AllocRef::by_ref` to take `&self` instead of `&mut self`

r? `@Amanieu`
2020-09-29 22:13:37 +00:00
Mara Bos
81edbbc2bf Implement TryFrom between NonZero types. 2020-09-29 16:35:41 +02:00
Shahar Or (mightyiam)
badf4afdd5 core::global_allocator docs link to std::alloc::GlobalAlloc 2020-09-29 14:39:44 +07:00
kadmin
3f1d2aadd1 Use more efficient scheme for display u128/i128
Add zero padding

Add benchmarks for fmt u128

This tests both when there is the max amount of work(all characters used)
And least amount of work(1 character used)
2020-09-28 20:38:38 +00:00
Jacob Hughes
5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
Ralf Jung
aba966a592
Rollup merge of #77194 - pickfire:patch-7, r=withoutboats
Add doc alias for iterator fold

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

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

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

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

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

Helps with #76268.

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

r? @matklad
2020-09-28 18:39:39 +02:00
Tim Diekmann
c22d896b9b Change AllocRef::by_ref to take &self instead of &mut self 2020-09-28 10:42:29 +02:00
Dylan MacKenzie
3cbd17fcc6 Remove rustc_allow_const_fn_ptr
This was a hack to work around the lack of an escape hatch for the "min
`const fn`" checks in const-stable functions. Now that we have co-opted
`allow_internal_unstable` for this purpose, we no longer need the
bespoke attribute.
2020-09-27 10:46:41 -07:00
Dylan MacKenzie
1ff143191c Add a feature gate for basic function pointer use in const fn 2020-09-27 10:46:41 -07:00
Dániel Buga
89b8a97aea Refactor memchr to allow optimization 2020-09-27 15:10:48 +02:00
Jonas Schievink
5926c43743
Rollup merge of #77167 - fusion-engineering-forks:fix-fixme-min-max-sign-test, r=nagisa
Fix FIXME in core::num test: Check sign of zero in min/max tests.

r? nagisa

@rustbot modify labels: +C-cleanup
2020-09-27 01:53:20 +02:00
Ralf Jung
3b544e73ae
Rollup merge of #77122 - ecstatic-morse:const-fn-arithmetic, r=RalfJung,oli-obk
Add `#![feature(const_fn_floating_point_arithmetic)]`

cc #76618

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

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

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

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

CC @RalfJung
2020-09-26 12:58:12 +02:00
Lzu Tao
dce7248a39 Remove unneeded tidy comment 2020-09-26 05:20:53 +00:00
Lzu Tao
37cd79cd32 Gather all ZST structs of str together 2020-09-26 05:20:53 +00:00
Lzu Tao
653b5bf18c Move functions converting bytes to str to new mod 2020-09-26 05:20:53 +00:00
Lzu Tao
90c813a0f0 Move utf-8 validating helpers to new mod 2020-09-26 05:20:53 +00:00
Lzu Tao
5f0d724e29 Move str's impl of iterations to new mod 2020-09-26 05:20:51 +00:00
Lzu Tao
5b533fccf3 Move traits implementation of str to new mod
Also move FromStr trait
2020-09-26 05:04:58 +00:00
Lzu Tao
d31ca4fc8e Move Utf8Error to new mod 2020-09-26 05:04:58 +00:00
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
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
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
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
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
Austin Keeley
1d3717d17c Removing erroneous semicolon 2020-09-25 00:03:59 -04: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
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
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
Bastian Kauschke
5b3016134f use array::from_ref for slices 2020-09-23 21:56:23 +02: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
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
Ashley Mannix
9b2c8d866e revert const_type_id stabilization
This reverts commit e3856616ee.
2020-09-23 09:40:51 +10: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
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
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
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
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
blitzerr
d9d02fa168 Changing the alloc() to accept &self instead of &mut self 2020-09-21 16:43:36 -07:00
Alexis Bourget
5be843fc54 Move format-ref-cell 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
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
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
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
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
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
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
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
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
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
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
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
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
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
est31
562422ecf7 Remove some unused features from alloc core and std 2020-09-20 04:29:11 +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
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
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
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
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
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
Alexis Bourget
982ec0d0c9 Fix broken link 2020-09-18 11:14:36 +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
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
Alexis Bourget
76ec3f8d2b Move to intra doc links in core/src/future 2020-09-17 17:25:06 +02: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
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
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
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
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
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
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
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
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
Jubilee Young
247b73939a Move Wrapping<T> ui tests into library 2020-09-15 07:15:59 -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
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
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
Guillaume Gomez
d069c7e928 Stabilize doc_alias feature 2020-09-14 11:03:47 +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
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
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
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
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
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
Guillaume Gomez
bb9ce7cb01 Add missing examples on binary core traits 2020-09-11 23:43:37 +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
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
Guillaume Gomez
d7a9707051 Add missing examples on core traits' method 2020-09-10 14:34:43 +02: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
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
Camelid
884a1b4b9b Fix anchor links
#safety -> self#safety
2020-09-09 13:42:57 -07:00
Michael Howell
d85db82960 Add documentation for impl<T> From<T> for Poll<T> 2020-09-09 11:51:19 -07: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
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
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
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
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
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
marmeladema
b869aa5f31 Add saturating methods for Duration 2020-09-08 00:42:56 +01:00
Ralf Jung
caeb5544ec do not inline black_box when building for Miri 2020-09-07 11:31:37 +02:00
bors
f76eda3f01 Auto merge of #76395 - dylni:adjust-documentation-for-slice-check-range, r=jyn514
Adjust documentation for slice_check_range

Adjust documentation for #76393.
2020-09-07 09:16:46 +00:00
bors
c133aac1e9 Auto merge of #76409 - jonas-schievink:fix-r-a-on-libcore, r=Mark-Simulacrum
Remove unneeded `#[cfg(not(test))]` from libcore

This fixes rust-analyzer inside these modules (currently it does not analyze them, assuming they're configured out).
2020-09-07 02:20:44 +00:00
Dylan DPC
5d8925905c
Rollup merge of #76358 - Wilfred:patch-3, r=lcnr
Minor grammar fix in doc comment for soft-deprecated methods
2020-09-07 01:18:15 +02:00
Dylan DPC
9f69a232a6
Rollup merge of #76338 - euclio:intra-link-iterator, r=jyn514
add some intra-doc links to `Iterator`
2020-09-07 01:18:08 +02:00
Dylan DPC
acd33e1d14
Rollup merge of #76318 - scottmcm:one-control-flow, r=ecstatic-morse
Use ops::ControlFlow in rustc_data_structures::graph::iterate

Since I only know about this because you mentioned it,
r? @ecstatic-morse

If we're not supposed to use new `core` things in compiler for a while then feel free to close, but it felt reasonable to merge the two types since they're the same, and it might be convenient for people to use `?` in their traversal code.

(This doesn't do the type parameter swap; NoraCodes has signed up to do that one.)
2020-09-07 01:18:05 +02:00
Dylan DPC
8ff13f4fd2
Rollup merge of #76309 - lzutao:indent-note, r=jyn514
Indent a note to make folding work nicer

Sublime Text folds code based on indentation. It maybe an unnecessary change, but does it look nicer after that ?
2020-09-07 01:18:01 +02:00
Dylan DPC
52d9162645
Rollup merge of #76305 - CDirkx:const-tests, r=matklad
Move various ui const tests to `library`

Move:
 - `src\test\ui\consts\const-nonzero.rs` to `library\core`
 - `src\test\ui\consts\ascii.rs` to `library\core`
 - `src\test\ui\consts\cow-is-borrowed` to `library\alloc`

Part of #76268

r? @matklad
2020-09-07 01:17:59 +02:00
Dylan DPC
ee840db718
Rollup merge of #76302 - jyn514:peekable-2, r=Dylan-DPC
Address review comments on `Peekable::next_if`

r? @pickfire
See https://github.com/rust-lang/rust/pull/72310#pullrequestreview-480895893 for context.
2020-09-07 01:17:54 +02:00
Dylan DPC
7ad2b3ab29
Rollup merge of #76287 - lzutao:rm-allowed, r=jyn514
Remove an unnecessary allowed lint

It is outdated.
2020-09-07 01:17:48 +02:00
bors
73dc675b94 Auto merge of #76157 - ArekPiekarz:const_caller_location_tracking_issue, r=joshtriplett
Update tracking issue for const_caller_location

Update the tracking issue to https://github.com/rust-lang/rust/issues/76156, as suggested in https://github.com/rust-lang/rust/issues/76105.
2020-09-06 20:27:51 +00:00
bors
5d74e88006 Auto merge of #75949 - vext01:filter-docs, r=jyn514
Try to improve the documentation of `filter()` and `filter_map()`.

I believe the documentation is currently a little misleading.

For example, in the docs for `filter()`:

> If the closure returns `false`, it will try again, and call the closure on
> the next element, seeing if it passes the test.

This kind of implies that if the closure returns true then we *don't* "try
again" and no further elements are considered. In actuality that's not the
case, every element is tried regardless of what happened with the previous
element.

This change tries to clarify that by removing the uses of "try again"
altogether.
2020-09-06 18:26:33 +00:00
Jonas Schievink
24dc182f20 Remove unneeded #[cfg(not(test))] from libcore 2020-09-06 16:00:28 +02:00
bors
aa81d32165 Auto merge of #76128 - poliorcetics:doc-use-arc-clone, r=KodrAus
Use Arc::clone and Rc::clone in documentation

This PR replaces uses of `x.clone()` by `Rc::clone(&x)` (or `Arc::clone(&x)`) to better match the documentation for those types.

@rustbot modify labels: T-doc
2020-09-06 12:34:31 +00:00
dylni
cf529c767e Adjust documentation for slice_check_range 2020-09-05 19:53:35 -04:00
Edd Barrett
8af85fa1f7 Improve the documentation of filter() and filter_map().
I believe the documentation is currently a little misleading.

For example, in the docs for `filter()`:

> If the closure returns `false`, it will try again, and call the closure on
> the next element, seeing if it passes the test.

This kind of implies that if the closure returns true then we *don't* "try
again" and no further elements are considered. In actuality that's not the
case, every element is tried regardless of what happened with the previous
element.

This change tries to clarify that by removing the uses of "try again"
altogether.
2020-09-05 19:59:30 +01:00
Ralf Jung
35068326b5 document remaining unsafety in maybe_uninit.rs 2020-09-05 17:24:22 +02:00
Ralf Jung
cff5f56886 rename MaybeUninit slice methods
first_ptr -> slice_as_ptr
first_ptr_mut -> slice_as_mut_ptr
slice_get_ref -> slice_assume_init_ref
slice_get_mut -> slice_assume_init_mut
2020-09-05 17:24:22 +02:00
Ayush Kumar Mishra
dc37b553ac Minor refactoring 2020-09-05 17:07:53 +05:30
Ayush Kumar Mishra
941dca8ed2 Add Arith Tests in Library 2020-09-05 16:52:52 +05:30
Josh Stone
86b9f710d0 Move ArrayChunksMut::get_unchecked per #73565 2020-09-04 20:08:12 -07:00
Josh Stone
21903532ee Build the slice directly in array_chunks_mut
Review discussion found that the concern about aliasing was overblown,
so we can simplify this to cast from one slice to another directly.
2020-09-04 19:51:29 -07:00
Josh Stone
b9fd6734e8 Add tests for array_chunks_mut 2020-09-04 19:51:29 -07:00
Josh Stone
f6a6d2fef6 Add slice::array_chunks_mut 2020-09-04 19:51:29 -07:00
Wilfred Hughes
4806e0ac93
Minor grammar fix in doc comment for soft-deprecated methods 2020-09-04 19:50:54 -07:00
Lzu Tao
dfd219d6e7 Indent a note to make folding work nicer
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-05 02:17:22 +00:00
Scott McMurray
59e37332b0 Add BREAK too, and improve the comments 2020-09-04 16:28:23 -07:00
Andy Russell
2ed1a21790
add some intra-doc links to Iterator 2020-09-04 15:51:58 -04:00
bors
ef55a0a92f Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAus
Add `slice::check_range`

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

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

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

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

[`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html
[`usize::MAX`]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.MAX
[`Vec::drain`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
2020-09-04 12:21:43 +00:00
Scott McMurray
fac272688e Use ops::ControlFlow in graph::iterate 2020-09-04 01:45:10 -07:00
Lzu Tao
a3ee65f87e Remove a useless allowed attr 2020-09-04 02:42:50 +00:00