Commit graph

930 commits

Author SHA1 Message Date
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
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
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
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
Pratyush Mishra
56d9784b5a
Fix typo in wrapping_shl documentation 2020-12-09 15:14:58 -08: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
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