Commit graph

5552 commits

Author SHA1 Message Date
bors
ef4b3069ba Auto merge of #89774 - the8472:inline-mut-iter-next, r=m-ou-se
inline next() on &mut Iterator impl

In [#87431](https://github.com/rust-lang/rust/pull/87431/files#diff-79a6b417b85ecf4f1a4ef2235135fedf540199caf6e9e1d154ac6a413b40a757R132-R136)   I found that `(&mut range).fold` doesn't optimize well because the default impl for for `fold` on `&mut Iterator` doesn't inline `next`. In that particular case it was worked around by using `try_fold` which takes a `&mut self` instead of `self`.

Let's see if this can be fixed more broadly.
2021-10-12 23:59:48 +00:00
the8472
7017410e5d
Rollup merge of #89799 - ast-ral:ready-method-spellck, r=joshtriplett
fix minor spelling error in Poll::ready docs

Fixes minor spelling error in the proposed `Poll::ready` docs. Not that my opinion matters, but +1 on the original PR (#89651), it reads much nicer to me than the `ready!` macro.
2021-10-12 14:53:11 +02:00
the8472
4cf0f1fede
Rollup merge of #89797 - jkugelman:must-use-is_condition-tests, r=joshtriplett
Add #[must_use] to is_condition tests

I threw in `std::path::Path::has_root` for funsies.

A continuation of #89718.

Parent issue: #89692

r? ```@joshtriplett```
2021-10-12 14:53:11 +02:00
the8472
a1bdd48106
Rollup merge of #89796 - jkugelman:must-use-non-mutating-verb-methods, r=joshtriplett
Add #[must_use] to non-mutating verb methods

These are methods that could be misconstrued to mutate their input, similar to #89694. I gave each one a different custom message.

I wrote that `upgrade` and `downgrade` don't modify the input pointers. Logically they don't, but technically they do...

Parent issue: #89692

r? ```@joshtriplett```
2021-10-12 14:53:10 +02:00
the8472
b55a3c5d15
Rollup merge of #89778 - jkugelman:must-use-as_type-conversions, r=joshtriplett
Add #[must_use] to as_type conversions

Clippy missed these:

```rust
alloc::string::String   fn as_mut_str(&mut self) -> &mut str;
core::mem::NonNull<T>   unsafe fn as_uninit_mut<'a>(&mut self) -> &'a MaybeUninit<T>;
str                     unsafe fn as_bytes_mut(&mut self) -> &mut [u8];
str                     fn as_mut_ptr(&mut self) -> *mut u8;
```

Parent issue: #89692

r? ````@joshtriplett````
2021-10-12 14:53:08 +02:00
bors
9475e609b8 Auto merge of #89770 - jkugelman:must-use-from-and-into, r=joshtriplett
Add #[must_use] to From::from and Into::into

Risk of churn: **High**
Magic 8-Ball says: **Outlook not so good**

I figured I'd put this out there. If we don't do it now maybe we save it for a rainy day.

Parent issue: #89692

r? `@joshtriplett`
2021-10-12 09:43:37 +00:00
bors
02f2b31e61 Auto merge of #89769 - jkugelman:must-use-maybe-uninit-new, r=joshtriplett
Add #[must_use] to MaybeUninit::new

As discussed in https://github.com/rust-lang/rust/pull/89729#issuecomment-939775659.

Parent issue: #89692

r? `@joshtriplett`
2021-10-12 07:02:53 +00:00
ast-ral
5100630dcd
fix minor spelling error in Poll::ready docs 2021-10-11 21:00:02 -07:00
bors
ffdf18d144 Auto merge of #88788 - falk-hueffner:speedup-int-log10-branchless, r=joshtriplett
Speedup int log10 branchless

This is achieved with a branchless bit-twiddling implementation of the case x < 100_000, and using this as building block.

Benchmark on an Intel i7-8700K (Coffee Lake):

```
name                                   old ns/iter  new ns/iter  diff ns/iter   diff %  speedup
num::int_log::u8_log10_predictable     165          169                     4    2.42%   x 0.98
num::int_log::u8_log10_random          438          423                   -15   -3.42%   x 1.04
num::int_log::u8_log10_random_small    438          423                   -15   -3.42%   x 1.04
num::int_log::u16_log10_predictable    633          417                  -216  -34.12%   x 1.52
num::int_log::u16_log10_random         908          471                  -437  -48.13%   x 1.93
num::int_log::u16_log10_random_small   945          471                  -474  -50.16%   x 2.01
num::int_log::u32_log10_predictable    1,496        1,340                -156  -10.43%   x 1.12
num::int_log::u32_log10_random         1,076        873                  -203  -18.87%   x 1.23
num::int_log::u32_log10_random_small   1,145        874                  -271  -23.67%   x 1.31
num::int_log::u64_log10_predictable    4,005        3,171                -834  -20.82%   x 1.26
num::int_log::u64_log10_random         1,247        1,021                -226  -18.12%   x 1.22
num::int_log::u64_log10_random_small   1,265        921                  -344  -27.19%   x 1.37
num::int_log::u128_log10_predictable   39,667       39,579                -88   -0.22%   x 1.00
num::int_log::u128_log10_random        6,456        6,696                 240    3.72%   x 0.96
num::int_log::u128_log10_random_small  4,108        3,903                -205   -4.99%   x 1.05
```

Benchmark on an M1 Mac Mini:

```
name                                   old ns/iter  new ns/iter  diff ns/iter   diff %  speedup
num::int_log::u8_log10_predictable     143          130                   -13   -9.09%   x 1.10
num::int_log::u8_log10_random          375          325                   -50  -13.33%   x 1.15
num::int_log::u8_log10_random_small    376          325                   -51  -13.56%   x 1.16
num::int_log::u16_log10_predictable    500          322                  -178  -35.60%   x 1.55
num::int_log::u16_log10_random         794          405                  -389  -48.99%   x 1.96
num::int_log::u16_log10_random_small   1,035        405                  -630  -60.87%   x 2.56
num::int_log::u32_log10_predictable    1,144        894                  -250  -21.85%   x 1.28
num::int_log::u32_log10_random         832          786                   -46   -5.53%   x 1.06
num::int_log::u32_log10_random_small   832          787                   -45   -5.41%   x 1.06
num::int_log::u64_log10_predictable    2,681        2,057                -624  -23.27%   x 1.30
num::int_log::u64_log10_random         1,015        806                  -209  -20.59%   x 1.26
num::int_log::u64_log10_random_small   1,004        795                  -209  -20.82%   x 1.26
num::int_log::u128_log10_predictable   56,825       56,526               -299   -0.53%   x 1.01
num::int_log::u128_log10_random        9,056        8,861                -195   -2.15%   x 1.02
num::int_log::u128_log10_random_small  1,528        1,527                  -1   -0.07%   x 1.00
```

The 128 bit case remains ridiculously slow because llvm fails to optimize division by a constant 128-bit value to multiplications. This could be worked around but it seems preferable to fix this in llvm.

From u32 up, table lookup (like suggested [here](https://github.com/rust-lang/rust/issues/70887#issuecomment-881099813)) is still faster, but requires a hardware `leading_zeros` to be viable, and might clog up the cache.
2021-10-12 03:18:54 +00:00
John Kugelman
c3f0577002 Add #[must_use] to non-mutating verb methods 2021-10-11 21:21:32 -04:00
John Kugelman
01b439e764 Add #[must_use] to is_condition tests
A continuation of #89718.
2021-10-11 21:15:57 -04:00
John Kugelman
f9692b5619 Add #[must_use] to From::from and Into::into 2021-10-11 18:10:30 -04:00
Matthias Krüger
f94a325496
Rollup merge of #89785 - nbdd0121:master, r=Mark-Simulacrum
Fix ICE when compiling nightly std/rustc on beta compiler

Fix #89775

#89479 renames a lot of diagnostic items, but it happens that the beta compiler assumes that there must be DefId with `rustc_diagnostic_item = "send_trait"`, causing an ICE when compiling stage 0 std or stage 1 compiler. So gate it with `cfg(bootstrap)`.

The unwrap is also removed, so that existence of the diagnostic item is not required. I ripgreped the code base and this seems the only place where `unwrap` is called on the return value of `get_diagnostic_item`.
2021-10-11 23:45:53 +02:00
Matthias Krüger
d3984e16bf
Rollup merge of #89651 - ibraheemdev:poll-ready, r=dtolnay
Add `Poll::ready` and revert stabilization of `task::ready!`

This PR adds an inherent `ready` method to `Poll` that can be used with the `?` operator as an alternative to the `task::ready!` macro:
```rust
let val = ready!(fut.poll(cx));
let val = fut.poll(cx).ready()?;
```

I think this form is a nice, non-breaking middle ground between changing the `impl Try for Poll`, and adding a separate macro. It looks better than `ready!` in my opinion, and it composes well:

```rust
let elem = ready!(fut.poll(cx)).pop().unwrap();
let elem = fut.poll(cx).ready()?.pop().unwrap();
```

The planned stabilization of `ready!` in 1.56 has been reverted because I think this alternate approach is worth considering.

r? rust-lang/libs
2021-10-11 23:45:48 +02:00
The8472
f1c588f1ef use fold instead of try_fold now that .by_ref().next() has been inlined 2021-10-11 23:36:04 +02:00
Gary Guo
148f456cc6 Fix ICE 89775 2021-10-11 20:52:36 +01:00
David Tolnay
a1e03fc563
Add library tracking issue for poll_ready feature 2021-10-11 12:17:41 -07:00
John Kugelman
b0b09f0842
Update library/core/src/mem/maybe_uninit.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-10-11 14:46:08 -04:00
John Kugelman
06e625f7d5 Add #[must_use] to as_type conversions 2021-10-11 13:57:38 -04:00
bors
5b210643eb Auto merge of #83908 - Flying-Toast:master, r=davidtwco
Add enum_intrinsics_non_enums lint

There is a clippy lint to prevent calling [`mem::discriminant`](https://doc.rust-lang.org/std/mem/fn.discriminant.html) with a non-enum type. I think the lint is worthy of being included in rustc, given that `discriminant::<T>()` where `T` is a non-enum has an unspecified return value, and there are no valid use cases where you'd actually want this.

I've also made the lint check [variant_count](https://doc.rust-lang.org/core/mem/fn.variant_count.html) (#73662).

closes #83899
2021-10-11 17:12:14 +00:00
The8472
a398b6b9d4 inline next() on &mut Iterator impl 2021-10-11 17:50:03 +02:00
bors
1067e2ca5e Auto merge of #89767 - GuillaumeGomez:rollup-sczixhk, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #89655 (bootstrap: don't use `--merges` to look for commit hashes for downloading artifacts)
 - #89726 (Add #[must_use] to alloc constructors)
 - #89729 (Add #[must_use] to core and std constructors)
 - #89743 (Fix RUSTC_LOG handling)
 - #89753 (Add #[must_use] to from_value conversions)
 - #89754 (Cleanup .item-table CSS)
 - #89761 (⬆️ rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-11 14:16:15 +00:00
John Kugelman
3ac0ae21d5 Add #[must_use] to MaybeUninit::new 2021-10-11 10:03:55 -04:00
Guillaume Gomez
96ffc74fe3
Rollup merge of #89753 - jkugelman:must-use-from_value-conversions, r=joshtriplett
Add #[must_use] to from_value conversions

I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument.

```rust
core::str           const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;
std::ffi::CString   unsafe fn from_raw(ptr: *mut c_char) -> CString;
```

I put a custom note on `from_raw`:

```rust
#[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"]
pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
```

Parent issue: #89692

r? ``@joshtriplett``
2021-10-11 14:11:45 +02:00
Guillaume Gomez
77be7e441a
Rollup merge of #89729 - jkugelman:must-use-core-std-constructors, r=joshtriplett
Add #[must_use] to core and std constructors

Parent issue: #89692

r? ``@joshtriplett``
2021-10-11 14:11:43 +02:00
Guillaume Gomez
d7c9693401
Rollup merge of #89726 - jkugelman:must-use-alloc-constructors, r=joshtriplett
Add #[must_use] to alloc constructors

Added `#[must_use]`. to the various forms of `new`, `pin`, and `with_capacity` in the `alloc` crate. No extra explanations given as I couldn't think of anything useful to add.

I figure this deserves extra scrutiny compared to the other PRs I've done so far. In particular:

* The 4 `pin`/`pin_in` methods I touched. Are there legitimate use cases for pinning and not using the result? Pinning's a difficult concept I'm not very comfortable with.
* `Box`'s constructors. Do people ever create boxes just for the side effects... allocating or zeroing out memory?

Parent issue: #89692

r? ``@joshtriplett``
2021-10-11 14:11:42 +02:00
bors
6ae8912a3e Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov
Apply clippy suggestions for rustc and core
2021-10-11 11:14:47 +00:00
Flying-Toast
59b186d99a
Add enum_intrinsics_non_enums lint 2021-10-11 09:46:27 +02:00
bors
86d6d2b738 Auto merge of #89755 - jkugelman:must-use-conversions-that-move-self, r=joshtriplett
Add #[must_use] to conversions that move self

Everything here got the same message. Is the wording okay?

```rust
#[must_use = "`self` will be dropped if the result is not used"]
```

I want to draw attention to these methods in particular:

```rust
alloc::sync::Arc<MaybeUninit<T>>     unsafe fn assume_init(self) -> Arc<T>;
alloc::sync::Arc<[MaybeUninit<T>]>   unsafe fn assume_init(self) -> Arc<[T]>;
core::pin::Pin<&'a mut T>            const fn into_ref(self) -> Pin<&'a T>;
core::pin::Pin<&'a mut T>            const fn get_mut(self) -> &'a mut T;
core::pin::Pin<&'a mut T>            const unsafe fn get_unchecked_mut(self) -> &'a mut T;
core::pin::Pin<&'a mut T>            unsafe fn map_unchecked_mut(self, func: F) -> Pin<&'a mut U>;
core::pin::Pin<&'a mut Pin<P>>       fn as_deref_mut(self) -> Pin<&'a mut P::Target>;
```

Parent issue: #89692

r? `@joshtriplett`
2021-10-11 07:27:44 +00:00
John Kugelman
b115781bcd Add #[must_use] to conversions that move self 2021-10-10 19:50:52 -04:00
John Kugelman
cf2bcd10ed Add #[must_use] to from_value conversions 2021-10-10 19:00:33 -04:00
Matthias Krüger
9c4791300a
Rollup merge of #89707 - clemenswasser:apply_clippy_suggestions, r=Mark-Simulacrum
Apply clippy suggestions for std
2021-10-11 00:34:39 +02:00
Matthias Krüger
4d89488c41
Rollup merge of #89735 - bjorn3:stabilize_proc_macro_is_available, r=petrochenkov
Stabilize proc_macro::is_available

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

The FCP for the stabilization of `proc_macro::is_available` has completed.
2021-10-10 18:22:26 +02:00
Matthias Krüger
c8b5a7b0c4
Rollup merge of #89720 - jkugelman:must-use-math-operations, r=joshtriplett
Add #[must_use] to math and bit manipulation methods

Also tidied up a few other nearby `#[must_use]`s.

Parent issue: #89692
2021-10-10 18:22:25 +02:00
Matthias Krüger
758a901a40
Rollup merge of #89719 - jkugelman:must-use-char-escape-methods, r=joshtriplett
Add #[must_use] to char escape methods

Parent issue: #89692
2021-10-10 18:22:24 +02:00
Matthias Krüger
0c04b1fc03
Rollup merge of #89718 - jkugelman:must-use-is_condition-tests, r=joshtriplett
Add #[must_use] to is_condition tests

There's nothing insightful to say about these so I didn't write any extra explanations.

Parent issue: #89692
2021-10-10 18:22:23 +02:00
Matthias Krüger
ce6097dfa4
Rollup merge of #89705 - nbdd0121:doc, r=GuillaumeGomez
Cfg hide no_global_oom_handling and no_fp_fmt_parse

These are unstable sysroot customisation cfg options that only projects building their own sysroot will use (e.g. Rust-for-linux). Most users shouldn't care. `no_global_oom_handling` can be especially annoying since it's applied on many commonly used alloc crate methods (e.g. `Box::new`, `Vec::push`).

r? ```@GuillaumeGomez```
2021-10-10 18:22:21 +02:00
Matthias Krüger
06cfd0af48
Rollup merge of #89438 - pierwill:prefix-free-hash, r=Amanieu
docs: `std:#️⃣:Hash` should ensure prefix-free data

Attempt to synthesize the discussion in #89429 into a suggestion regarding `Hash` implementations (not a hard requirement).

Closes #89429.
2021-10-10 18:22:20 +02:00
Matthias Krüger
4473b945bf
Rollup merge of #88713 - falk-hueffner:int-log10-documentation-fixes, r=scottmcm
Improve docs for int_log

* Clarify rounding.
* Avoid "wrapping" wording.
* Omit wrong claim on 0 only being returned in error cases.
* Typo fix for one_less_than_next_power_of_two.
2021-10-10 18:22:18 +02:00
Matthias Krüger
fd5bed73d0
Rollup merge of #88374 - joshlf:patch-2, r=JohnTitor
Fix documentation in Cell
2021-10-10 18:22:17 +02:00
John Kugelman
ecd7ea8a9c
Merge branch 'rust-lang:master' into must-use-alloc-constructors 2021-10-10 10:15:16 -04:00
Clemens Wasser
71dd0b928b Apply clippy suggestions 2021-10-10 15:38:19 +02:00
bors
0c87288f92 Auto merge of #89219 - nickkuk:str_split_once_get_unchecked, r=Mark-Simulacrum
Use get_unchecked in str::[r]split_once

This PR removes indices checking in `str::split_once` and `str::rsplit_once` methods.
2021-10-10 12:29:48 +00:00
bjorn3
09dd213cd2 Stabilize proc_macro::is_available 2021-10-10 14:09:54 +02:00
bors
9e8356c6ad Auto merge of #88952 - skrap:add-armv7-uclibc, r=nagisa
Add new tier-3 target: armv7-unknown-linux-uclibceabihf

This change adds a new tier-3 target: armv7-unknown-linux-uclibceabihf

This target is primarily used in embedded linux devices where system resources are slim and glibc is deemed too heavyweight.  Cross compilation C toolchains are available [here](https://toolchains.bootlin.com/) or via [buildroot](https://buildroot.org).

The change is based largely on a previous PR #79380 with a few minor modifications.  The author of that PR was unable to push the PR forward, and graciously allowed me to take it over.

Per the [target tier 3 policy](https://github.com/rust-lang/rfcs/blob/master/text/2803-target-tier-policy.md), I volunteer to be the "target maintainer".

This is my first PR to Rust itself, so I apologize if I've missed things!
2021-10-10 08:16:22 +00:00
John Kugelman
5b5c12be1c Add #[must_use] to core and std constructors 2021-10-10 02:44:26 -04:00
John Kugelman
58cc18c56b Add #[must_use] to alloc constructors 2021-10-10 02:19:30 -04:00
John Kugelman
bc9d13e658 Add #[must_use] to math and bit manipulation methods
Also tidied up a few other nearby `#[must_use]`s.
2021-10-09 22:43:32 -04:00
John Kugelman
fec9514727 Add #[must_use] to char escape methods 2021-10-09 21:35:09 -04:00
John Kugelman
475e9925a7 Add #[must_use] to is_condition tests
There's nothing insightful to say about these so I didn't write any
extra explanations.
2021-10-09 21:27:13 -04:00