Commit Graph

9439 Commits

Author SHA1 Message Date
Yuki Okushi
5c731cd796
Rollup merge of #102433 - RalfJung:temp-dir-typo, r=thomcc
env::temp_dir: fix a typo
2022-09-29 11:42:06 +09:00
Yuki Okushi
8e4869e862
Rollup merge of #102368 - beetrees:nano-niche, r=joshtriplett
Add a niche to `Duration`, unix `SystemTime`, and non-apple `Instant`

As the nanoseconds fields is always between `0` and `(NANOS_PER_SEC - 1)` inclusive, use the `rustc_layout_scalar_valid_range` attributes to create a niche in the nanosecond field of `Duration` and `Timespec` (which is used to implement unix `SystemTime` and non-apple unix `Instant`; windows `Instant` is implemented with `Duration` and therefore will also benefit). This change has the benefit of making `Option<T>` the same size as `T` for the previously mentioned types. Also shrinks the nanoseconds field of `Timespec` to a `u32` as nanoseconds do not need the extra range of an `i64`, shrinking `Timespec` by 4 bytes on 32-bit platforms.

r? ```@joshtriplett```
2022-09-29 11:42:05 +09:00
Yuki Okushi
7cd4780c91
Rollup merge of #98368 - sunfishcode:sunfishcode/std-os-fd, r=joshtriplett
Make `std::os::fd` public.

`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common
between Unix and non-Unix platforms that share a basic file-descriptor
concept. Rust currently uses this internally to simplify its own code,
but it would be useful for external users in the same way, so make it
public.

This means that `OwnedFd` etc. will all appear in three places, for
example on unix platforms:
 - `std::os::fd::OwnedFd`
 - `std::os::unix::io::OwnedFd`
 - `std::os::unix::prelude::OwnedFd`

r? `````@joshtriplett`````
2022-09-29 11:42:03 +09:00
John Millikin
9d5e3a1f45 Add is_empty() method to core::ffi::CStr. 2022-09-29 07:55:12 +09:00
Guillaume Gomez
49b25d3412 Improve example of Iterator::reduce 2022-09-29 00:44:53 +02:00
John Millikin
ceb53a3c4f nonzero_negation_ops: inline(always) -> inline. 2022-09-29 07:33:26 +09:00
John Millikin
cdae82c5fc nonzero_negation_ops: Set issue = "102443". 2022-09-29 07:32:15 +09:00
Ralf Jung
5baceaf796 env::temp_dir: fix a typo 2022-09-28 21:51:09 +02:00
bors
ce7f0f1aa0 Auto merge of #100719 - CohenArthur:rust-safe-intrinsic-attribute, r=wesleywiser
Add `#[rustc_safe_intrinsic]`

This PR adds the `#[rustc_safe_intrinsic]` attribute as mentionned on Zulip. The goal of this attribute is to avoid keeping a list of symbols as the source for stable intrinsics, and instead rely on an attribute. This is similar to `#[rustc_const_stable]` and `#[rustc_const_unstable]`, which among other things, are used to mark the constness of intrinsic functions.
2022-09-28 19:07:50 +00:00
beetrees
a913277829
Add a niche to Duration, unix SystemTime, and non-apple Instant 2022-09-28 18:15:10 +01:00
joboet
b0b9f5bc26
std: never panic in thread::park and thread::park_timeout 2022-09-28 16:54:00 +02:00
Marijn Schouten
ac310e6643
Update result.rs
Remove a FIXME whose code got moved away in https://github.com/rust-lang/rust/pull/62883.
2022-09-28 14:52:59 +02:00
Yuki Okushi
9436ffc226
Rollup merge of #102288 - mejrs:inner, r=compiler-errors
Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.

This suggests various ways to get inside wrapper types if the method cannot be found on the wrapper type, but is present on the wrappee.

For this PR, those wrapper types include `Localkey`, `MaybeUninit`, `RefCell`, `RwLock` and `Mutex`.
2022-09-28 13:07:17 +09:00
Yuki Okushi
07bb2e6527
Rollup merge of #102232 - Urgau:stabilize-bench_black_box, r=TaKO8Ki
Stabilize bench_black_box

This PR stabilize `feature(bench_black_box)`.

```rust
pub fn black_box<T>(dummy: T) -> T;
```

The FCP was completed in https://github.com/rust-lang/rust/issues/64102.

`@rustbot` label +T-libs-api -T-libs
2022-09-28 13:07:17 +09:00
woppopo
7b993885d0 Sort mod 2022-09-27 19:53:58 +00:00
Matthias Krüger
ad57d5f27c
Rollup merge of #101555 - jhpratt:stabilize-mixed_integer_ops, r=joshtriplett
Stabilize `#![feature(mixed_integer_ops)]`

Tracked and FCP completed in #87840.

````@rustbot```` label +T-libs-api +S-waiting-on-review +relnotes

r? rust-lang/t-libs-api
2022-09-27 21:42:21 +02:00
mejrs
f3ac328d58 Address feedback 2022-09-27 21:42:09 +02:00
mejrs
c4c9415132 Wrapper suggestions 2022-09-27 21:42:09 +02:00
woppopo
ca55a88161 Fix indent 2022-09-27 19:40:53 +00:00
woppopo
767a7771c7 Add newlines 2022-09-27 19:23:52 +00:00
woppopo
834cab7244 Add test cases for const Location 2022-09-27 19:09:32 +00:00
Urgau
9ad2f00f6a Stabilize bench_black_box 2022-09-27 17:38:51 +02:00
Arthur Cohen
99d57ee23d core: Mark all safe intrinsics with #[rustc_safe_intrinsic] 2022-09-27 15:55:42 +02:00
Akshay
591c1f25b2 introduce {char, u8}::is_ascii_octdigit 2022-09-27 11:55:13 +05:30
John Millikin
259bbfbc3d Add negation methods for signed non-zero integers. 2022-09-27 13:15:55 +09:00
bors
f3a6fbf2f2 Auto merge of #102283 - GuillaumeGomez:option-code-example-unwrap-or-default, r=thomcc
Improve code example for Option::unwrap_or_default

Fixes #100054.
Follow-up of #102259.

r? `@thomcc`
2022-09-26 23:17:52 +00:00
Michael Howell
7381d7d8b2
Rollup merge of #102326 - yancyribbens:splin-mut-doc-change, r=thomcc
rustdoc: Update doc comment for splitn_mut to include mutable in the …

The doc comment for [splitn](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L2051:L2056) is the exact same as the comment for [splitn_mut](https://github.com/rust-lang/rust/blob/master/library/core/src/slice/mod.rs#L2079:L2084).  The doc comment for `splitn_mut` should instead say it's working on a mutable subslice.
2022-09-26 15:40:55 -07:00
Michael Howell
66bab6b781
Rollup merge of #102322 - sigaloid:master, r=GuillaumeGomez
Document that Display automatically implements ToString

Closes #92941

r? rust-lang/docs
2022-09-26 15:40:54 -07:00
Michael Howell
2668a6839a
Rollup merge of #102283 - GuillaumeGomez:option-code-example-unwrap-or-default, r=thomcc
Improve code example for Option::unwrap_or_default

Fixes #100054.
Follow-up of #102259.

r? ``@thomcc``
2022-09-26 15:40:52 -07:00
Scott McMurray
55492de545 Use a macro to not have to copy-paste ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0 everywhere
Also use that macro to replace a bunch of places that had custom closure-wrappers.
2022-09-26 11:38:18 -07:00
yancy
40f404468a rustdoc: Update doc comment for splitn_mut to include mutable in the description 2022-09-26 20:20:13 +02:00
Matthew Esposito
4fad063cba Document that Display entails ToString 2022-09-26 13:03:59 -04:00
Anirudh
4c42e3831f Update docs so that deprecated method points to relevant method 2022-09-26 19:28:51 +05:30
Guillaume Gomez
475aeab79e Improve code example for Option::unwrap_or_default 2022-09-26 12:37:41 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Pietro Albini
d0305b3d00
replace stabilization placeholders 2022-09-26 10:13:44 +02:00
David Carlier
2ea770d067 fs::get_path solarish version. 2022-09-26 06:41:27 +01:00
bors
72f4923979 Auto merge of #102297 - fee1-dead-contrib:rollup-2np0cre, r=fee1-dead
Rollup of 5 pull requests

Successful merges:

 - #102143 (Recover from struct nested in struct)
 - #102178 (bootstrap: the backtrace feature is stable, no need to allow it any more)
 - #102197 (Stabilize const `BTree{Map,Set}::new`)
 - #102267 (Don't set RUSTC in the bootstrap build script)
 - #102270 (Remove benches from `rustc_middle`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-26 05:27:43 +00:00
fee1-dead
804c2c1ed9
Rollup merge of #102197 - Nilstrieb:const-new-🌲, r=Mark-Simulacrum
Stabilize const `BTree{Map,Set}::new`

The FCP was completed in #71835.

Since `len` and `is_empty` are not const stable yet, this also creates a new feature for them since they previously used the same `const_btree_new` feature.
2022-09-26 13:09:42 +08:00
fee1-dead
beb224084d
Rollup merge of #102263 - GuillaumeGomez:iterator-rposition-example, r=thomcc
Clarify Iterator::rposition code example

Fixes #101095.

r? `@thomcc`
2022-09-26 09:27:37 +08:00
Martin Geisler
f67184fdcb Consistently write RwLock
Before the documentation sometimes referred to an "rwlock" and sometimes to "`RwLock`".
2022-09-25 21:09:38 +02:00
fee1-dead
c50303ca1f
Rollup merge of #102259 - gimbles:patch-1, r=joshtriplett
Type-annotate and simplify documentation of Option::unwrap_or_default

Part of #100054
2022-09-25 22:06:41 +08:00
fee1-dead
b00b918f28
Rollup merge of #102245 - ink-feather-org:const_cmp_by, r=fee1-dead
Constify cmp_min_max_by.

Constifies `core::cmp::{min, max}_by[_key]` behind the `const_cmp` #92391 feature gate, using `const_closure`.
2022-09-25 22:06:40 +08:00
fee1-dead
69aa41b000
Rollup merge of #102200 - ink-feather-org:const_default_impls, r=fee1-dead
Constify Default impl's for Arrays and Tuples.

Allows to create arrays and tuples in const Context using the ~const Default implementation of the inner type.
2022-09-25 22:06:40 +08:00
fee1-dead
da884d25da
Rollup merge of #101800 - chriss0612:feat/const_split_at_mut, r=fee1-dead
Constify slice.split_at_mut(_unchecked)

Tracking Issue: [Tracking Issue for const_slice_split_at_mut](https://github.com/rust-lang/rust/issues/101804)

Feature gate: `#![feature(const_slice_split_at_mut)]`

Still requires const_mut_refs to be actually used, but this feature removes the need to manually re implement these functions in a user crate.
2022-09-25 22:06:38 +08:00
fee1-dead
033f93fbb9
Rollup merge of #98111 - eggyal:issue-97982, r=GuillaumeGomez
Clarify `[T]::select_nth_unstable*` return values

In cases where the nth element is not unique within the slice, it is not
correct to say that the values in the returned triplet include ones for
"all elements" less/greater than that at the given index: indeed one (or
more) such values would then also contain elements equal to that at
the given index.

The text proposed here clarifies exactly what is returned, but in so
doing it is also documenting an implementation detail that previously
wasn't detailed: namely that the returned slices are slices into the
reordered slice.  I don't think this can be contentious, because the
lifetimes of those returned slices are bound to that of the original
(now reordered) slice—so there really isn't any other reasonable
implementation that could have this behaviour; but nevertheless it's
probably best if `@rust-lang/libs-api` give it a nod?

Fixes #97982
r? `@m-ou-se`

`@rustbot` label +A-docs +C-bug +T-libs-api -T-libs
2022-09-25 22:06:36 +08:00
Guillaume Gomez
a20672c919 Clarify Iterator::rposition code example 2022-09-25 14:09:41 +02:00
Gimgim
4411d5fcc7
Update option.rs 2022-09-25 15:48:08 +05:30
Camille GILLOT
75d3a9ebd1 Remove unused variable. 2022-09-25 11:36:14 +02:00
bors
8e9c93df46 Auto merge of #99609 - workingjubilee:lossy-unix-strerror, r=thomcc
Recover error strings on Unix from_lossy_utf8

Some language settings can result in unreliable UTF-8 being produced.
This can result in failing to emit the error string, panicking instead.
from_lossy_utf8 allows us to assume these strings usually will be fine.

This fixes rust-lang#99535.
2022-09-25 06:53:14 +00:00
bors
e20fabb0d0 Auto merge of #98457 - japaric:gh98378, r=m-ou-se
make Condvar, Mutex, RwLock const constructors work with the `unsupported` impl

applying this patch locally to the `rust-src` component fixes #98378

however, the solution seems wrong to me because PR #97791 didn't add any `rustc_const_stable` attribute to underlying implementations like `std::sys::unix::futex`, so I must be missing something about how const-stability is checked ... maybe the `restricted_std` feature (gate?) has an effect?

fixes #98378
fixes #98293 (probably)
2022-09-25 04:12:30 +00:00
bors
e58621a4a3 Auto merge of #102169 - scottmcm:constify-some-conditions, r=thomcc
Make ZST checks in core/alloc more readable

There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff.

This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse.

*Not* proposed for stabilization.  Would be `pub(crate)` except `alloc` wants to use it too.

(And while it doesn't matter now, if we ever get something like #85836 making it a const can help codegen be simpler.)
2022-09-25 01:20:11 +00:00
onestacked
2e7a201d2e Constify cmp_min_max_by 2022-09-24 22:12:00 +02:00
Scott McMurray
ed16dbf65e Add some more documentation 2022-09-24 12:12:41 -07:00
bors
6580010551 Auto merge of #102234 - matthiaskrgr:rollup-5cb20l1, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #100823 (Refactor some `std` code that works with pointer offstes)
 - #102088 (Fix wrongly refactored Lift impl)
 - #102109 (resolve: Set effective visibilities for imports more precisely)
 - #102186 (Add const_closure, Constify Try trait)
 - #102203 (rustdoc: remove no-op CSS `#source-sidebar { z-index }`)
 - #102204 (Make `ManuallyDrop` satisfy `~const Destruct`)
 - #102210 (diagnostics: avoid syntactically invalid suggestion in if conditionals)
 - #102226 (bootstrap/miri: switch to non-deprecated env var for setting the sysroot folder)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-24 14:37:01 +00:00
Matthias Krüger
455a20b7ba
Rollup merge of #102186 - ink-feather-org:const_try_trait, r=fee1-dead
Add const_closure, Constify Try trait

Adds a struct for creating const `FnMut` closures (for now just copy pasted form my [const_closure](https://crates.io/crates/const_closure) crate).
I'm not sure if this way is how it should be done.
The `ConstFnClosure` and `ConstFnOnceClosure` structs can probably also be entirely removed.

This is then used to constify the try trait.

Not sure if i should add const_closure in its own pr and maybe make it public behind a perma-unstable feature gate.

cc ```@fee1-dead```  ```@rust-lang/wg-const-eval```
2022-09-24 14:29:54 +02:00
Matthias Krüger
1b1596c118
Rollup merge of #100823 - WaffleLapkin:less_offsets, r=scottmcm
Refactor some `std` code that works with pointer offstes

This PR replaces `pointer::offset` in standard library with `pointer::add` and `pointer::sub`, [re]moving some casts and using `.addr()` while we are at it.

This is a more complicated refactor than all other sibling PRs, so take a closer look when reviewing, please 😃  (though I've checked this multiple times and it looks fine).

r? ````@scottmcm````

_split off from #100746, continuation of #100822_
2022-09-24 14:29:52 +02:00
bors
cdb76db493 Auto merge of #102167 - thomcc:exclusive-inline, r=scottmcm
Add `#[inline]` to trivial functions on `core::sync::Exclusive`

When optimizing for size things like these sometimes don't inlined even though they're generic. This is bad because they're no-ops.

Only dodgy one is poll I guess since it forwards to the inner poll, but it's not like we're doing `#[inline(always)]` here.
2022-09-24 12:17:53 +00:00
bors
199fe1d169 Auto merge of #102223 - matthiaskrgr:rollup-wb1qdhk, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #101780 (Add a platform support document for Android)
 - #102044 (Remove `RtlGenRandom` (take two))
 - #102081 (Adding ignore fuchsia tests for execvp (pre_exec))
 - #102082 (Adding ignore fuchsia non-applicable commands)
 - #102146 (rustdoc: CSS prevent sidebar width change jank)
 - #102152 (Calculate `ProjectionTy::trait_def_id` for return-position `impl Trait` in trait correctly)
 - #102175 (Also require other subtrees to always build successfully)
 - #102176 (Add `llvm-dis` to the set of tools in `ci-llvm`)
 - #102188 (Update doc after renaming `fn is_zero`)
 - #102199 (Improve rustdoc GUI tests)
 - #102218 (Document some missing command-line arguments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-24 06:55:32 +00:00
Matthias Krüger
be902e8905
Rollup merge of #102188 - flba-eb:doc_missed_at_rename, r=jyn514
Update doc after renaming `fn is_zero`

`fn is_zero` has been renamed to `fn count_is_zero` in 1b1bf24636.
This patch updates the documentation accordingly.
2022-09-24 07:38:57 +02:00
Matthias Krüger
3baf5f8d9a
Rollup merge of #102044 - ChrisDenton:BCrypt-system-rand, r=thomcc
Remove `RtlGenRandom` (take two)

First try to use the system preferred RNG but if that fails (e.g. due to a broken system configuration) then fallback to manually opening an algorithm handle.
2022-09-24 07:38:53 +02:00
Scott McMurray
f0dc35927b Put back one of the uses for intra-doc mentions 2022-09-23 21:47:23 -07:00
bors
06968954f7 Auto merge of #100845 - timvermeulen:iter_compare, r=scottmcm
Use internal iteration in `Iterator` comparison methods

Updates the `Iterator` methods `cmp_by`, `partial_cmp_by`, and `eq_by` to use internal iteration on `self`. I've also extracted their shared logic into a private helper function `iter_compare`, which will either short-circuit once the comparison result is known or return the comparison of the lengths of the iterators.

This change also indirectly benefits calls to `cmp`, `partial_cmp`, `eq`, `lt`, `le`, `gt`, and `ge`.

Unsurprising benchmark results: iterators that benefit from internal iteration (like `Chain`) see a speedup, while other iterators are unaffected.
```
 name                           before ns/iter  after ns/iter  diff ns/iter   diff %  speedup
 iter::bench_chain_partial_cmp  208,301         54,978             -153,323  -73.61%   x 3.79
 iter::bench_partial_cmp        55,527          55,702                  175    0.32%   x 1.00
 iter::bench_lt                 55,502          55,322                 -180   -0.32%   x 1.00
```
2022-09-24 04:04:46 +00:00
Nilstrieb
aa35ab81ea Stabilize const BTree{Map,Set}::new
Since `len` and `is_empty` are not const stable yet, this also
creates a new feature for them since they previously used the same
`const_btree_new` feature.
2022-09-23 20:55:37 +02:00
onestacked
84666afb36 Constify Residual behind const_try 2022-09-23 20:17:31 +02:00
onestacked
d78bc41785 Remove unused ConstFn(Once)Closure structs. 2022-09-23 19:55:51 +02:00
onestacked
6267c60f6a Added some spacing in const closure 2022-09-23 18:20:57 +02:00
onestacked
449326aaad Added const Default impls for Arrays and Tuples. 2022-09-23 17:53:59 +02:00
Matthias Krüger
dfe045ad71
Rollup merge of #102177 - inquisitivecrystal:std-doc-typo, r=Dylan-DPC
Fix a typo in `std`'s root docs

Remarkably, this typo has been present for *seven years.* I was so surprised that I reread the text five times and then asked people on the rust Zulip to double-check. :)
2022-09-23 15:40:23 +02:00
Matthias Krüger
6b001f3d68
Rollup merge of #102115 - Alfriadox:master, r=thomcc
Add examples to `bool::then` and `bool::then_some`

Added examples to `bool::then` and `bool::then_some` to show the distinction between the eager evaluation of `bool::then_some` and the lazy evaluation of `bool::then`.
2022-09-23 15:40:20 +02:00
Matthias Krüger
986fc4b5d2
Rollup merge of #102094 - GuillaumeGomez:bool-from-str-missing-docs, r=scottmcm
Add missing documentation for `bool::from_str`

Fixes #101870.
2022-09-23 15:40:20 +02:00
onestacked
53049f7dcd Fixed Doc-Tests 2022-09-23 15:39:13 +02:00
Florian Bartels
8eeeac69db Update doc after renaming fn is_zero
`fn is_zero` has been renamed to `fn count_is_zero` in
1b1bf24636.
This patch updates the documentation accordingly.
2022-09-23 14:16:35 +02:00
onestacked
8e0ea60a04 Constifed Try trait 2022-09-23 13:43:34 +02:00
onestacked
0b2f717dfa Added const_closure 2022-09-23 13:42:31 +02:00
inquisitivecrystal
a0eb46788a Fix a typo in std's root docs 2022-09-23 01:45:43 -07:00
Scott McMurray
cbbcd9f52c rustfmt 2022-09-22 23:13:12 -07:00
Scott McMurray
44b4ce1d61 Make ZST checks in core/alloc more readable
There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff.

This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse.

*Not* proposed for stabilization at this time.  Would be `pub(crate)` except `alloc` wants to use it too.

(And while it doesn't matter now, if we ever get something like 85836 making it a const can help codegen be simpler.)
2022-09-22 23:12:29 -07:00
Thom Chiovoloni
29efe8c789
Add #[inline] to trivial functions on core::sync::Exclusive 2022-09-22 22:15:27 -07:00
Dan Gohman
ed812c7add Add AsFd implementations for stdio lock types on WASI.
This mirrors the implementations on Unix platforms, and also mirrors the
existing `AsRawFd` impls.

This is similar to #100892, but is for the `*Lock` types.
2022-09-22 16:16:39 -07:00
Matthias Krüger
23370637ef
Rollup merge of #102144 - chriss0612:const_convert_control_flow, r=scottmcm
Extend const_convert with const {FormResidual, Try} for ControlFlow.

Very small change so I just used the existing `const_convert` feature flag.  #88674
Newly const API:
```
impl<B, C> const ops::Try for ControlFlow<B, C>;
impl<B, C> const ops::FromResidual for ControlFlow<B, C>;
```

`@usbalbin` I hope it is ok that I added to your feature.
2022-09-22 21:34:55 +02:00
Scott McMurray
c158b7b7d0 Derive Eq/PartialEq instead of manually implementing it 2022-09-22 11:50:51 -07:00
onestacked
5a5138df59 Constify {FormResidual, Try} for ControlFlow 2022-09-22 18:21:34 +02:00
Maybe Waffle
98a32305af Apply changes proposed in the review 2022-09-22 17:44:06 +04:00
Dylan DPC
33b7ff128f
Rollup merge of #102131 - orlp:patch-1, r=thomcc
Added which number is computed in compute_float.

The original comment was very elaborate but ultimately did not mention at all what is being computed using parameters `w, q`, only referencing an external article for the algorithm.
2022-09-22 18:25:57 +05:30
Dylan DPC
c99a603b87
Rollup merge of #102036 - Patiga:remove-io-errorkind-other-use-in-std, r=Mark-Simulacrum
Remove use of `io::ErrorKind::Other` in std

The documentation states that this `ErrorKind` is not used by the standard library. Instead, `io::ErrorKind::Uncategorized` should be used.

The two instances are in the unstable API [linux_pidfd](https://github.com/rust-lang/rust/issues/82971).
2022-09-22 18:25:52 +05:30
Orson Peters
186debc650
Added which number is computed in compute_float. 2022-09-22 11:34:42 +02:00
Venus Xeon-Blonde
ca26dec15f
Add missing assertion 2022-09-22 02:12:06 -04:00
bors
7a8636c843 Auto merge of #100982 - fee1-dead-contrib:const-impl-requires-const-trait, r=oli-obk
Require `#[const_trait]` on `Trait` for `impl const Trait`

r? `@oli-obk`
2022-09-22 04:22:24 +00:00
Venus Xeon-Blonde
804cd8499b
Remove trailing whitespace
Trailing whitespace seemed to be causing the CI checks to error out.
2022-09-21 23:23:14 -04:00
Yuki Okushi
15b4788e36
Rollup merge of #102102 - GuillaumeGomez:doc-aliases-sized-trait, r=thomcc
Add doc aliases on Sized trait

Fixes #101267.

It adds both `?` and `?Sized` doc aliases for the `Sized` trait.

Some screenshots of the result:

![Screenshot from 2022-09-21 16-19-55](https://user-images.githubusercontent.com/3050060/191529854-65a79b75-6c20-4fd4-88c2-56d617d1acff.png)
![Screenshot from 2022-09-21 16-20-04](https://user-images.githubusercontent.com/3050060/191529857-2d11b477-5c5d-4080-9382-0b07950fd7f6.png)
2022-09-22 09:03:57 +09:00
Venus Xeon-Blonde
758ca9dc3a
Add examples to bool::then and bool::then_some
Added examples to `bool::then` and `bool::then_some` to show the distinction between the eager evaluation of `bool::then_some` and the lazy evaluation of `bool::then`.
2022-09-21 17:07:50 -04:00
Scott McMurray
e2d7cdcf2b Add rustc_allow_const_fn_unstable annotations to pre-existing Layout methods 2022-09-21 13:43:21 -07:00
Guillaume Gomez
efbde853af Add doc aliases on Sized trait 2022-09-21 16:20:15 +02:00
Konrad Borowski
80c8680a0c Use fetch_update in sync::Weak::upgrade 2022-09-21 14:06:20 +00:00
Dylan DPC
77d063b954
Rollup merge of #102058 - mqudsi:path_extension_docs, r=thomcc
Clarify Path::extension() semantics in docs abstract

State up-front and center what shape the returned extension will have, without making the user read through the description and examples.

This is a doc-only change. There are no changes to the API contract and the clarification is in line with what was already stated/promised in the existing doc text - just clarified, summarized, and served bright and early.

Rationale: Various frameworks and libraries for different platforms have their different conventions as to whether an "extension" is ".ext" or just "ext" and anyone that's had to deal with this ambiguity in the past is always double- or triple-checking to make sure the function call returns an extension that matches the expected semantics. Offer the answer to this important question right off the bat instead of making them dig to find it.

```@rustbot``` label +A-docs
2022-09-21 19:01:09 +05:30
Dylan DPC
9b24a1f9a0
Rollup merge of #101995 - scottmcm:carrying-mul-example, r=Mark-Simulacrum
Add another example for `uN::carrying_mul`

The prose talks about doing this, so might as well add a simple code example of it too.
2022-09-21 19:01:07 +05:30
Dylan DPC
5377c31122
Rollup merge of #89891 - ojeda:modular-alloc, r=Mark-Simulacrum
`alloc`: add unstable cfg features `no_rc` and `no_sync`

In Rust for Linux we are using these to make `alloc` a bit more modular.

See https://github.com/rust-lang/rust/pull/86048 and https://github.com/rust-lang/rust/pull/84266 for similar requests.

Of course, the particular names are not important.
2022-09-21 19:01:06 +05:30
Guillaume Gomez
b4fdc5861d Add missing documentation for bool::from_str 2022-09-21 14:17:11 +02:00
bors
4ecfdfac51 Auto merge of #100214 - scottmcm:strict-range, r=thomcc
Optimize `array::IntoIter`

`.into_iter()` on arrays was slower than it needed to be (especially compared to slice iterator) since it uses `Range<usize>`, which needs to handle degenerate ranges like `10..4`.

This PR adds an internal `IndexRange` type that's like `Range<usize>` but with a safety invariant that means it doesn't need to worry about those cases -- it only handles `start <= end` -- and thus can give LLVM more information to optimize better.

I added one simple demonstration of the improvement as a codegen test.

(`vec::IntoIter` uses pointers instead of indexes, so doesn't have this problem, but that only works because its elements are boxed.  `array::IntoIter` can't use pointers because that would keep it from being movable.)
2022-09-21 00:41:33 +00:00
bors
7743aa836e Auto merge of #100581 - joboet:sync_rwlock_everywhere, r=thomcc
std: use `sync::RwLock` for internal statics

Since `sync::RwLock` is now `const`-constructible, it can be used for internal statics, removing the need for `sys_common::StaticRwLock`. This adds some extra allocations on platforms which need to box their locks (currently SGX and some UNIX), but these will become unnecessary with the lock improvements tracked in #93740.
2022-09-20 22:00:08 +00:00
Scott McMurray
585bcc6980 Add ptr::Alignment type
Essentially no new code here, just exposing the previously-`pub(crate)` `ValidAlign` type under the name from the ACP.
2022-09-20 14:20:21 -07:00
Chris Denton
8ca6a272bd
Remove RtlGenRandom (take two)
First try to use the system preferred RNG but if that fails (e.g. due to a broken system configuration) then fallback to manually opening an algorithm handle.
2022-09-20 18:39:31 +01:00
Mahmoud Al-Qudsi
c291d2adec Clarify Path::extension() semantics in docs abstract
State up-front and center what shape the returned extension will have, without
making the user read through the description and examples.

Rationale: Various frameworks and libraries for different platforms have their
different conventions as to whether an "extension" is ".ext" or just "ext" and
anyone that's had to deal with this ambiguity in the past is always double- or
triple-checking to make sure the function call returns an extension that matches
the expected semantics. Offer the answer to this important question right off
the bat instead of making them dig to find it.
2022-09-20 11:12:03 -05:00
Scott McMurray
6dbd9a29c2 Optimize array::IntoIter
`.into_iter()` on arrays was slower than it needed to be (especially compared to slice iterator) since it uses `Range<usize>`, which needs to handle degenerate ranges like `10..4`.

This PR adds an internal `IndexRange` type that's like `Range<usize>` but with a safety invariant that means it doesn't need to worry about those cases -- it only handles `start <= end` -- and thus can give LLVM more information to optimize better.

I added one simple demonstration of the improvement as a codegen test.
2022-09-19 23:24:34 -07:00
Patiga
04c108711e Remove use of io::ErrorKind::Other in std
The documentation states that this `ErrorKind` is not used by the
standard library. Instead, `io::ErrorKind::Uncategorized` should be
used.
2022-09-20 02:56:23 +02:00
joboet
be09a4a8b2
std: use sync::RwLock for internal statics 2022-09-19 23:27:26 +02:00
Matthias Krüger
ea076a4f9f
Rollup merge of #101798 - y86-dev:const_waker, r=lcnr
Make `from_waker`, `waker` and `from_raw` unstably `const`

Make
- `Context::from_waker`
- `Context::waker`
- `Waker::from_raw`

`const`.

Also added a small test.
2022-09-19 17:55:19 +02:00
Matthias Krüger
27b1b04065
Rollup merge of #101389 - lukaslueg:rcgetmutdocs, r=m-ou-se
Tone down explanation on RefCell::get_mut

The language around `RefCell::get_mut` is remarkably sketchy and especially to the novice seems to quite strongly discourage using the method ("be cautious", "Also, please be aware", "special circumstances", "usually not what you want"). It was added six years ago in #40634 due to confusion about when to use `get_mut` and `borrow_mut`.

While its signature limits the use-cases for `get_mut`, there is no chance for a safety footgun, and readers can be made aware of `borrow_mut` more softly. I've also just sent a [PR](https://github.com/rust-lang/rust-clippy/issues/9044) to lint situations where `get_mut` could be used to improve ergonomics and performance.

So this PR tones down the language around `get_mut` and also brings it more in line with [`std::sync::Mutex::get_mut()`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html#method.get_mut).
2022-09-19 17:55:18 +02:00
y86-dev
8e848dc23f Added tracking issue 2022-09-19 15:07:12 +02:00
Scott McMurray
690aaef5b6 Add another example for uN::carrying_mul
The prose talked about doing this, so might as well add a simple code example of it too.
2022-09-18 12:55:38 -07:00
bors
4af79ccd5e Auto merge of #101955 - jam1garner:fix-proc-macro-typo, r=petrochenkov
Fix typo in proc_macro Span::eq documentation
2022-09-18 11:42:13 +00:00
bors
4c2e500788 Auto merge of #101816 - raldone01:cleanup/select_nth_unstable, r=Mark-Simulacrum
Cleanup slice sort related closures in core and alloc
2022-09-18 06:03:22 +00:00
jam1garner
527f7887b8
Fix typo in proc_macro Span::eq 2022-09-17 19:15:30 -04:00
bors
5253b0a0a1 Auto merge of #101949 - matthiaskrgr:rollup-xu5cqnd, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #101093 (Initial version of 1.64 release notes)
 - #101713 (change AccessLevels representation)
 - #101821 (Bump Unicode to version 15.0.0, regenerate tables)
 - #101826 (Enforce "joined()" and "joined_with_noop()" test)
 - #101835 (Allow using vendoring when running bootstrap from outside the source root)
 - #101942 (Revert "Copy stage0 binaries into stage0-sysroot")
 - #101943 (rustdoc: remove unused CSS `.non-exhaustive { margin-bottom }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-17 22:04:28 +00:00
Matthias Krüger
36b066daa4
Rollup merge of #101821 - thomcc:unicode-15, r=Manishearth
Bump Unicode to version 15.0.0, regenerate tables

r? `@Mark-Simulacrum`
2022-09-17 23:30:49 +02:00
Matthias Krüger
92d8bf918c
Rollup merge of #101861 - wesleywiser:update_stdarch, r=Amanieu
Update stdarch

This pulls in the following changes:

- [Use simd_bitmask intrinsic in a couple of places](9f0928782b)
- [Remove simd_shuffle<n> usage in favor of simd_shuffle](3fd17e4607)
- [Remove late specifiers in __cpuid_count](f1db941633)
  - Helps with #101346
- [Use mov and xchg instead of movl(q) and xchgl(q)](3049a31937)
- [Bump cfg-if dependency to 1.0](f305cc83e7)
- [Fix documentation of __m256bh and __m512bh structs](699c093a42)

r? ``@Amanieu``
2022-09-17 19:27:07 +02:00
Matthias Krüger
00d88bdb2c
Rollup merge of #101672 - idigdoug:array_try_into, r=Mark-Simulacrum
array docs - advertise how to get array from slice

On my first Rust project, I spent more time than I care to admit figuring out how to efficiently get an array from a slice. Update the array documentation to explain this a bit more clearly.

(As a side note, it's a bit unfortunate that get-array-from-slice is only available via trait since that means it can't be used from const functions yet.)
2022-09-17 19:27:05 +02:00
bors
672831a5c8 Auto merge of #101938 - Dylan-DPC:rollup-6vlohhs, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #93628 (Stabilize `let else`)
 - #98441 (Implement simd_as for pointers)
 - #101790 (Do not suggest a placeholder to const and static without a type)
 - #101807 (Disallow defaults on type GATs)
 - #101915 (doc: fix redirected link in `/index.html`)
 - #101931 (doc: Fix a typo in `Rc::make_mut` docstring)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-17 10:56:42 +00:00
Dylan DPC
80cceb8f77
Rollup merge of #101931 - msakuta:master, r=thomcc
doc: Fix a typo in `Rc::make_mut` docstring

A very minor typo fix.
2022-09-17 15:31:09 +05:30
Dylan DPC
3ad81e0dd8
Rollup merge of #93628 - est31:stabilize_let_else, r=joshtriplett
Stabilize `let else`

🎉  **Stabilizes the `let else` feature, added by [RFC 3137](https://github.com/rust-lang/rfcs/pull/3137).** 🎉

Reference PR: https://github.com/rust-lang/reference/pull/1156

closes #87335 (`let else` tracking issue)

FCP: https://github.com/rust-lang/rust/pull/93628#issuecomment-1029383585

----------

## Stabilization report

### Summary

The feature allows refutable patterns in `let` statements if the expression is
followed by a diverging `else`:

```Rust
fn get_count_item(s: &str) -> (u64, &str) {
    let mut it = s.split(' ');
    let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
        panic!("Can't segment count item pair: '{s}'");
    };
    let Ok(count) = u64::from_str(count_str) else {
        panic!("Can't parse integer: '{count_str}'");
    };
    (count, item)
}
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
```

### Differences from the RFC / Desugaring

Outside of desugaring I'm not aware of any differences between the implementation and the RFC. The chosen desugaring has been changed from the RFC's [original](https://rust-lang.github.io/rfcs/3137-let-else.html#reference-level-explanations). You can read a detailed discussion of the implementation history of it in `@cormacrelf` 's [summary](https://github.com/rust-lang/rust/pull/93628#issuecomment-1041143670) in this thread, as well as the [followup](https://github.com/rust-lang/rust/pull/93628#issuecomment-1046598419). Since that followup, further changes have happened to the desugaring, in #98574, #99518, #99954. The later changes were mostly about the drop order: On match, temporaries drop in the same order as they would for a `let` declaration. On mismatch, temporaries drop before the `else` block.

### Test cases

In chronological order as they were merged.

Added by df9a2e0687 (#87688):

* [`ui/pattern/usefulness/top-level-alternation.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/pattern/usefulness/top-level-alternation.rs) to ensure the unreachable pattern lint visits patterns inside `let else`.

Added by 5b95df4bdc (#87688):

* [`ui/let-else/let-else-bool-binop-init.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-bool-binop-init.rs) to ensure that no lazy boolean expressions (using `&&` or `||`) are allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-brace-before-else.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-brace-before-else.rs) to ensure that no `}` directly preceding the `else` is allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-check.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-check.rs) to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for the `else` block.
* [`ui/let-else/let-else-irrefutable.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-irrefutable.rs) to ensure that the `irrefutable_let_patterns` lint fires.
* [`ui/let-else/let-else-missing-semicolon.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-missing-semicolon.rs) to ensure the presence of semicolons at the end of the `let` statement.
* [`ui/let-else/let-else-non-diverging.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-non-diverging.rs) to ensure the `else` block diverges.
* [`ui/let-else/let-else-run-pass.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-run-pass.rs) to ensure the feature works in some simple test case settings.
* [`ui/let-else/let-else-scope.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-scope.rs) to ensure the bindings created by the outer `let` expression are not available in the `else` block of it.

Added by bf7c32a447 (#89965):

* [`ui/let-else/issue-89960.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/issue-89960.rs) as a regression test for the ICE-on-error bug #89960 . Later in 102b9125e1 this got removed in favour of more comprehensive tests.

Added by 856541963c (#89974):

* [`ui/let-else/let-else-if.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-if.rs) to test for the improved error message that points out that `let else if` is not possible.

Added by 9b45713b6c:

* [`ui/let-else/let-else-allow-unused.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-unused.rs) as a regression test for #89807, to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for bindings created by the `let else` pattern.

Added by 61bcd8d307 (#89841):

* [`ui/let-else/let-else-non-copy.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-non-copy.rs) to ensure that a copy is performed out of non-copy wrapper types. This mirrors `if let` behaviour. The test case bases on rustc internal changes originally meant for #89933 but then removed from the PR due to the error prior to the improvements of #89841.
* [`ui/let-else/let-else-source-expr-nomove-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-source-expr-nomove-pass.rs) to ensure that while there is a move of the binding in the successful case, the `else` case can still access the non-matching value. This mirrors `if let` behaviour.

Added by 102b9125e1 (#89841):

* [`ui/let-else/let-else-ref-bindings.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings.rs) and [`ui/let-else/let-else-ref-bindings-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings-pass.rs) to check `ref` and `ref mut` keywords in the pattern work correctly and error when needed.

Added by 2715c5f984 (#89841):

* Match ergonomic tests adapted from the `rfc2005` test suite.

Added by fec8a507a2 (#89841):

* [`ui/let-else/let-else-deref-coercion-annotated.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion-annotated.rs) and [`ui/let-else/let-else-deref-coercion.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion.rs) to check deref coercions.

#### Added since this stabilization report was originally written (2022-02-09)

Added by 76ea566677 (#94211):

* [`ui/let-else/let-else-destructuring.rs`](https://github.com/rust-lang/rust/blob/1.63.0/src/test/ui/let-else/let-else-destructuring.rs) to give a nice error message if an user tries to do an assignment with a (possibly refutable) pattern and an `else` block, like asked for in #93995.

Added by e7730dcb7e (#94208):

* [`ui/let-else/let-else-allow-in-expr.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-in-expr.rs) to test whether `#[allow(unused_variables)]` works in the expr, as well as its non presence, as well as putting it on the entire `let else` *affects* the expr, too. This was adding a missing test as pointed out by the stabilization report.
* Expansion of `ui/let-else/let-else-allow-unused.rs` and `ui/let-else/let-else-check.rs` to ensure that non-presence of `#[allow(unused)]` does issue the unused lint. This was adding a missing test case as pointed out by the stabilization report.

Added by 5bd71063b3 (#94208):

* [`ui/let-else/let-else-slicing-error.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-slicing-error.rs), a regression test for #92069, which got fixed without addition of a regression test. This resolves a missing test as pointed out by the stabilization report.

Added by 5374688e1d (#98574):

* [`src/test/ui/async-await/async-await-let-else.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/async-await-let-else.rs) to test the interaction of async/await with `let else`

Added by 6c529ded86 (#98574):

* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) as a (partial) regression test for #98672

Added by 9b56640106 (#99518):

* [`src/test/ui/let-else/let-else-temp-borrowck.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) as a regression test for #93951
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #98672 (especially regarding `else` drop order)

Added by baf9a7cb57 (#99518):

* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #93951, similar to `let-else-temp-borrowck.rs`

Added by 60be2de8b7 (#99518):

* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a program that can now be compiled thanks to borrow checker implications of #99518

Added by 47a7a91c96 (#100132):

* [`src/test/ui/let-else/issue-100103.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-100103.rs), as a regression test for #100103, to ensure that there is no ICE when doing `Err(...)?` inside else blocks.

Added by e3c5bd617d (#100443):

* [`src/test/ui/let-else/let-else-then-diverge.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-then-diverge.rs), to verify that there is no unreachable code error with the current desugaring.

Added by 981852677c (#100443):

* [`src/test/ui/let-else/issue-94176.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-94176.rs), to make sure that a correct span is emitted for a missing trailing expression error. Regression test for #94176.

Added by e182d12a84 (#100434):

* [src/test/ui/unpretty/pretty-let-else.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/unpretty/pretty-let-else.rs), as a regression test to ensure pretty printing works for `let else` (this bug surfaced in many different ways)

Added by e26285603c (#99954):

* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) extended to contain & borrows as well, as this was identified as an earlier issue with the desugaring: https://github.com/rust-lang/rust/issues/98672#issuecomment-1200196921

Added by 2d8460ef43 (#99291):

* [`src/test/ui/let-else/let-else-drop-order.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-drop-order.rs) a matrix based test for various drop order behaviour of `let else`. Especially, it verifies equality of `let` and `let else` drop orders, [resolving](https://github.com/rust-lang/rust/pull/93628#issuecomment-1238498468) a [stabilization blocker](https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523).

Added by 1b87ce0d40 (#101410):

* Edit to `src/test/ui/let-else/let-else-temporary-lifetime.rs` to add the `-Zvalidate-mir` flag, as a regression test for #99228

Added by af591ebe4d (#101410):

* [`src/test/ui/let-else/issue-99975.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-99975.rs) as a regression test for the ICE #99975.

Added by this PR:

* `ui/let-else/let-else.rs`, a simple run-pass check, similar to `ui/let-else/let-else-run-pass.rs`.

### Things not currently tested

* ~~The `#[allow(...)]` tests check whether allow works, but they don't check whether the non-presence of allow causes a lint to fire.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~There is no `#[allow(...)]` test for the expression, as there are tests for the pattern and the else block.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~`let-else-brace-before-else.rs` forbids the `let ... = {} else {}` pattern and there is a rustfix to obtain `let ... = ({}) else {}`. I'm not sure whether the `.fixed` files are checked by the tooling that they compile. But if there is no such check, it would be neat to make sure that `let ... = ({}) else {}` compiles.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~#92069 got closed as fixed, but no regression test was added. Not sure it's worth to add one.~~ → *test added by 5bd71063b3810d977aa376d1e6dd7cec359330cc*
* ~~consistency between `let else` and `if let` regarding lifetimes and drop order: https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523~~ → *test added by 2d8460ef43d902f34ba2133fe38f66ee8d2fdafc*

Edit: they are all tested now.

### Possible future work / Refutable destructuring assignments

[RFC 2909](https://rust-lang.github.io/rfcs/2909-destructuring-assignment.html) specifies destructuring assignment, allowing statements like `FooBar { a, b, c } = foo();`.
As it was stabilized, destructuring assignment only allows *irrefutable* patterns, which before the advent of `let else` were the only patterns that `let` supported.
So the combination of `let else` and destructuring assignments gives reason to think about extensions of the destructuring assignments feature that allow refutable patterns, discussed in #93995.

A naive mapping of `let else` to destructuring assignments in the form of `Some(v) = foo() else { ... };` might not be the ideal way. `let else` needs a diverging `else` clause as it introduces new bindings, while assignments have a default behaviour to fall back to if the pattern does not match, in the form of not performing the assignment. Thus, there is no good case to require divergence, or even an `else` clause at all, beyond the need for having *some* introducer syntax so that it is clear to readers that the assignment is not a given (enums and structs look similar). There are better candidates for introducer syntax however than an empty `else {}` clause, like `maybe` which could be added as a keyword on an edition boundary:

```Rust
let mut v = 0;
maybe Some(v) = foo(&v);
maybe Some(v) = foo(&v) else { bar() };
```

Further design discussion is left to an RFC, or the linked issue.
2022-09-17 15:31:06 +05:30
bors
b195f5349a Auto merge of #101784 - reitermarkus:const-memchr, r=thomcc
Simplify `const` `memchr`.

Extracted from https://github.com/rust-lang/rust/pull/101607.

Removes the need for `const_eval_select`.
2022-09-17 08:15:35 +00:00
msakuta
673c43b6e1 Fix a typo in docstring 2022-09-17 13:58:53 +09:00
Bradford Hovinen
e19a98cff7 Do not panic when a test function returns Result::Err.
Rust's test library allows test functions to return a Result, so that the test is deemed to have failed if the function returns a Result::Err variant. Currently, this works by having Result implement the Termination trait and asserting in assert_test_result that Termination::report() indicates successful completion. This turns a Result::Err into a panic, which is caught and unwound in the test library.

This approach is problematic in certain environments where one wishes to save on both binary size and compute resources when running tests by:

 * Compiling all code with --panic=abort to avoid having to generate unwinding tables, and
 * Running most tests in-process to avoid the overhead of spawning new processes.

This change removes the intermediate panic step and passes a Result::Err directly through to the test runner.

To do this, it modifies assert_test_result to return a Result<(), String> where the Err variant holds what was previously the panic message. It changes the types in the TestFn enum to return Result<(), String>.

This tries to minimise the changes to benchmark tests, so it calls unwrap() on the Result returned by assert_test_result, effectively keeping the same behaviour as before.
2022-09-16 14:36:00 +00:00
Dylan DPC
cfef659d13
Rollup merge of #101802 - chriss0612:const_fn_trait_ref_impls, r=fee1-dead
Constify impl Fn* &(mut) Fn*

Tracking Issue: [101803](https://github.com/rust-lang/rust/issues/101803)

Feature gate: `#![feature(const_fn_trait_ref_impls)]`

This feature allows using references to Fn* Items as Fn* Items themself in a const context.
2022-09-16 11:17:02 +05:30
Deadbeef
31f259ce5a Add const_trait to Allocator 2022-09-16 12:08:45 +08:00
Deadbeef
08ac185e99 append_const_msg for std traits 2022-09-16 11:48:43 +08:00
Deadbeef
a77f4bc6d3 Mark Drop with #[const_trait] 2022-09-16 11:48:43 +08:00
Deadbeef
5a6273e263 Do not implement Unpin as const 2022-09-16 11:48:42 +08:00
Deadbeef
bc6483d11e Prevent errors for stage0 rustc build 2022-09-16 11:48:42 +08:00
Deadbeef
4b539b04a6 Add more const_trait annotations 2022-09-16 11:48:42 +08:00
Deadbeef
be65e03676 Add const_traits 2022-09-16 11:48:42 +08:00
Deadbeef
81b1810cd7 Require #[const_trait] for const impls 2022-09-16 11:48:42 +08:00
est31
173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
Wesley Wiser
9286c3c3f5 Update stdarch
stdarch updated their version of `cfg-if` so we need to update the one
used by libstd as well.
2022-09-15 13:05:28 -04:00
Matthias Krüger
b71b640f3c
Rollup merge of #101810 - raldone01:feat/const_partial_eq_ordering, r=fee1-dead
Constify `PartialEq` for `Ordering`

Adds `impl const PartialEq for Ordering {}` to #92391.
2022-09-15 08:00:16 +02:00
Matthias Krüger
93ae223951
Rollup merge of #101559 - andrewpollack:add-backtrace-off-fuchsia, r=tmandry
Adding "backtrace off" option for fuchsia targets

Used for improving compiler test suite results on Fuchsia targets
2022-09-15 08:00:12 +02:00
Andrew Pollack
88baf8f6f5 Adding backtrace off option for fuchsia targets 2022-09-14 23:54:40 +00:00
Thom Chiovoloni
ac55092a14
Bump Unicode to version 15.0.0, regenerate tables 2022-09-14 13:21:19 -07:00
raldone01
59fe291cec Cleanup closures. 2022-09-14 20:11:45 +02:00
Keenan Gugeler
3d28a1ad76 Warn about safety of fetch_update
Specifically as it relates to the ABA problem.
2022-09-14 13:25:14 -04:00
raldone01
f4ff6860dc Constify PartialEq for Ordering. 2022-09-14 18:31:53 +02:00
onestacked
8d6edac763 Add const_slice_split_at_mut Feature gate. 2022-09-14 16:54:49 +02:00
onestacked
478c471ce8 Added Tracking Issue number. 2022-09-14 15:10:02 +02:00
y86-dev
9a78faba71 Made from_waker, waker, from_raw const 2022-09-14 14:53:16 +02:00
onestacked
404b60bf6b Constify impl Fn* &(mut) Fn* 2022-09-14 14:19:11 +02:00
Markus Reiter
db29de7745
Simplify const memchr. 2022-09-14 02:00:18 +02:00
Matthias Krüger
e44073b5db
Rollup merge of #101754 - NaokiM03:rename-log-to-ilog, r=Dylan-DPC
Fix doc of log function

Hi.

I found a forgotten documentation correction in the following pull request.
https://github.com/rust-lang/rust/pull/100332

See also:
https://github.com/rust-lang/rust/issues/70887
2022-09-13 22:25:36 +02:00
Dylan DPC
95c9a7e7c8
Rollup merge of #101745 - jay3332:patch-1, r=JohnTitor
Fix typo in concat_bytes documentation

This fixes the typo `&[u8, _]` -> `&[u8; _]`
2022-09-13 16:51:32 +05:30
NaokiM03
a4f8d3e36d Fix doc of log function 2022-09-13 19:21:40 +09:00
bors
c81575657c Auto merge of #100640 - reitermarkus:socket-display-buffer, r=thomcc
Use `DisplayBuffer` for socket addresses.

Continuation of https://github.com/rust-lang/rust/pull/100625 for socket addresses.

Renames `net::addr` to `net::addr::socket`, `net::ip` to `net::addr::ip` and `net::ip::display_buffer::IpDisplayBuffer` to `net::addr::display_buffer::DisplayBuffer`.
2022-09-13 06:41:37 +00:00
Jay3332
ba3b3bcc17
Fix typo in concat_bytes documentation
This fixes the typo `&[u8, _]` -> `&[u8; _]`
2022-09-12 21:40:28 -04:00
Guillaume Gomez
7fc3183520
Rollup merge of #100291 - WaffleLapkin:cstr_const_methods, r=oli-obk
constify some `CStr` methods

This PR marks the following public APIs as `const`:
```rust
impl CStr {
    // feature(const_cstr_from_bytes)
    pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError>;
    pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError>;

    // feature(const_cstr_to_bytes)
    pub const fn to_bytes(&self) -> &[u8];
    pub const fn to_bytes_with_nul(&self) -> &[u8];
    pub const fn to_str(&self) -> Result<&str, str::Utf8Error>;
}
```

r? ```@oli-obk``` (use of `const_eval_select` :P )
cc ```@mina86``` (you've asked for this <3 )
2022-09-12 22:47:14 +02:00
Markus Reiter
14230a7f8e
Simplify clippy fix. 2022-09-12 19:46:51 +02:00
Markus Reiter
d01498a902
Add rustc_diagnostic_item for IP addresses. 2022-09-12 19:04:17 +02:00
Markus Reiter
f7e8ba28a4
Flatten net module again. 2022-09-12 19:04:17 +02:00
Markus Reiter
a1e4a339ed
Move net::parser into net::addr module. 2022-09-12 19:04:17 +02:00
Markus Reiter
65003fd4e3
Add tests for SockAddr Display. 2022-09-12 19:04:16 +02:00
Markus Reiter
96b44f6f65
Use DisplayBuffer for socket addresses. 2022-09-12 19:04:16 +02:00
Maybe Waffle
cb02b647dc constify CStr methods 2022-09-12 16:29:12 +04:00
Dylan DPC
10af4fb530
Rollup merge of #101671 - LingMan:ieee_754, r=Dylan-DPC
Fix naming format of IEEE 754 standard

Currently the documentation of f64::min refers to "IEEE-754 2008" while the documentation of f64::minimum refers to "IEEE 754-2019".
Note that one has the format IEEE,hyphen,number,space,year while the other is IEEE,space,number,hyphen,year. The official IEEE site [1] uses the later format and it is also the one most commonly used throughout the codebase.

Update all comments and - more importantly - documentation to consistently use the official format.

[1] https://standards.ieee.org/ieee/754/4211/
2022-09-12 15:21:32 +05:30
Dylan DPC
93177758fc
Rollup merge of #100767 - kadiwa4:escape_ascii, r=jackh726
Remove manual <[u8]>::escape_ascii

`@rustbot` label: +C-cleanup
2022-09-12 15:21:30 +05:30
bors
3194958217 Auto merge of #100251 - compiler-errors:tuple-trait-2, r=jackh726
Implement `std::marker::Tuple`

Split out from #99943 (https://github.com/rust-lang/rust/pull/99943#pullrequestreview-1064459183).

Implements part of rust-lang/compiler-team#537
r? `@jackh726`
2022-09-12 03:24:29 +00:00
bors
98e1f041b6 Auto merge of #101442 - joboet:null_check_tcs, r=thomcc
Check if TCS is a null pointer on SGX

The `EENTER` instruction only checks if the TCS is aligned, not if it zero. Saying the address returned is a `NonNull<u8>` (for which `Tcs` is a type alias) is unsound. As well-behaved runners will not put the TCS at address zero, so the definition of `Tcs` is correct. However, `std` should check the address before casting it to a `NonNull`.

ping `@jethrogb` `@raoulstrackx`
`@rustbot` label I-unsound
2022-09-11 22:19:24 +00:00
bors
59e7a308e4 Auto merge of #101299 - saethlin:vecdeque-drain-drop, r=thomcc
Remove &[T] from vec_deque::Drain

Fixes https://github.com/rust-lang/rust/issues/60076

I don't know what the right approach is here. There were a few suggestions in the issue, and they all seem a bit thorny to implement. So I just picked one that was kind of familiar.
2022-09-11 19:50:41 +00:00
joboet
2fa58080cb
std: check if TCS is a null pointer 2022-09-11 12:15:32 +02:00
bors
56b625be68 Auto merge of #101482 - joboet:netbsd_parker, r=sanxiyn
Optimize thread parking on NetBSD

As the futex syscall is not present in the latest stable release, NetBSD cannot use the efficient thread parker and locks Linux uses. Currently, it therefore relies on a pthread-based parker, consisting of a mutex and semaphore which protect a state variable. NetBSD however has more efficient syscalls available: [`_lwp_park`](https://man.netbsd.org/_lwp_park.2) and [`_lwp_unpark`](https://man.netbsd.org/_lwp_unpark.2). These already provide the exact semantics of `thread::park` and `Thread::unpark`, but work with thread ids. In `std`, this ID is here stored in an atomic state variable, which is also used to optimize cases were the parking token is already available at the time `thread::park` is called.

r? `@m-ou-se`
2022-09-11 04:07:17 +00:00
Doug Cook (WINDOWS)
705a7667c5 array docs - advertise how to get array from slice
On my first Rust project, I spent more time than I care to admit
figuring out how to efficiently get an array from a slice. Update the
array documentation to explain this a bit more clearly.

(As a side note, it's a bit unfortunate that get-array-from-slice is
only available via trait since that means it can't be used from const
functions yet.)
2022-09-10 19:37:07 -07:00
LingMan
fd21df7182 Fix naming format of IEEE 754 standard
Currently the documentation of f64::min refers to "IEEE-754 2008" while the documentation of
f64::minimum refers to "IEEE 754-2019".
Note that one has the format IEEE,hyphen,number,space,year while the other is
IEEE,space,number,hyphen,year. The official IEEE site [1] uses the later format and it is also the
one most commonly used throughout the codebase.

Update all comments and - more importantly - documentation to consistently use the official format.

[1] https://standards.ieee.org/ieee/754/4211/
2022-09-11 04:13:33 +02:00
bors
abd4d2ef0d Auto merge of #101643 - ChrisDenton:alloc-link-kernel32, r=thomcc
Explicitly link kernel32.lib from alloc
2022-09-11 01:44:09 +00:00
Ben Kimock
54684c438f Alternate approach; just modify Drain 2022-09-10 17:52:34 -04:00
Ben Kimock
25f4cb59d3 Remove &[T] from vec_deque::Drain 2022-09-10 17:52:34 -04:00
joboet
81b11ed698
std: optimize thread parking on NetBSD 2022-09-10 20:03:15 +02:00
Dylan DPC
33d54c4f73
Rollup merge of #101606 - akhi3030:patch-1, r=Dylan-DPC
doc: fix minor typo
2022-09-10 18:56:07 +05:30
Giacomo Stevanato
dad049cb5c Update test 2022-09-10 13:13:54 +02:00
Giacomo Stevanato
f52082f543 Update documentation 2022-09-10 13:13:54 +02:00
Chris Denton
931e851144
Explicitly link kernel32.lib from alloc 2022-09-10 11:57:36 +01:00
bors
5197c96c49 Auto merge of #101483 - oli-obk:guaranteed_opt, r=fee1-dead
The `<*const T>::guaranteed_*` methods now return an option for the unknown case

cc https://github.com/rust-lang/rust/issues/53020#issuecomment-1236932443

I chose `0` for "not equal" and `1` for "equal" and left `2` for the unknown case so backends can just forward to raw pointer equality and it works 

r? `@fee1-dead` or `@lcnr`

cc `@rust-lang/wg-const-eval`
2022-09-10 09:50:21 +00:00
Giacomo Stevanato
f81b07e947 Adapt inplace collection leak test to check for no leaks 2022-09-10 11:34:23 +02:00
Giacomo Stevanato
fa61678a7d Fix leaking in inplace collection when destructor panics 2022-09-10 11:34:22 +02:00
bors
395e56f398 Auto merge of #101617 - Dylan-DPC:rollup-iiy4ipc, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #101366 (Restore old behaviour on broken UNC paths)
 - #101492 (Suggest adding array lengths to references to arrays if possible)
 - #101529 (Fix the example code and doctest for Formatter::sign_plus)
 - #101573 (update `ParamKindOrd`)
 - #101612 (Fix code generation of `Rvalue::Repeat` with 128 bit values)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-09 23:06:40 +00:00
Dylan DPC
fcdd5016c5
Rollup merge of #101529 - mousetail:patch-2, r=thomcc
Fix the example code and doctest for Formatter::sign_plus

The provided example to the `sign_plus` method on `fmt` was broken, it displays the `-` sign twice for negative numbers.

This pull request should fix the issue by `.abs()` ing the number so that the negative sign appears only once. It is just one possible solution to the issue, not sure if it's the best. However, this one will behave as expected when combined with fill and alignment operators.
2022-09-09 22:02:17 +05:30
Dylan DPC
d9609c7c26
Rollup merge of #101366 - ChrisDenton:unc-forward-slash, r=m-ou-se
Restore old behaviour on broken UNC paths

This fixes #101358 by restoring the behaviour from previous stable Rust versions. I'm not convinced this is ultimately right but I think it's less wrong and maybe this should be backported to beta?

r? libs
2022-09-09 22:02:16 +05:30
Oli Scherer
f632dbe46f The <*const T>::guaranteed_* methods now return an option for the unknown case 2022-09-09 15:16:04 +00:00
Guillaume Gomez
ff21ccfba1
Rollup merge of #101529 - mousetail:patch-2, r=thomcc
Fix the example code and doctest for Formatter::sign_plus

The provided example to the `sign_plus` method on `fmt` was broken, it displays the `-` sign twice for negative numbers.

This pull request should fix the issue by `.abs()` ing the number so that the negative sign appears only once. It is just one possible solution to the issue, not sure if it's the best. However, this one will behave as expected when combined with fill and alignment operators.
2022-09-09 15:36:37 +02:00
Guillaume Gomez
3ec332fc82
Rollup merge of #101495 - bjorn3:pause-no-sse2, r=Mark-Simulacrum
Compile spin_loop_hint as pause on x86 even without sse2 enabled

The x86 `pause` instruction was introduced with sse2, but because it is encoded as `rep nop`, it works just fine on cpu's without sse2 support. It just doesn't do anything.
2022-09-09 15:36:36 +02:00
joboet
262193e044
std: use futex-based locks and thread parker on Hermit 2022-09-09 11:56:50 +02:00
Akhilesh Singhania
1933b74dbd
doc: fix minor typo 2022-09-09 11:30:40 +02:00
Matthias Krüger
bdfbc3597b
Rollup merge of #101556 - compiler-errors:tweak-generator-print, r=jackh726
Tweak future opaque ty pretty printing

1. The `Return` type of a generator doesn't need to be a lang item just for diagnostic printing of types
2. We shouldn't suppress the `Output = Ty` of a opaque future if the type is a int or float var.
2022-09-09 07:02:32 +02:00
bors
7200da0217 Auto merge of #93873 - Stovent:big-ints, r=m-ou-se
Reimplement `carrying_add` and `borrowing_sub` for signed integers.

As per the discussion in #85532, this PR reimplements `carrying_add` and `borrowing_sub` for signed integers.

It also adds unit tests for both unsigned and signed integers, emphasing on the behaviours of the methods.
2022-09-09 00:59:08 +00:00
Michael Goulet
2c4dc4f494
Rollup merge of #101423 - mkroening:hermit-warnings, r=sanxiyn
Fix hermit warnings

This fixes two `unused_imprt` and one `dead_code` warning for hermit.
2022-09-08 14:41:08 -07:00
Dylan DPC
7064344ba4
Rollup merge of #101422 - mkroening:hermit-file-time, r=joshtriplett
Hermit: Add File::set_time stub

This is not supported on hermit yet. This change is required for compiling std.
2022-09-08 11:55:07 +05:30
Michael Goulet
2c94102df5 Generator return doesn't need to be a lang item 2022-09-08 02:52:57 +00:00
Jacob Pratt
5510a69981
Stabilize #![feature(mixed_integer_ops)] 2022-09-07 21:59:09 -04:00
bors
c2804e6ec2 Auto merge of #101544 - matthiaskrgr:rollup-4urx917, r=matthiaskrgr
Rollup of 14 pull requests

Successful merges:

 - #101343 (Add -api-level to pm command)
 - #101416 (stdio: Document no support for writing to non-blocking stdio/stderr)
 - #101435 (Remove unnecessary `EMIT_MIR_FOR_EACH_BITWIDTH`)
 - #101493 (Pass ImplTraitContext as &mut to avoid the need of ImplTraitContext::reborrow)
 - #101502 (Do not suggest a semicolon for a macro without `!`)
 - #101503 (Add debug calls)
 - #101506 (rustdoc: remove unused CSS `#main-content > .since`)
 - #101507 (rustdoc: remove unused CSS `#main-content > table td`)
 - #101521 (Rustdoc-Json: More accurate struct type.)
 - #101525 (Fix typo in pass_manager.rs)
 - #101534 (rustdoc: remove unused mobile CSS `.rustdoc { flex-direction }`)
 - #101535 (Fix error printing mistake in tidy)
 - #101536 (Add documentation for Attr::is_doc_comment)
 - #101538 (rustdoc: remove unused CSS `.content .methods > div`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-07 21:17:30 +00:00
bors
9682b5d3a3 Auto merge of #101476 - ChrisDenton:BCryptRandom-fix, r=thomcc
Open a BCrypt algorithm handle

Fixes #101474, supplants #101456.

Replaces use of a pseduo handle with manually opening a algorithm handle.

Most interesting thing here is the atomics.

r? `@thomcc`
2022-09-07 18:54:03 +00:00
Maurits van Riezen
5fbe485ecc
Typo 2022-09-07 17:53:47 +02:00
Maurits van Riezen
0a9b49c794
Add doctest 2022-09-07 16:36:32 +02:00
Usama Arif
dfbc1f712d stdio: Document no support for writing to non-blocking stdio/stderr
Printing to stdio/stderr that have been opened with non-blocking
(O_NONBLOCK in linux) can result in an error, which is not handled
by std::io module causing a panic.

Signed-off-by: Usama Arif <usama.arif@bytedance.com>
2022-09-07 14:22:57 +01:00
Chris Denton
832c7af0ea
Don't break windows/rand for miri 2022-09-07 14:00:15 +01:00