Commit graph

1069 commits

Author SHA1 Message Date
Albin Hedman
0cea1c9206 Added reference to tracking issue #80377 2020-12-26 14:03:28 +01:00
bors
780b094d76 Auto merge of #80209 - erikdesjardins:ptrcmp, r=Mark-Simulacrum
Remove pointer comparison from slice equality

This resurrects #71735.

Fixes #71602, helps with #80140.

r? `@Mark-Simulacrum`
2020-12-26 06:43:51 +00:00
bors
733cb54d18 Remove pointer comparison from slice equality
This resurrects #71735.

Fixes #71602, helps with #80140.

r? `@Mark-Simulacrum`
2020-12-26 06:43:51 +00:00
Albin Hedman
5e27765ddf Add tests 2020-12-26 03:45:51 +01:00
Albin Hedman
1975a6e710 Constify MaybeUninit::assume_init_read 2020-12-26 02:25:38 +01:00
Albin Hedman
d4fd7987b5 Constify *const T::read[_unaligned] and *mut T::read[_unaligned] 2020-12-26 02:25:38 +01:00
Albin Hedman
7594d2a084 Constify ptr::read and ptr::read_unaligned 2020-12-26 02:25:08 +01:00
Albin Hedman
1b77f8e6ea Constify intrinsics::copy[_nonoverlapping] 2020-12-26 02:22:29 +01:00
Dylan DPC
21d36e0daf
Rollup merge of #79213 - yoshuawuyts:stabilize-slice-fill, r=m-ou-se
Stabilize `core::slice::fill`

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

Stabilizes the `core::slice::fill` API in Rust 1.50, adding a `memset` doc alias so people coming from C/C++ looking for this operation can find it in the docs. This API hasn't seen any changes since we changed the signature in https://github.com/rust-lang/rust/pull/71165/, and it seems like the right time to propose stabilization. Thanks!

r? `@m-ou-se`
2020-12-25 03:39:31 +01:00
bors
87eecd40e8 Auto merge of #79261 - faern:deprecate-compare-and-swap, r=Amanieu
Deprecate atomic compare_and_swap method

Finish implementing [RFC 1443](https://github.com/rust-lang/rfcs/blob/master/text/1443-extended-compare-and-swap.md) (https://github.com/rust-lang/rfcs/pull/1443).

It was decided to deprecate `compare_and_swap` [back in Rust 1.12 already](https://github.com/rust-lang/rust/issues/31767#issuecomment-215903038). I can't find any info about that decision being reverted. My understanding is just that it has been forgotten. If there has been a decision on keeping `compare_and_swap` then it's hard to find, and even if this PR does not go through it can act as a place where people can find out about the decision being reverted.

Atomic operations are hard to understand, very hard. And it does not help that there are multiple similar methods to do compare and swap with. They are so similar that for a reader it might be hard to understand the difference. This PR aims to make that simpler by finally deprecating `compare_and_swap` which is essentially just a more limited version of `compare_exchange`. The documentation is also updated (according to the RFC text) to explain the differences a bit better.

Even if we decide to not deprecate `compare_and_swap`. I still think the documentation for the atomic operations should be improved to better describe their differences and similarities. And the documentation can be written nicer than the PR currently proposes, but I wanted to start somewhere. Most of it is just copied from the RFC.

The documentation for `compare_exchange` and `compare_exchange_weak` indeed describe how they work! The problem is that they are more complex and harder to understand than `compare_and_swap`. So for someone who does not fully grasp this they might fall back to using `compare_and_swap`. Making the documentation outline the similarities and differences might build a bridge for people so they can cross over to the more powerful and sometimes more efficient operations.

The conversions I do to avoid the `std` internal deprecation errors are very straight forward `compare_and_swap -> compare_exchange` changes where the orderings are just using the mapping in the new documentation. Only in one place did I use `compare_exchange_weak`. This can probably be improved further. But the goal here was not for those operations to be perfect. Just to not get worse and to allow the deprecation to happen.
2020-12-23 09:32:38 +00:00
bors
0fe1dc6ac2 Auto merge of #79451 - usbalbin:array_zip, r=m-ou-se
Added [T; N]::zip()

This is my first PR to rust so I hope I have done everything right, or at least close :)

---

This is PR adds the array method `[T; N]::zip()` which, in my mind, is a natural extension to #75212.

My implementation of `zip()` is mostly just a modified copy-paste of `map()`. Should I keep the comments? Also am I right in assuming there should be no way for the `for`-loop to panic, thus no need for the dropguard seen in the `map()`-function?

The doc comment is in a similar way a slightly modified copy paste of [`Iterator::zip()`](https://doc.rust-lang.org/beta/std/iter/trait.Iterator.html#method.zip)

`@jplatte` mentioned in [#75490](https://github.com/rust-lang/rust/pull/75490#issuecomment-677790758) `zip_with()`,
> zip and zip_with seem like they would be useful :)

is this something I should add (assuming there is interest for this PR at all :))
2020-12-22 13:19:40 +00:00
Linus Färnstrand
3eef20ffa0 Improve documentation on success and failure arguments 2020-12-22 12:19:46 +01:00
Linus Färnstrand
7f35e2d573 Add doc aliases to compare_exchange[_weak] 2020-12-22 12:19:46 +01:00
Linus Färnstrand
828d4ace4d Migrate standard library away from compare_and_swap 2020-12-22 12:19:46 +01:00
Linus Färnstrand
4252e48256 Add documentation on migrating away from compare_and_swap 2020-12-22 12:17:43 +01:00
Linus Färnstrand
3abba5e21f Deprecate compare_and_swap on all atomic types 2020-12-22 12:17:43 +01:00
Yoshua Wuyts
c2281cc189 Stabilize core::slice::fill 2020-12-22 00:16:04 +01:00
Tomasz Miąsko
4ad53dc9f5 Use pointer type in AtomicPtr::swap implementation 2020-12-20 00:00:00 +00:00
bors
59aaa2a04b Auto merge of #80123 - DrMeepster:maybe_uninit_write_slice, r=RalfJung
Fix memory leak in test "mem::uninit_write_slice_cloned_no_drop"

This fixes #80116. I replaced the `Rc` based method I was using with a type that panics when dropped.
2020-12-20 10:08:56 +00:00
bors
c1d5843661 Auto merge of #79473 - m-ou-se:clamp-in-core, r=m-ou-se
Move {f32,f64}::clamp to core.

`clamp` was recently stabilized (tracking issue: https://github.com/rust-lang/rust/issues/44095). But although `Ord::clamp` was added in `core` (because `Ord` is in `core`), the versions for the `f32` and `f64` primitives were added in `std` (together with `floor`, `sin`, etc.), not in `core` (together with `min`, `max`, `from_bits`, etc.).

This change moves them to `core`, such that `clamp` on floats is available in `no_std` programs as well.
2020-12-19 21:57:38 +00:00
DrMeepster
28e0d2f234
Fix unused import error on wasm 2020-12-18 14:53:55 -08:00
bors
6340607aca Auto merge of #79485 - EllenNyan:stabilize_unsafe_cell_get_mut, r=m-ou-se
Stabilize `unsafe_cell_get_mut`

Tracking issue: #76943

r? `@m-ou-se`
2020-12-18 11:39:26 +00:00
DrMeepster
01f36c51c2 fix memory leak in test 2020-12-17 09:18:06 -08:00
Ohad Ravid
1e9e30dc40 Added impl Rem<NonZeroU{0}> for u{0} which cannot panic 2020-12-17 18:42:19 +02:00
Ohad Ravid
3f671bc944 Added impl Div<NonZeroU{0}> for u{0} which cannot panic 2020-12-17 18:41:47 +02:00
Guillaume Gomez
93f1c67e91
Rollup merge of #80035 - ChayimFriedman2:patch-1, r=nagisa
Optimization for bool's PartialOrd impl

Fix #80034.
2020-12-17 11:36:51 +01:00
Albin Hedman
8b3725973a Added reference to tracking issue 2020-12-17 00:27:21 +01:00
Simon Sapin
f365de353a Add popcount and popcnt as doc aliases for count_ones methods.
Integer types have a `count_ones` method that end up calling
`intrinsics::ctpop`.
On some architectures, that intrinsic is translated as a corresponding
CPU instruction know as "popcount" or "popcnt".

This PR makes it so that searching for those names in rustdoc shows those methods.

CC https://blog.rust-lang.org/2020/11/19/Rust-1.48.html#adding-search-aliases
2020-12-17 00:22:48 +01:00
Albin Hedman
baa5e47106
Update doc comment
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-12-16 21:12:10 +01:00
Albin Hedman
be2c8f2d43 Update zip for better codegen, see discussion 2020-12-16 18:35:56 +01:00
bors
ddbc6176de Auto merge of #79607 - DrMeepster:maybe_uninit_write_slice, r=m-ou-se
MaybeUninit::copy/clone_from_slice

This PR adds 2 new methods to MaybeUninit under the feature of `maybe_uninit_write_slice`: `copy_from_slice` and `clone_from_slice`.

These are useful for initializing uninitialized buffers (such as the one returned by `Vec::spare_capacity_mut` for example) with initialized data.

The methods behave similarly to the methods on slices, but the destination is uninitialized and they return the destination slice as an initialized slice.
2020-12-16 06:26:51 +00:00
DrMeepster
4652a13f44 write_slice(_cloned) 2020-12-15 12:21:33 -08:00
Chayim Refael Friedman
777ca999a9 Optimization for bool's PartialOrd impl 2020-12-14 23:32:52 +02:00
Yuki Okushi
1698773263
Rollup merge of #79360 - wchargin:wchargin-doc-iter-by-reference, r=m-ou-se
std::iter: document iteration over `&T` and `&mut T`

A colleague of mine is new to Rust, and mentioned that it was “slightly
confusing” to figure out what `&mut` does in iterating over `&mut foo`:

```rust
for value in &mut self.my_vec {
    // ...
}
```

My colleague had read the `std::iter` docs and not found the answer
there. There is a brief section at the top about “the three forms of
iteration”, which mentions `iter_mut`, but it doesn’t cover the purpose
of `&mut coll` for a collection `coll`. This patch adds an explanatory
section to the docs. I opted to create a new section so that it can
appear after the note that `impl<I: Iterator> IntoIterator for I`, and
it’s nice for the existing “three forms of iteration” to appear near the
top.

Test Plan:
Ran `./x.py doc library/core`, and the result looked good, including
links. Manually copy-pasted the two doctests into the playground and ran
them.

wchargin-branch: doc-iter-by-reference
2020-12-13 11:05:22 +09:00
bors
2225ee1b62 Auto merge of #79925 - camelid:flatten-docs, r=scottmcm
Improve wording of `flatten()` docs
2020-12-11 15:18:47 +00:00
Tyler Mandry
c94345e3c2
Rollup merge of #79871 - Pratyush:patch-1, r=joshtriplett
Fix small typo in `wrapping_shl` documentation

Fixes a small typo in the documentation.
2020-12-10 21:33:15 -08:00
Camelid
97cd55e962 Improve wording of flatten() docs 2020-12-10 20:36:12 -08:00
bors
0c9ef564a7 Auto merge of #79656 - jnqnfe:ordering, r=sfackler
Add some core::cmp::Ordering helpers

...to allow easier equal-to-or-greater-than and less-than-or-equal-to
comparisons.

Prior to Rust 1.42 a greater-than-or-equal-to comparison might be written
either as a match block, or a traditional conditional check like this:

```rust
if cmp == Ordering::Equal || cmp == Ordering::Greater {
    // Do something
}
```

Which requires two instances of `cmp`. Don't forget that while `cmp` here
is very short, it could be something much longer in real use cases.

From Rust 1.42 a nicer alternative is possible:

```rust
if matches!(cmp, Ordering::Equal | Ordering::Greater) {
    // Do something
}
```

The commit adds another alternative which may be even better in some cases:

```rust
if cmp.is_equal_or_greater() {
    // Do something
}
```

The earlier examples could be cleaner than they are if the variants of
`Ordering` are imported such that `Equal`, `Greater` and `Less` can be
referred to directly, but not everyone will want to do that.

The new solution can shorten lines, help avoid logic mistakes, and avoids
having to import `Ordering` / `Ordering::*`.
2020-12-11 03:08:32 +00:00
Lyndon Brown
169c59ff0f Add some core::cmp::Ordering helpers
...to allow easier greater-than-or-equal-to and less-than-or-equal-to
comparisons, and variant checking without needing to import the enum,
similar to `Option::is_none()` / `Option::is_some()`, in situations where
you are dealing with an `Ordering` value. (Simple `PartialOrd` / `Ord`
based evaluation may not be suitable for all situations).

Prior to Rust 1.42 a greater-than-or-equal-to comparison might be written
either as a match block, or a traditional conditional check like this:

```rust
if cmp == Ordering::Equal || cmp == Ordering::Greater {
    // Do something
}
```

Which requires two instances of `cmp`. Don't forget that while `cmp` here
is very short, it could be something much longer in real use cases.

From Rust 1.42 a nicer alternative is possible:

```rust
if matches!(cmp, Ordering::Equal | Ordering::Greater) {
    // Do something
}
```

The commit adds another alternative which may be even better in some cases:

```rust
if cmp.is_ge() {
    // Do something
}
```

The earlier examples could be cleaner than they are if the variants of
`Ordering` are imported such that `Equal`, `Greater` and `Less` can be
referred to directly, but not everyone will want to do that.

The new solution can shorten lines, help avoid logic mistakes, and avoids
having to import `Ordering` / `Ordering::*`.
2020-12-10 20:32:12 +00:00
Clément Renault
b2a7076b10
Implement a user friendly Debug on GroupBy and GroupByMut 2020-12-10 19:44:37 +01:00
Clément Renault
7952ea5a04
Fix the fmt issues 2020-12-10 19:44:37 +01:00
Clément Renault
45693b43a5
Mute the file-length error 2020-12-10 18:36:07 +01:00
Clément Renault
5190fe4979
Mark the Iterator last self parameter as mut 2020-12-10 11:58:52 +01:00
Clément Renault
6a5a60048d
Indicate the anonymous lifetime of the GroupBy and GroupByMut 2020-12-10 11:47:15 +01:00
bors
39b841dfe3 Auto merge of #79621 - usbalbin:constier_maybe_uninit, r=RalfJung
Constier maybe uninit

I was playing around trying to make `[T; N]::zip()` in #79451 be `const fn`. One of the things I bumped into was `MaybeUninit::assume_init`. Is there any reason for the intrinsic `assert_inhabited<T>()` and therefore `MaybeUninit::assume_init` not being `const`?

---

I have as best as I could tried to follow the instruction in [library/core/src/intrinsics.rs](https://github.com/rust-lang/rust/blob/master/library/core/src/intrinsics.rs#L11). I have no idea what I am doing but it seems to compile after some slight changes after the copy paste. Is this anywhere near how this should be done?

Also any ideas for name of the feature gate? I guess `const_maybe_assume_init` is quite misleading since I have added some more methods. Should I add test? If so what should be tested?
2020-12-10 10:46:38 +00:00
Clément Renault
0ebf8e13f0
Import the GroupBy and GroupByMut in the slice module 2020-12-10 11:41:43 +01:00
Clément Renault
1b406afe23
Use none as the issue instead of 0 2020-12-10 11:37:40 +01:00
Clément Renault
005912fce8
Implement last on the GroupBy and GroupByMut Iterators 2020-12-10 11:22:29 +01:00
Clément Renault
e16eaeaa11
Implement size_hint on the GroupBy and GroupByMut Iterators 2020-12-10 11:22:20 +01:00
Clément Renault
1c55a73b75
Implement it with only safe code 2020-12-10 11:20:15 +01:00
Clément Renault
a891f6edfe
Introduce the GroupBy and GroupByMut Iterators 2020-12-10 10:16:29 +01:00
Tomasz Miąsko
cf5bd26329 Describe why size_align have not been inlined so far 2020-12-10 00:00:00 +00:00
Pratyush Mishra
56d9784b5a
Fix typo in wrapping_shl documentation 2020-12-09 15:14:58 -08:00
Max Sharnoff
72a7f73610
Apply suggestions from code review
Co-authored-by: Camelid <camelidcamel@gmail.com>
2020-12-09 23:13:24 +00:00
sharnoff
1c36bb2f69 add docs note about Any::type_id on smart pointers 2020-12-09 22:43:59 +00:00
bors
1cc4107109 Auto merge of #79867 - tmandry:rollup-7mubs3b, r=tmandry
Rollup of 12 pull requests

Successful merges:

 - #79732 (minor stylistic clippy cleanups)
 - #79750 (Fix trimming of lint docs)
 - #79777 (Remove `first_merge` from liveness debug logs)
 - #79795 (Privatize some of libcore unicode_internals)
 - #79803 (Update xsv to prevent random CI failures)
 - #79810 (Account for gaps in def path table during decoding)
 - #79818 (Fixes to Rust coverage)
 - #79824 (Strip prefix instead of replacing it with empty string)
 - #79826 (Simplify visit_{foreign,trait}_item)
 - #79844 (Move RWUTable to a separate module)
 - #79861 (Update LLVM submodule)
 - #79862 (Remove tab-lock and replace it with ctrl+up/down arrows to switch between search result tabs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-09 22:21:55 +00:00
Tyler Mandry
26e4cf0fc7
Rollup merge of #79795 - matklad:unicode-private, r=cramertj
Privatize some of libcore unicode_internals

My understanding is that these API are perma unstable, so it doesn't
make sense to pollute docs & IDE completion[1] with them.

[1]: https://github.com/rust-analyzer/rust-analyzer/issues/6738
2020-12-09 13:38:22 -08:00
bors
f0f68778f7 Auto merge of #77611 - oli-obk:atomic_miri_leakage, r=nagisa
Directly use raw pointers in `AtomicPtr` store/load

I was unable to find any reason for this limitation in the latest source of LLVM or in the documentation [here](http://llvm.org/docs/Atomics.html#libcalls-atomic).

fixes https://github.com/rust-lang/miri/issues/1574
2020-12-09 19:53:23 +00:00
Albin Hedman
077527170b Make write and slice_as_[mut_]_ptr const 2020-12-08 00:07:34 +01:00
Albin Hedman
174935988f Make assume_init_{ref,mut} const 2020-12-08 00:05:26 +01:00
bors
b5ff9c3d05 Auto merge of #79773 - lcnr:type-visitor, r=oli-obk
small `TypeVisitor` refactor

cc `@LeSeulArtichaut` `@scottmcm`

adds `ControlFlow::map_break`
2020-12-07 15:07:09 +00:00
Bastian Kauschke
e3e4870bce small TypeVisitor refactor 2020-12-07 15:52:59 +01:00
Aleksey Kladov
88da5682c3 Privatize some of libcore unicode_internals
My understanding is that these API are perma unstable, so it doesn't
make sense to pollute docs & IDE completion[1] with them.

[1]: https://github.com/rust-analyzer/rust-analyzer/issues/6738
2020-12-07 16:16:42 +03:00
bors
e5721a5283 Auto merge of #79641 - sourcefrog:split-example, r=dtolnay
Add a doctest example of str::split on a slice of chars

This is mentioned as supported, but the semantics are not described.
2020-12-07 06:05:34 +00:00
Albin Hedman
d0a1e40eae Remove unused feature gate 2020-12-06 22:29:13 +01:00
Albin Hedman
4255a5afd5 Moved failing test to src/test/ui/
Still have not figured out how to make it work
2020-12-06 19:01:03 +01:00
Albin Hedman
94762417e8 Still unable to get the tests working 2020-12-05 19:41:02 +01:00
Albin Hedman
7bd754cf8c Fix tests (hopefully) 2020-12-05 18:39:10 +01:00
oli
fda4c8d5c1 Update documentation to review comments 2020-12-04 17:28:22 +00:00
Tim Diekmann
9274b37d99 Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
Dylan DPC
88f0c72dc6
Rollup merge of #79611 - poliorcetics:use-std-in-docs, r=jyn514
Use more std:: instead of core:: in docs for consistency

``@rustbot`` label T-doc

Some cleanup work to use `std::` instead of `core::` in docs as much as possible. This helps with terminology and consistency, especially for newcomers from other languages that have often heard of `std` to describe the standard library but not of `core`.

Edit: I also added more intra doc links when I saw the opportunity.
2020-12-04 03:30:27 +01:00
bors
d015f0d921 Auto merge of #79594 - vn-ki:const-eval-intrinsic, r=oli-obk
add const_allocate intrinsic

r? `@oli-obk`

fixes #75390
2020-12-03 09:44:07 +00:00
Albin Hedman
4f9fd2a5d4 Undo fn -> const fn for all intrinsics but assert_inhabited 2020-12-02 21:07:40 +01:00
Albin Hedman
f311db100b Added tests for assume_init 2020-12-02 19:14:10 +01:00
Martin Pool
0273f6f849 Add a doctest example of str::split on a slice of chars
This is mentioned as supported, but the semantics are not described.
2020-12-02 08:54:42 -08:00
Albin Hedman
1ef5dbe716 Resolved some of the comments
* Undo fn -> const fn for some fns.
* Split feature gate.
* Made all three intrinsics const
2020-12-02 16:17:37 +01:00
Albin Hedman
91772c35c8 Even more const 2020-12-02 03:22:47 +01:00
Albin Hedman
8bd80e25f0 Make some of MaybeUninit's methods const 2020-12-02 03:22:47 +01:00
Alexis Bourget
4eb76fcc8e Use more std:: instead of core:: in docs for consistency, add more intra doc links 2020-12-02 00:41:53 +01:00
Vishnunarayan K I
b5b811aab4 review comments 2020-12-01 19:48:09 +05:30
Mara Bos
b565fe241e
Rollup merge of #79038 - CDirkx:move-ui-tests, r=dtolnay
Change ui test that are run-pass and that do not test the compiler to library tests

Part of #76268, these are some of the relevant ui tests I found that can be replaced by library tests.

Note: this PR just moves the tests, I have not checked for any overlap between these tests and existing library tests. The only test I changed is `env_home_dir`, where I added code to restore the old home dir after testing.

All moved tests:

| ui test | library test file | test |
| --- | --- | --- |
| `const\ascii_ctype.rs` | `core\tests\ascii.rs` | `ascii_ctype_const` |
| `const\const-str-ptr.rs` | `alloc\tests\str.rs` | `const_str_ptr` |
| `assert-eq-trailing-comma.rs` | `core\tests\macros.rs` | `assert_eq_trailing_comma` |
| `assert-escape.rs` | `core\tests\macros.rs` | `assert_escape` |
| `assert-ne-trailing-comma.rs` | `core\tests\macros.rs` | `assert_ne_trailing_comma` |
| `atomic-access-bool.rs` | `core\tests\atomic.rs` | `atomic_access_bool` |
| `atomic-alignment.rs` | `core\tests\atomic.rs` | `atomic_alignment` |
| `atomic-compare_exchange.rs` | `core\tests\atomic.rs` | `atomic_compare_exchange` |
| ~~`atomic-print.rs`~~ | ~~`std\tests\process.rs`~~ | ~~`atomic_print`~~ |
| `bool.rs` | `core\tests\bool.rs` | `test_bool` |
| `bool_not.rs` | `core\tests\bool.rs` | `test_bool_not` |
| `char_unicode.rs` | `core\tests\unicode.rs` | `version` |
| `cmp-default.rs` | `core\tests\cmp.rs` | `cmp_default` |
| `deref-mut-on-ref.rs` | `core\tests\ops.rs` | `deref_mut_on_ref` |
| `deref-on-ref.rs` | `core\tests\ops.rs` | `deref_on_ref` |
| `env-home-dir.rs` | `std\tests\env.rs` | `env_home_dir` |
| ~~`env-vars.rs`~~ | ~~`std\tests\env.rs`~~ | ~~`env_vars`~~ |
| `extend-for-unit.rs` | `core\tests\iter.rs` | `extend_for_unit` |
| `offset_from.rs` | `core\tests\ptr.rs` | `offset_from` |
| `option-ext.rs` | `core\tests\option.rs` | `option_ext` |
| `result-opt-conversions.rs` | `core\tests\result.rs` | `result_opt_conversions` |
| `sleep.rs` | `std\tests\thread.rs` | `sleep` |
| ~~`try-wait.rs`~~ | ~~`std\tests\process.rs`~~ | ~~`try_wait`~~ |
| `utf8.rs` | `alloc\tests\str.rs` | `utf8` |
| `utf8_chars.rs` | `alloc\tests\str.rs` | `utf8_chars` |
| `wrapping-int-api.rs` | `core\tests\num\wrapping.rs` | `wrapping_int_api` |
2020-12-01 10:50:02 +00:00
Vishnunarayan K I
528355c541 add const_allocate intrisic 2020-12-01 15:39:25 +05:30
Alexis Bourget
5bdd640913 Fix several broken links in doc that used the wrong qualifier or Self:: 2020-11-30 21:21:15 +01:00
Alexis Bourget
c0560c2755 Back to #method for links on char 2020-11-30 21:18:56 +01:00
Alexis Bourget
af40c04301 ptr links 2020-11-30 21:18:56 +01:00
Alexis Bourget
ac8d1173b5 Use core::primitive module instead of prim@ 2020-11-30 21:18:56 +01:00
Alexis Bourget
a5726eb28d Use Self:: in links 2020-11-30 21:18:56 +01:00
Alexis Bourget
b702060865 Intra doc links for iterator adapters 2020-11-30 21:18:55 +01:00
Alexis Bourget
b3b1e0c224 Intra doc links for f32/f64 2020-11-30 21:18:55 +01:00
Alexis Bourget
4e54b4c3e6 Intra doc links for the pointer primitive 2020-11-30 21:18:55 +01:00
Alexis Bourget
9c27ccff19 Intra doc links for str/mod.rs 2020-11-30 21:18:55 +01:00
Alexis Bourget
0bf4aafc54 Intra doc links for the char primitive 2020-11-30 21:18:55 +01:00
Alexis Bourget
19fb4fec50 Intra doc links for cell.rs 2020-11-30 21:18:55 +01:00
Christiaan Dirkx
be554c4101 Make ui test that are run-pass and do not test the compiler itself library tests 2020-11-30 02:47:32 +01:00
bors
cf9bfdb872 Auto merge of #78122 - fusion-engineering-forks:fmt-write-bounds-check, r=Mark-Simulacrum
Avoid panic_bounds_check in fmt::write.

Writing any fmt::Arguments would trigger the inclusion of usize formatting and padding code in the resulting binary, because indexing used in fmt::write would generate code using panic_bounds_check, which prints the index and length.

These bounds checks are not necessary, as fmt::Arguments never contains any out-of-bounds indexes.

This change replaces them with unsafe get_unchecked, to reduce the amount of generated code, which is especially important for embedded targets.

---

Demonstration of the size of and the symbols in a 'hello world' no_std binary:

<details>
<summary>Source code</summary>

```rust
#![feature(lang_items)]
#![feature(start)]
#![no_std]

use core::fmt;
use core::fmt::Write;

#[link(name = "c")]
extern "C" {
    #[allow(improper_ctypes)]
    fn write(fd: i32, s: &str) -> isize;
    fn exit(code: i32) -> !;
}

struct Stdout;

impl fmt::Write for Stdout {
    fn write_str(&mut self, s: &str) -> fmt::Result {
        unsafe { write(1, s) };
        Ok(())
    }
}

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
    let _ = writeln!(Stdout, "Hello World");
    0
}

#[lang = "eh_personality"]
fn eh_personality() {}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    unsafe { exit(1) };
}
```
</details>

Before:
```
   text	   data	    bss	    dec	    hex	filename
   6059	    736	      8	   6803	   1a93	before
```
```
0000000000001e00 T <T as core::any::Any>::type_id
0000000000003dd0 D core::fmt::num::DEC_DIGITS_LUT
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for u64>::fmt
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for usize>::fmt
0000000000001370 T core::fmt::write
0000000000001b30 t core::fmt::Formatter::pad_integral::write_prefix
0000000000001660 T core::fmt::Formatter::pad_integral
0000000000001350 T core::ops::function::FnOnce::call_once
0000000000001b80 t core::ptr::drop_in_place
0000000000001120 t core::ptr::drop_in_place
0000000000001c50 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001c90 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001b90 T core::panicking::panic_bounds_check
0000000000001c10 T core::panicking::panic_fmt
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```

After:
```
   text	   data	    bss	    dec	    hex	filename
   3068	    600	      8	   3676	    e5c	after
```
```
0000000000001360 T core::fmt::write
0000000000001340 T core::ops::function::FnOnce::call_once
0000000000001120 t core::ptr::drop_in_place
0000000000001620 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001660 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```
2020-11-29 23:14:40 +00:00
Ellen
1a1a99ccb7 Change "non-unsafe" to "safe" in UnsafeCell docs 2020-11-29 20:27:14 +00:00
oli
392ea29757 Cast pointers to usize before passing them to atomic operations as some platforms do not support atomic operations on pointers. 2020-11-29 12:58:03 +00:00
bstrie
90a2e5e3fe Update tests to remove old numeric constants
Part of #68490.

Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros.

For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.
2020-11-29 00:55:55 -05:00
oli
aabe70f90e Directly use raw pointers in AtomicPtr store/load 2020-11-28 17:13:47 +00:00
Jonas Schievink
248e5ad299
Rollup merge of #79478 - lukaslueg:peek_mut_docs, r=m-ou-se
Expand docs on Peekable::peek_mut

Slightly expand docs on `std::iter::Peekable::peek_mut`, tracked in #78302

r? `@m-ou-se`
2020-11-28 15:58:28 +01:00
Julian Wollersberger
7438f43b7c Implement From<char> for u64 and u128. 2020-11-28 13:35:09 +01:00
Ellen
9db1f42fa2 Stabilize unsafe_cell_get_mut 2020-11-28 00:30:26 +00:00
Lukas Lueg
08ec201c72 Expand docs on Peekable::peek_mut 2020-11-27 22:50:22 +01:00
Mara Bos
0523eeb8a3 Move {f32,f64}::clamp to core. 2020-11-27 19:15:51 +01:00
Albin Hedman
2f35fb1e11 Remove redundant tests 2020-11-27 11:46:49 +01:00
Albin Hedman
3b8617b9b6 Added [T; N]::zip() 2020-11-26 23:22:36 +01:00
Aaron Hill
6f91c32da6
Fix new 'unnecessary trailing semicolon' warnings 2020-11-26 17:08:36 -05:00
bors
ec039bd075 Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obk
Rename `optin_builtin_traits` to `auto_traits`

They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.

r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-25 07:25:19 +00:00
bors
b387f62d4d Auto merge of #77491 - lukaslueg:peek_mut, r=m-ou-se
Proposal to add Peekable::peek_mut

A "peekable" iterator has a `peek()`-method which provides an immutable reference to the next item. We currently do not have a method to modify that item, which we could easily add via a `peek_mut()`. See the test for a use-case (alike to my original use case), where a "pristine" iterator is passed on after modifying its state via `peek_mut()`.

If there is interest in this, I can expand on the tests and docs.
2020-11-25 05:10:53 +00:00
bors
3f7ccb4cf5 Auto merge of #76688 - yokodake:patch-2, r=kodrAus
Document unsafety in core::slice::memchr

Contributes to #66219

Note sure if that's good enough, especially for the `align_to` call.
The docs only mention transmuting and I don't think that everything related to reference lifetimes and state validity mentioned in the [nomicon](https://doc.rust-lang.org/nomicon/transmutes.html) are relevant here.
2020-11-25 02:49:28 +00:00
William Chargin
6edc90a3e2 [update patch]
wchargin-branch: doc-iter-by-reference
wchargin-source: e4069ac9a9d73860467cea74cf3ae1605af37d74
2020-11-23 15:46:13 -08:00
Lukas Lueg
3b015622be Add Peekable::peek_mut 2020-11-23 23:52:19 +01:00
Camelid
810324d1f3 Rename optin_builtin_traits to auto_traits
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
bors
f32a0cce2f Auto merge of #78343 - camelid:macros-qualify-panic, r=m-ou-se
Qualify `panic!` as `core::panic!` in non-built-in `core` macros

Fixes #78333.

-----

Otherwise code like this

    #![no_implicit_prelude]

    fn main() {
        ::std::todo!();
        ::std::unimplemented!();
    }

will fail to compile, which is unfortunate and presumably unintended.

This changes many invocations of `panic!` in a `macro_rules!` definition
to invocations of `$crate::panic!`, which makes the invocations hygienic.

Note that this does not make the built-in macro `assert!` hygienic.
2020-11-23 22:05:28 +00:00
William Chargin
ce3d60476a std::iter: document iteration over &T and &mut T
A colleague of mine is new to Rust, and mentioned that it was “slightly
confusing” to figure out what `&mut` does in iterating over `&mut foo`:

```rust
for value in &mut self.my_vec {
    // ...
}
```

My colleague had read the `std::iter` docs and not found the answer
there. There is a brief section at the top about “the three forms of
iteration”, which mentions `iter_mut`, but it doesn’t cover the purpose
of `&mut coll` for a collection `coll`. This patch adds an explanatory
section to the docs. I opted to create a new section so that it can
appear after the note that `impl<I: Iterator> IntoIterator for I`, and
it’s nice for the existing “three forms of iteration” to appear near the
top.

Implementation note: I haven’t linkified the references to `HashSet` and
`HashMap`, since those are in `std` and these docs are in `core`;
linkifying them gave an “unresolved link” rustdoc error.

Test Plan:
Ran `./x.py doc library/core`, and the result looked good. Manually
copy-pasted the two doctests into the playground and ran them.

wchargin-branch: doc-iter-by-reference
wchargin-source: 0f35369a8a735868621166608797744e97536792
2020-11-23 11:59:42 -08:00
Camelid
d8b1d51b95 Clean up core macros documentation
* Switch a couple links over to intra-doc links
* Clean up some formatting/typography
2020-11-23 11:28:25 -08:00
Camelid
d37e1e186e Qualify panic! as core::panic! in non-built-in core macros
Otherwise code like this

    #![no_implicit_prelude]

    fn main() {
        ::std::todo!();
        ::std::unimplemented!();
    }

will fail to compile, which is unfortunate and presumably unintended.

This changes many invocations of `panic!` in a `macro_rules!` definition
to invocations of `$crate::panic!`, which makes the invocations hygienic.

Note that this does not make the built-in macro `assert!` hygienic.
2020-11-23 11:28:25 -08:00
Jonas Schievink
703f176d57
Rollup merge of #76829 - tspiteri:const-int-pow, r=oli-obk
stabilize const_int_pow

This also requires stabilizing constctlz for const ctlz_nonzero.
2020-11-23 15:25:38 +01:00
bors
068320b39e Auto merge of #77893 - petertodd:2020-impl-default-for-phantompinned, r=dtolnay
Impl Default for PhantomPinned

`PhantomPinned` is just a marker type, with an obvious default value (the only value). So I can't think of a reason not to do this. Sure, it's used in exotic situations with unsafe code. But the people writing that code can decide for themselves if they can derive `Default`, and in many situations the derived impl will make sense:

```rust
#[derive(Default)]
struct NeedsPin {
   marker: PhantomPinned,
   buf: [u8; 1024],
   ptr_to_data: Option<*const u8>,
}
```
2020-11-23 07:00:30 +00:00
Trevor Spiteri
a6bcf7a2b6 const_int_pow will be stabilized in 1.50.0, not in 1.49.0
Same for constctlz.
2020-11-23 02:04:37 +01:00
Trevor Spiteri
aca37b65f1 stabilize const_int_pow
Also stabilize constctlz for const ctlz_nonzero.

The public methods stabilized const by this commit are:

  * `{i*,u*}::checked_pow`
  * `{i*,u*}::saturating_pow`
  * `{i*,u*}::wrapping_pow`
  * `{i*,u*}::overflowing_pow`
  * `{i*,u*}::pow`
  * `u*::next_power_of_two`
  * `u*::checked_next_power_of_two`
  * `u*::wrapping_next_power_of_two` (the method itself is still unstable)
2020-11-23 01:58:27 +01:00
bors
32da90b431 Auto merge of #79319 - m-ou-se:rollup-d9n5viq, r=m-ou-se
Rollup of 10 pull requests

Successful merges:

 - #76941 (Add f{32,64}::is_subnormal)
 - #77697 (Split each iterator adapter and source into individual modules)
 - #78305 (Stabilize alloc::Layout const functions)
 - #78608 (Stabilize refcell_take)
 - #78793 (Clean up `StructuralEq` docs)
 - #79267 (BTreeMap: address namespace conflicts)
 - #79293 (Add test for eval order for a+=b)
 - #79295 (BTreeMap: fix minor testing mistakes in #78903)
 - #79297 (BTreeMap: swap the names of NodeRef::new and Root::new_leaf)
 - #79299 (Stabilise `then`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-22 23:59:48 +00:00
Mara Bos
41c033b2f7
Rollup merge of #79299 - varkor:stabilise-then, r=m-ou-se
Stabilise `then`

Stabilises the lazy variant of https://github.com/rust-lang/rust/issues/64260 now that the FCP [has ended](https://github.com/rust-lang/rust/issues/64260#issuecomment-731636203).

I've kept the original feature gate `bool_to_option` for the strict variant (`then_some`), and created a new insta-stable feature gate `lazy_bool_to_option` for `then`.
2020-11-22 23:01:08 +01:00
Mara Bos
8a623e6f98
Rollup merge of #78793 - camelid:fixup-structuraleq, r=jyn514
Clean up `StructuralEq` docs
2020-11-22 23:01:00 +01:00
Mara Bos
b249844c33
Rollup merge of #78608 - ThinkChaos:stabilize_refcell_take, r=m-ou-se
Stabilize refcell_take

Tracking Issue: #71395

``@KodrAus`` nominated this for FCP, so here's a PR!
I've never made a stabilization PR, so please mention if there's anything I can improve, thanks.
2020-11-22 23:00:58 +01:00
Mara Bos
186ec64947
Rollup merge of #78305 - ChrisDenton:const-layout, r=oli-obk
Stabilize alloc::Layout const functions

Stabilizes #67521. In particular the following stable methods are stabilized as `const fn`:

* `size`
* `align`
* `from_size_align`

Stabilizing `size` and `align` should not be controversial as they are simple (usize and NonZeroUsize) fields and I don't think there's any reason to make them not const compatible in the future. That being true, the other methods are trivially `const`. The only other issue being returning a `Result` from a `const fn` but this has been made more usable by recent stabilizations.
2020-11-22 23:00:56 +01:00
Mara Bos
4407049fcb
Rollup merge of #77697 - WaffleLapkin:iter_split_adaptors, r=m-ou-se
Split each iterator adapter and source into individual modules

This PR creates individual modules for each iterator adapter and iterator source.

This is done to enhance the readability of corresponding modules (`adapters/mod.rs` and `sources.rs`) which were hard to navigate and read because of lots of repeated lines (e.g.: `adapters/mod.rs` was 3k lines long). This is also in line with some adapters which already had their own modules (`Flatten`, `FlatMap`, `Chain`, `Zip`, `Fuse`).

This PR also makes `Take`s adapter fields private (I have no idea why they were `pub(super)` before).

r? ``@LukasKalbertodt``
2020-11-22 23:00:55 +01:00
Mara Bos
9b98f1d226
Rollup merge of #76941 - clarfonthey:is_subnormal, r=m-ou-se
Add f{32,64}::is_subnormal

The docs recommend that you use dedicated methods instead of calling `classify` directly, although there isn't actually a way of checking if a number is subnormal without calling classify. There are dedicated methods for all other forms, excluding `is_zero` (which is just `== 0.0` anyway).
2020-11-22 23:00:48 +01:00
Chris Denton
9050d12714
Stabilize alloc::Layout const functions
Stabilizes #67521. In particular the following stable methods are stabilized as const fn:

* size
* align
* from_size_align
2020-11-22 21:43:30 +00:00
bors
a0d664bae6 Auto merge of #79219 - shepmaster:beta-bump, r=Mark-Simulacrum
Bump bootstrap compiler version

r? `@Mark-Simulacrum`

/cc `@pietroalbini`
2020-11-22 21:38:03 +00:00
ltdk
cf26f2f00e Add f{32,64}::is_subnormal 2020-11-22 15:37:46 -05:00
ThinkChaos
5c6689baff Stabilize refcell_take 2020-11-22 20:13:31 +01:00
varkor
cf32afcf48 Stabilise then 2020-11-22 13:45:14 +00:00
bors
828461b4b2 Auto merge of #78816 - SkiFire13:fix-slice-pointer-provenance, r=RalfJung
<[T]>::reverse: Fix pointer provenance rules

Should fix #78749
2020-11-22 13:10:15 +00:00
bors
5d5ff84130 Auto merge of #77872 - Xaeroxe:stabilize-clamp, r=scottmcm
Stabilize clamp

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

Clamp has been merged and unstable for about a year and a half now. How do we feel about stabilizing this?
2020-11-22 10:50:04 +00:00
bors
20328b5323 Auto merge of #79275 - integer32llc:doc-style, r=jonas-schievink
More consistently use spaces after commas in lists in docs

This PR changes instances of lists that didn't use spaces after commas, like `vec![1,2,3]`, to `vec![1, 2, 3]` to be more consistent with idiomatic Rust style (the way these were looks strange to me, especially because there are often lists that *do* use spaces after the commas later in the same code block 😬).

I noticed one of these in an example in the stdlib docs and went looking for more, but as far as I can see, I'm only changing those spots in user-facing documentation or rustc output, and the changes make no semantic difference.
2020-11-22 08:30:23 +00:00
bors
8ca930aa26 Auto merge of #79229 - sdroege:slice-fill-memset, r=dtolnay
Add "memset" as doc alias to slice::fill()

Similar to 53f969dfd1 and should make it easier for people coming from C to find this function.
2020-11-22 04:27:03 +00:00
Waffle
461265825b Remove multiline uses 2020-11-22 02:39:22 +03:00
Waffle
0dc187c787 Fix doc links in core::iter::sources 2020-11-22 02:39:21 +03:00
Waffle
b82a76ae3a Merge uses in core::iter 2020-11-22 02:39:21 +03:00
Waffle
66d6708c3d Split iterator sources into different modules 2020-11-22 02:39:21 +03:00
Waffle
773b73c66c Split iterator adaptors into individual modules
This commit also makes fields of `Take` private. I have no idea why they
were `pub(super)` before.
2020-11-22 02:39:16 +03:00
Carol (Nichols || Goulding)
ae17d7d455
More consistently use spaces after commas in lists in docs 2020-11-21 14:43:34 -05:00
Dylan DPC
6cd02a85f1
Rollup merge of #77844 - RalfJung:zst-box, r=nikomatsakis
clarify rules for ZST Boxes

LLVM's rules around `getelementptr inbounds` with offset 0 are a bit annoying, and as a consequence we have no choice but say that a `Box<()>` pointing to previously allocated memory that has since been freed is UB. Clarify the docs to reflect this.

This is based on conversations on the LLVM mailing list.
* Here's my initial mail: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130452.html
* The first email of the March part of that thread: https://lists.llvm.org/pipermail/llvm-dev/2019-March/130831.html
* First email of the April part: https://lists.llvm.org/pipermail/llvm-dev/2019-April/131693.html

The conclusion for me at least was that `getelementptr inbounds` with offset 0 is *not* the identity function, but can sometimes return `poison` even when the input is a regular pointer -- specifically, it returns `poison` when this pointer points into something that LLVM "knows has been deallocated", i.e., a former LLVM-managed allocation. It is however the identity function on pointers obtained by casting integers.

Note that there [are formal proposals](https://people.mpi-sws.org/~jung/twinsem/twinsem.pdf) for LLVM semantics where `getelementptr inbounds` with offset 0 isn't quite the identity function but never returns `poison` (it affects the provenance of the pointer but in a way that doesn't matter if this pointer is never used for memory accesses), and indeed this is likely necessary to consistently describe LLVM semantics. But with the informal LLVM LangRef that we have right now, and with LLVM devs insisting otherwise, it seems unwise to rely on this.
2020-11-21 19:44:07 +01:00
bors
29a74e6285 Auto merge of #79222 - yoshuawuyts:slice-fill-with, r=m-ou-se
Add `core::slice::fill_with`

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

As suggested by `@m-ou-se` in https://github.com/rust-lang/rust/issues/70758#issuecomment-726838099 this implements `slice::fill_with` as a counterpart to `slice::fill`. This mirrors `Vec::resize` and `Vec::resize_with`. Thanks!

r? `@m-ou-se`
2020-11-21 08:15:16 +00:00
Jacob Kiesel
fb6ceac46b We missed 1.49.0, so bump version to 1.50.0 2020-11-20 10:37:22 -07:00
Sebastian Dröge
7a3b331587 Add "memset" as doc alias to slice::fill() 2020-11-20 15:19:47 +02:00
Yoshua Wuyts
a64d0d4774 Add core::slice::fill_with 2020-11-20 14:12:54 +01:00
Ralf Jung
a7677f7714 reference NonNull::dangling 2020-11-20 11:09:49 +01:00
bors
74285eb3a8 Auto merge of #78088 - fusion-engineering-forks:panic-fmt-lint, r=estebank
Add lint for panic!("{}")

This adds a lint that warns about `panic!("{}")`.

`panic!(msg)` invocations with a single argument use their argument as panic payload literally, without using it as a format string. The same holds for `assert!(expr, msg)`.

This lints checks if `msg` is a string literal (after expansion), and warns in case it contained braces. It suggests to insert `"{}", ` to use the message literally, or to add arguments to use it as a format string.

![image](https://user-images.githubusercontent.com/783247/96643867-79eb1080-1328-11eb-8d4e-a5586837c70a.png)

This lint is also a good starting point for adding warnings about `panic!(not_a_string)` later, once [`panic_any()`](https://github.com/rust-lang/rust/pull/74622) becomes a stable alternative.
2020-11-20 03:40:20 +00:00