Commit Graph

7368 Commits

Author SHA1 Message Date
Matthias Krüger
277802e99a
Rollup merge of #94947 - Dylan-DPC:fix/typos, r=oli-obk
fix typos

Rework of #94603 which got closed as I was trying to unmerge and repush.  This is a subset of changes from the original pr as I sed'd whatever typos I remembered from the original PR

thanks to `@cuishuang` for the original PR
2022-03-15 17:15:53 +01:00
zed.zy
7da07ff48b Improve the explanation about the behaviour of read_line 2022-03-15 19:37:52 +08:00
Dylan DPC
13e889986d fix typos 2022-03-15 02:00:08 +01:00
Tony Arcieri
78567df575 Stabilize ADX target feature
This is a continuation of #60109, which noted that while the ADX
intrinsics were stabilized, the corresponding target feature never was.

This PR follows the same general structure and stabilizes the ADX target
feature.
2022-03-14 18:56:39 -06:00
Matthias Krüger
0e423932f8
Rollup merge of #90621 - adamgemmell:dev/stabilise-target-feature, r=Amanieu
Stabilise `aarch64_target_feature`

This PR stabilises `aarch64_target_feature` - see https://github.com/rust-lang/rust/issues/90620
2022-03-14 17:24:56 +01:00
Thomas Orozco
b628497b7c Add a process_group method to UNIX CommandExt 2022-03-14 14:33:41 +00:00
Adam Gemmell
5a5621791f Stabilise aarch64_target_feature 2022-03-14 11:02:50 +00:00
bors
e95b10ba4a Auto merge of #94916 - matthiaskrgr:rollup-s6zedfl, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #93292 (Implement `BITS` constant for non-zero integers)
 - #94777 (Update armv7-unknown-linux-uclibceabi platform support page.)
 - #94816 (Add `Atomic*::get_mut_slice`)
 - #94844 (Reduce rustbuild bloat caused by serde_derive)
 - #94907 (Omit stdarch test crates from the rust-src component)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-13 20:59:29 +00:00
Matthias Krüger
8dad2d172c
Rollup merge of #94816 - WaffleLapkin:atomic_get_mut_slice, r=Mark-Simulacrum
Add `Atomic*::get_mut_slice`

This PR adds the inverse of `Atomic*::from_mut_slice` introduced in #94384 with the following API:
```rust
// core::sync::atomic

impl Atomic* {
    fn get_mut_slice(this: &mut [Self]) -> &mut [*];
}
```

cc `@cuviper`

-----

For now I've used the same tracking issue as `Atomic*::from_mut_slice`, should I open a new one?
2022-03-13 20:02:00 +01:00
Matthias Krüger
2f9bc56e5a
Rollup merge of #93292 - nvzqz:nonzero-bits, r=dtolnay
Implement `BITS` constant for non-zero integers

This adds the associated [`BITS`](https://doc.rust-lang.org/stable/std/primitive.usize.html#associatedconstant.BITS) constant to `NonZero{U,I}{8,16,32,64,128,size}`.

This is useful when a type alias refers to either a regular or non-zero integer.
2022-03-13 20:01:58 +01:00
bors
21b0325c68 Auto merge of #94738 - Urgau:rustbuild-check-cfg-values, r=Mark-Simulacrum
Enable conditional checking of values in the Rust codebase

This pull-request enable conditional checking of (well known) values in the Rust codebase.

Well known values were added in https://github.com/rust-lang/rust/pull/94362. All the `target_*` values are taken from all the built-in targets which is why some extra values were needed do be added as they are not (yet ?) defined in any built-in targets.

r? `@Mark-Simulacrum`
2022-03-13 18:34:00 +00:00
Jubilee Young
2b1f249ecf Use reduce_sum in as_simd example 2022-03-12 16:43:38 -08:00
Jubilee Young
aabaf8430c Sync portable-simd to rust-lang/portable-simd@72df4c4505 2022-03-12 16:09:37 -08:00
Nikolai Vazquez
6b5acf0d40 Use Self::BITS in log2 implementation 2022-03-12 08:01:35 -05:00
Nikolai Vazquez
1d13de6867 Implement BITS constant for non-zero integers 2022-03-12 08:00:45 -05:00
David Tolnay
af53809c87
Format core and std macro rules, removing needless surrounding blocks 2022-03-11 15:26:51 -08:00
bors
2c6a29af35 Auto merge of #94860 - Dylan-DPC:rollup-n06j8h6, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #87618 (Add missing documentation for std::char types)
 - #94769 (Collapse blanket and auto-trait impls by default)
 - #94798 (`parse_tt` refactorings)
 - #94818 (Rename `IntoFuture::Future` to `IntoFuture::IntoFuture`)
 - #94827 (CTFE/Miri: detect out-of-bounds pointers in offset_from)
 - #94838 (Make float parsing docs more comprehensive)
 - #94839 (Suggest using double colon when a struct field type include single colon)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-11 21:44:06 +00:00
Dylan DPC
ad513548ce
Rollup merge of #94838 - antonok-edm:float-parse-docs, r=Dylan-DPC
Make float parsing docs more comprehensive

I was working on some code with some specialized restrictions on float parsing. I noticed the doc comments for `f32::from_str` and `f64::from_str` were missing several cases of valid inputs that are otherwise difficult to discover without looking at source code.

I'm not sure if the doc comments were initially intended to contain a comprehensive description of valid inputs, but I figured it's useful to include these extra cases for reference.
2022-03-11 20:29:46 +01:00
Dylan DPC
fedf70acb1
Rollup merge of #94818 - yoshuawuyts:into-future-associated-type, r=joshtriplett
Rename `IntoFuture::Future` to `IntoFuture::IntoFuture`

Ref: https://github.com/rust-lang/rust/issues/67644#issuecomment-1051401459

This renames `IntoFuture::Future` to `IntoFuture::IntoFuture`. This adds the `Into*` prefix to the associated type, similar to the [`IntoIterator::IntoIter`](https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#associatedtype.IntoIter) associated type. It's my mistake we didn't do so in the first place. This fixes that and brings the two closer together. Thanks!

### References
__`IntoIterator` trait def__
```rust
pub trait IntoIterator {
    type Item;
    type IntoIter: Iterator<Item = Self::Item>;
    fn into_iter(self) -> Self::IntoIter;
}
```
__`IntoFuture` trait def__
```rust
pub trait IntoFuture {
    type Output;
    type IntoFuture: Future<Output = Self::Output>; // Prior to this PR: `type Future:`
    fn into_future(self) -> Self::IntoFuture;
}
```

cc/ `@eholk` `@rust-lang/wg-async`
2022-03-11 20:29:45 +01:00
Dylan DPC
85056107fa
Rollup merge of #87618 - GuillaumeGomez:std-char-types-doc, r=jyn514,camelid
Add missing documentation for std::char types
2022-03-11 20:29:42 +01:00
bors
335ffbfa54 Auto merge of #94472 - JmPotato:use_maybeuninit_for_vecdeque, r=m-ou-se
Use MaybeUninit in VecDeque to remove the undefined behavior of slice

Signed-off-by: JmPotato <ghzpotato@gmail.com>

Ref https://github.com/rust-lang/rust/issues/74189. Adjust the code to follow the [doc.rust-lang.org/reference/behavior-considered-undefined.html](https://doc.rust-lang.org/reference/behavior-considered-undefined.html).

* Change the return type of `buffer_as_slice` from `&[T]` to `&[MaybeUninit<T>]`.
* Add some corresponding safety comments.

Benchmark results:

master 8d6f527530

```rust
test collections::vec_deque::tests::bench_pop_back_100       ... bench:          47 ns/iter (+/- 1)
test collections::vec_deque::tests::bench_pop_front_100      ... bench:          50 ns/iter (+/- 4)
test collections::vec_deque::tests::bench_push_back_100      ... bench:          69 ns/iter (+/- 10)
test collections::vec_deque::tests::bench_push_front_100     ... bench:          72 ns/iter (+/- 6)
test collections::vec_deque::tests::bench_retain_half_10000  ... bench:     145,891 ns/iter (+/- 7,975)
test collections::vec_deque::tests::bench_retain_odd_10000   ... bench:     141,647 ns/iter (+/- 3,711)
test collections::vec_deque::tests::bench_retain_whole_10000 ... bench:     120,132 ns/iter (+/- 4,078)
```

This PR

```rust
test collections::vec_deque::tests::bench_pop_back_100       ... bench:          48 ns/iter (+/- 2)
test collections::vec_deque::tests::bench_pop_front_100      ... bench:          51 ns/iter (+/- 3)
test collections::vec_deque::tests::bench_push_back_100      ... bench:          73 ns/iter (+/- 2)
test collections::vec_deque::tests::bench_push_front_100     ... bench:          73 ns/iter (+/- 2)
test collections::vec_deque::tests::bench_retain_half_10000  ... bench:     131,796 ns/iter (+/- 5,440)
test collections::vec_deque::tests::bench_retain_odd_10000   ... bench:     137,563 ns/iter (+/- 3,349)
test collections::vec_deque::tests::bench_retain_whole_10000 ... bench:     128,815 ns/iter (+/- 3,289)
```
2022-03-11 19:23:55 +00:00
Dylan DPC
fb3d126458
Rollup merge of #94842 - tspiteri:there-is-no-try, r=Dylan-DPC
Remove unnecessary try_opt for operations that cannot fail

As indicated in the added comments, some operation cannot overflow, so using `try_opt!` for them is unnecessary.
2022-03-11 13:38:39 +01:00
Dylan DPC
cdd6d39ecc
Rollup merge of #94776 - martingms:optimize-escape-default, r=nnethercote
Optimize ascii::escape_default

`ascii::escape_default` showed up as a hot function when compiling `deunicode-1.3.1` in `@nnethercote's` [analysis](https://hackmd.io/mxdn4U58Su-UQXwzOHpHag) of `@lqd's` [rustc-benchmarking-data](https://github.com/lqd/rustc-benchmarking-data).
After taking a look at the generated assembly it looked like a LUT-based approach could be faster for `hexify()`-ing ascii characters, so that's what this PR implements

The patch looks like it provides about a 1-2% improvement in instructions for that particular crate. This should definitely be verified with a perf run as I'm still getting used to the `rustc-perf` tooling and might easily have made an error!
2022-03-11 13:38:37 +01:00
Dylan DPC
7189fceab7
Rollup merge of #93283 - m1guelperez:master, r=Mark-Simulacrum
Fix for localized windows editions in testcase fn read_link() Issue#93211

This PR aims to fix the issue with localized windows versions that do not necessarily have the folder "Documents and settings" in English.

The idea was provided by `@the8472.` We check if the "CI" environment variable is set, then we always check for the "Documents and Settings"-folder, otherwise we check if the folder exists on the local machine, and if not we skip this assert.

Resoles #93211.
2022-03-11 13:38:36 +01:00
Antonio Yang
14daf47e0a Show ignore message in console and json output 2022-03-11 07:15:27 -05:00
Trevor Spiteri
ed10356d52 remove unnecessary try_opt for operations that cannot fail 2022-03-11 11:07:45 +01:00
Anton Lazarev
4c17217f99
make float parsing docs more comprehensive 2022-03-10 22:26:30 -08:00
Dylan DPC
f97a1c6909
Rollup merge of #94826 - allgoewer:fix-retain-documentation, r=yaahc
Improve doc wording for retain on some collections

I found the documentation wording on the various retain methods on many collections to be unusual.
I tried to invert the relation by switching `such that` with `for which` .
2022-03-11 03:32:06 +01:00
Dylan DPC
6d66020594
Rollup merge of #94765 - m-ou-se:is-some-and, r=Dylan-DPC
Rename is_{some,ok,err}_with to is_{some,ok,err}_and.

This renames `is_{some,ok,err}_with` to `is_{some,ok,err}_and`. This was discussed on the [tracking issue](https://github.com/rust-lang/rust/issues/93050).
2022-03-11 03:32:04 +01:00
Dylan DPC
ab851653a5
Rollup merge of #94356 - Thomasdezeeuw:stabilize_unix_socket_creation, r=dtolnay
Rename unix::net::SocketAddr::from_path to from_pathname and stabilize it

Stabilizes `unix_socket_creation`.

Closes https://github.com/rust-lang/rust/issues/93423
r? `@m-ou-se`
2022-03-11 03:32:03 +01:00
Dylan DPC
d58c69ae96
Rollup merge of #93293 - nvzqz:nonzero-min-max, r=joshtriplett
Implement `MIN`/`MAX` constants for non-zero integers

This adds the associated [`MIN`](https://doc.rust-lang.org/stable/std/primitive.usize.html#associatedconstant.MIN)/[`MAX`](https://doc.rust-lang.org/stable/std/primitive.usize.html#associatedconstant.MAX) constants to `NonZero{U,I}{8,16,32,64,128,size}`, requested in #89065.

This reimplements #89077 due that PR being stagnant for 4 months. I am fine with closing this in favor of that one if the author revisits it. If so, I'd like to see that PR have the docs link to the `$Int`'s constants.
2022-03-11 03:32:02 +01:00
Maik Allgöwer
229e01d11f Improve doc wording for retain on some collections 2022-03-11 00:29:43 +01:00
Nikolai Vazquez
ecb7927050 Move note about 0 gap to signed integers
Was accidentally placed on unsigned integers, where it is not relevant.
2022-03-10 17:52:48 -05:00
Dylan DPC
3979e150cc
Rollup merge of #94790 - RalfJung:portable-simd-miri, r=Dylan-DPC
enable portable-simd doctests in Miri

With https://github.com/rust-lang/miri/pull/2013 we shouldn't need to disable these tests any more. :)
2022-03-10 23:13:01 +01:00
Dylan DPC
5a7f09d9a3
Rollup merge of #93950 - T-O-R-U-S:use-modern-formatting-for-format!-macros, r=Mark-Simulacrum
Use modern formatting for format! macros

This updates the standard library's documentation to use the new format_args syntax.
The documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).

`eprintln!("{}", e)` becomes `eprintln!("{e}")`, but `eprintln!("{}", e.kind())` remains untouched.
2022-03-10 23:12:57 +01:00
Maybe Waffle
ecf46d1074 Add Atomic*::get_mut_slice
Just as `get_mut` is the inverse of `from_mut`, `get_mut_slice` is the
inverse of `from_mut_slice`.
2022-03-11 00:31:19 +04:00
Yoshua Wuyts
3f2cb6eba1 Rename IntoFuture::Future to IntoFuture::IntoFuture 2022-03-10 20:51:52 +01:00
Matthias Krüger
af35dc2a95
Rollup merge of #94805 - oli-obk:drop_box, r=pnkfelix
Revert accidental stabilization

fixes #94804
2022-03-10 19:00:11 +01:00
Matthias Krüger
f1a677789a
Rollup merge of #94644 - m-ou-se:scoped-threads-drop-soundness, r=joshtriplett
Fix soundness issue in scoped threads.

This was discovered in https://github.com/rust-lang/rust/pull/94559#discussion_r820116323

The `scope()` function returns when all threads are finished, but I accidentally considered a thread 'finished' before dropping their panic payload or ignored return value.

So if a thread returned (or panics with) something that in its `Drop` implementation still uses borrowed stuff, it goes wrong.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=2a1f19ac4676cdabe43e24e536ff9358
2022-03-10 19:00:07 +01:00
Matthias Krüger
b5127202b2
Rollup merge of #94587 - JKAnderson409:issue-90107-fix, r=scottmcm
Document new recommended use of `FromIterator::from_iter`

#90107
Most of the added prose was paraphrased from the links provided in the issue. The suggested `VecDeque` example seemed to make the point well enough so I just used that.
2022-03-10 19:00:06 +01:00
T-O-R-U-S
72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00
Oli Scherer
5f7ca55df6 Revert accidental stabilization 2022-03-10 14:36:51 +00:00
Martin Gammelsæter
c62ab422d0 Inline <EscapeDefault as Iterator>::next 2022-03-10 15:35:22 +01:00
Matthias Krüger
e7281d08de
Rollup merge of #94746 - notriddle:notriddle/method-rustc-on-unimplemented, r=davidtwco
diagnostics: use rustc_on_unimplemented to recommend `[].iter()`

To make this work, the `#[rustc_on_unimplemented]` data needs to be used to
report method resolution errors, which is most of what this commit does.

Fixes #94581
2022-03-10 12:20:53 +01:00
Matthias Krüger
fe034cb43b
Rollup merge of #94657 - fee1-dead:const_slice_index, r=oli-obk
Constify `Index{,Mut}` for `[T]`, `str`, and `[T; N]`

Several panic functions were rewired (via `const_eval_select`) to simpler implementations that do not require formatting for compile-time usage.

r? ```@oli-obk```
2022-03-10 12:20:52 +01:00
Matthias Krüger
313a668234
Rollup merge of #94635 - jhpratt:merge-deprecated-attrs, r=davidtwco
Merge `#[deprecated]` and `#[rustc_deprecated]`

The first commit makes "reason" an alias for "note" in `#[rustc_deprecated]`, while still prohibiting it in `#[deprecated]`.

The second commit changes "suggestion" to not just be a feature of `#[rustc_deprecated]`. This is placed behind the new `deprecated_suggestion` feature. This needs a tracking issue; let me know if this PR will be approved and I can create one.

The third commit is what permits `#[deprecated]` to be used when `#![feature(staged_api)]` is enabled. This isn't yet used in stdlib (only tests), as it would require duplicating all deprecation attributes until a bootstrap occurs. I intend to submit a follow-up PR that replaces all uses and removes the remaining `#[rustc_deprecated]` code after the next bootstrap.

`@rustbot` label +T-libs-api +C-feature-request +A-attributes +S-waiting-on-review
2022-03-10 12:20:51 +01:00
Scott McMurray
7ef74bc8b9 Let try_collect take advantage of try_fold overrides
Without this change it's going through `&mut impl Iterator`, which handles `?Sized` and thus currently can't forward generics.

Here's the test added, to see that it fails before this PR (once a new enough nightly is out): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=462f2896f2fed2c238ee63ca1a7e7c56
2022-03-10 00:16:06 -08:00
JmPotato
2f18fa801b Use MaybeUninit in VecDeque to remove the undefined behavior of slice
Signed-off-by: JmPotato <ghzpotato@gmail.com>
2022-03-10 14:14:25 +08:00
Ralf Jung
29d979fb3c enable portable-simd doctests in Miri 2022-03-09 19:31:25 -05:00
Matthias Krüger
06944d9e49
Rollup merge of #94768 - fortanix:raoul/fix_close_read_wakes_up_test_sgx_platform, r=dtolnay
Ignore `close_read_wakes_up` test on SGX platform

PR #94714 enabled the `close_read_wakes_up` test for all platforms. This is incorrect. This test should be ignored at least for the SGX platform.

cc: ``@mzohreva`` ``@jethrogb``
2022-03-09 23:14:15 +01:00
Matthias Krüger
9e90f8d39b
Rollup merge of #94763 - m-ou-se:scoped-threads-lifetime-docs, r=Mark-Simulacrum
Add documentation about lifetimes to thread::scope.

This resolves the last unresolved question of https://github.com/rust-lang/rust/issues/93203

This was brought up in https://github.com/rust-lang/rust/pull/94559#discussion_r820872694

r? `````@Mark-Simulacrum`````
2022-03-09 23:14:14 +01:00
Matthias Krüger
d5c05fcc8a
Rollup merge of #93057 - frengor:iter_collect_into, r=m-ou-se
Add Iterator::collect_into

This PR adds `Iterator::collect_into` as proposed by ``@cormacrelf`` in #48597 (see https://github.com/rust-lang/rust/pull/48597#issuecomment-842083688).
Followup of #92982.

This adds the following method to the Iterator trait:

```rust
fn collect_into<E: Extend<Self::Item>>(self, collection: &mut E) -> &mut E
```
2022-03-09 23:14:11 +01:00
Matthias Krüger
2567d0f883
Rollup merge of #92541 - asquared31415:from-docs, r=m-ou-se
Mention intent of `From` trait in its docs

This pr is a docs modification to add to the documentation of the `From` trait a note about its intent as a perfect conversion.  This is already stated in the `TryFrom` docs so this is simply adding that information in a more visible way.
2022-03-09 23:14:10 +01:00
Matthias Krüger
c0259626b6
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
Make some `Clone` impls `const`

Tracking issue: #91805
`Clone::clone_from` and some impls (Option, Result) bounded on `~const Drop`.

```rust
// core::clone
impl const Clone for INTEGER
impl const Clone for FLOAT
impl const Clone for bool
impl const Clone for char
impl const Clone for !
impl<T: ?Sized> const Clone for *const T
impl<T: ?Sized> const Clone for *mut T
impl<T: ?Sized> const Clone for &T

// core::option
impl<T> const Clone for Option<T>
where
    T: ~const Clone + ~const Drop

// core::result
impl<T, E> const Clone for Result<T, E>
where
    T: ~const Clone + ~const Drop,
    E: ~const Clone + ~const Drop,

// core::convert
impl const Clone for Infallible

// core::ptr
impl<T: ?Sized> const Clone for NonNull<T>
impl<T: ?Sized> const Clone for Unique<T>
```
2022-03-09 23:14:09 +01:00
Jacob Pratt
5636655d0f
New deprecated_suggestion feature, use in tests 2022-03-09 16:32:47 -05:00
Martin Gammelsæter
7f4f4fc34c Use indexing instead of .get_unchecked() for LUT lookup
Based on @paolobarbolini's tip that the unsafe block was unnecessary in
this case.

Not much left of `hexify()` after this, so seemed clearer to just inline
it.
2022-03-09 22:21:35 +01:00
fren_gor
63eddb3e68
Add tracking issue 2022-03-09 21:12:07 +01:00
Michael Howell
32d7f8145a diagnostics: use rustc_on_unimplemented to recommend [].iter()
To make this work, the `#[rustc_on_unimplemented]` data needs to be used to
report method resolution errors, which is most of what this commit does.

Fixes #94581
2022-03-09 09:52:55 -07:00
Martin Gammelsæter
876142417c Optimize ascii::escape_default by using a digit LUT 2022-03-09 17:10:34 +01:00
Frank King
2c3c891df0 BTreeMap::entry: Avoid allocating if no insertion 2022-03-09 22:29:05 +08:00
Mara Bos
4d56c1563c Add documentation about lifetimes to thread::scope. 2022-03-09 15:20:00 +01:00
Raoul Strackx
491350ce75 Ignore close_read_wakes_up test on SGX platform 2022-03-09 12:28:16 +01:00
Benjamin Lamowski
bc199b5778 add as_raw() method to L4Re's Socket mock
Minimally comply with with #87329 to avoid breaking tests on L4Re.
2022-03-09 11:53:27 +01:00
Benjamin Lamowski
cb013d4802 put L4Re specifics into their own platform
The initial stdlib modifications for L4Re just used the linux specifics
directly because they were reasonably close to L4Re's behavior.
However, this breaks when Linux-specific code relies on code that is
only available for the linux target, such as in #81825.

Put L4Re into its own platform to avoid such breakage in the future.
This uses the Linux-specific code as a starting point, which seems to be
in line with other OSes with a unix-y interface such as Fuchsia.
2022-03-09 11:53:27 +01:00
Benjamin Lamowski
997dc5899a adapt L4Re network interface mock to #87329
Copy the relevant trait implementations from the Unix default.
2022-03-09 11:53:27 +01:00
Benjamin Lamowski
c0dc41f5ff L4Re does not support sanitizing standard streams
L4Re provides limited POSIX support which includes support for
standard I/O streams, and a limited implementation of the standard file
handling API. However, because as a capability based OS it strives to
only make a local view available to each application, there are
currently no standardized special files like /dev/null that could serve
to sanitize closed standard FDs.

For now, skip any attempts to sanitize standard streams until a more
complete POSIX runtime is available.
2022-03-09 11:53:27 +01:00
Benjamin Lamowski
898f379817 drop unused libc imports on L4Re
As a capability-based microkernel OS, L4Re only has incomplete support
for POSIX APIs, in particular it does not implement UIDs and GIDs.
2022-03-09 11:53:27 +01:00
Sebastian Humenda
11b717647e fix return value of LookupHost::port()
[Benjamin Lamowski: Reworded commit message after split commit.]
2022-03-09 11:53:27 +01:00
Sebastian Humenda
7a74d28c38 fix return values in L4Re networking stub
[Benjamin Lamowski: Reworded commit message after split commit.]
2022-03-09 11:53:27 +01:00
Mara Bos
b97d87518d Add soundness test for dropping scoped thread results before joining. 2022-03-09 11:47:53 +01:00
Mara Bos
1c06eb7c1f Remove outdated comment. 2022-03-09 11:47:46 +01:00
Mara Bos
7a481ff8a4 Properly abort when thread result panics on drop. 2022-03-09 11:44:24 +01:00
Mara Bos
5226395d6f Fix soundness issue in scoped threads. 2022-03-09 11:44:24 +01:00
Mara Bos
7c7411fb5d Rename is_{some,ok,err}_with to is_{some,ok,err}_and. 2022-03-09 11:20:36 +01:00
Dylan DPC
28d06bdec9
Rollup merge of #94756 - ChrisDenton:unreachable, r=yaahc
Use `unreachable!` for an unreachable code path

Closes #73212
2022-03-09 06:38:53 +01:00
Dylan DPC
4de06d459f
Rollup merge of #94699 - ssomers:btree_prune_insert, r=Dylan-DPC
BTree: remove dead data needlessly complicating insert

Possibly needless instructions generated

r? rust-lang/libs
r? ``@Amanieu``
cc ``@frank-king``
2022-03-09 06:38:52 +01:00
bors
163c207fc2 Auto merge of #94750 - cuviper:dirent64_min, r=joshtriplett
unix: reduce the size of DirEntry

On platforms where we call `readdir` instead of `readdir_r`, we store
the name as an allocated `CString` for variable length. There's no point
carrying around a full `dirent64` with its fixed-length `d_name` too.
2022-03-09 02:17:58 +00:00
Ralf Jung
28eb06bd98 docs 2022-03-08 20:09:44 -05:00
Chris Denton
57442beb18
Use unreachable! for an unreachable code path 2022-03-09 01:05:47 +00:00
Loïc BRANSTETT
e3ea59ada5 Remove unexpected #[cfg(target_pointer_width = "8")] in tests 2022-03-09 00:30:17 +01:00
Dylan DPC
5629026e90
Rollup merge of #94730 - msabansal:sabansal/b-atomic-mut-ptr, r=Dylan-DPC
Reverted atomic_mut_ptr feature removal causing compilation break

Fixes a regression introduced as part of https://github.com/rust-lang/rust/pull/94546

Std no longer compiles on nightly while using the following commnd:

export RUSTFLAGS='-C target-feature=+atomics,+bulk-memory'
cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std

I can help add tests to avoid future breaks but i couldn't understand the test framework
2022-03-08 22:44:01 +01:00
Dylan DPC
a67b6299b4
Rollup merge of #94724 - cuviper:rmdirall-cstr, r=Dylan-DPC
unix: Avoid name conversions in `remove_dir_all_recursive`

Each recursive call was creating an `OsString` for a `&Path`, only for
it to be turned into a `CString` right away. Instead we can directly
pass `.name_cstr()`, saving two allocations each time.
2022-03-08 22:44:00 +01:00
Dylan DPC
ff54e34463
Rollup merge of #94723 - dtolnay:mustuse, r=Mark-Simulacrum
Add core::hint::must_use

The example code in this documentation is minimized from a real-world situation in the `anyhow` crate where this function would have been valuable.

Having this provided by the standard library is especially useful for proc macros, even more than for macro_rules. That's because proc macro crates aren't allowed to export anything other than macros, so they couldn't make their own `must_use` function for their macro-generated code to call.

<br>

## Rendered documentation

> An identity function that causes an `unused_must_use` warning to be triggered if the given value is not used (returned, stored in a variable, etc) by the caller.
>
> This is primarily intended for use in macro-generated code, in which a [`#[must_use]` attribute][must_use] either on a type or a function would not be convenient.
>
> [must_use]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute
>
> ### Example
>
> ```rust
> #![feature(hint_must_use)]
>
> use core::fmt;
>
> pub struct Error(/* ... */);
>
> #[macro_export]
> macro_rules! make_error {
>     ($($args:expr),*) => {
>         core::hint::must_use({
>             let error = $crate::make_error(core::format_args!($($args),*));
>             error
>         })
>     };
> }
>
> // Implementation detail of make_error! macro.
> #[doc(hidden)]
> pub fn make_error(args: fmt::Arguments<'_>) -> Error {
>     Error(/* ... */)
> }
>
> fn demo() -> Option<Error> {
>     if true {
>         // Oops, meant to write `return Some(make_error!("..."));`
>         Some(make_error!("..."));
>     }
>     None
> }
> ```
>
> In the above example, we'd like an `unused_must_use` lint to apply to the value created by `make_error!`. However, neither `#[must_use]` on a struct nor `#[must_use]` on a function is appropriate here, so the macro expands using `core::hint::must_use` instead.
>
> - We wouldn't want `#[must_use]` on the `struct Error` because that would make the following unproblematic code trigger a warning:
>
>   ```rust
>   fn f(arg: &str) -> Result<(), Error>
>
>   #[test]
>   fn t() {
>       // Assert that `f` returns error if passed an empty string.
>       // A value of type `Error` is unused here but that's not a problem.
>       f("").unwrap_err();
>   }
>   ```
>
> - Using `#[must_use]` on `fn make_error` can't help because the return value *is* used, as the right-hand side of a `let` statement. The `let` statement looks useless but is in fact necessary for ensuring that temporaries within the `format_args` expansion are not kept alive past the creation of the `Error`, as keeping them alive past that point can cause autotrait issues in async code:
>
>   ```rust
>   async fn f() {
>       // Using `let` inside the make_error expansion causes temporaries like
>       // `unsync()` to drop at the semicolon of that `let` statement, which
>       // is prior to the await point. They would otherwise stay around until
>       // the semicolon on *this* statement, which is after the await point,
>       // and the enclosing Future would not implement Send.
>       log(make_error!("look: {:p}", unsync())).await;
>   }
>
>   async fn log(error: Error) {/* ... */}
>
>   // Returns something without a Sync impl.
>   fn unsync() -> *const () {
>       0 as *const ()
>   }
>   ```
2022-03-08 22:43:59 +01:00
Dylan DPC
ee8109d12d
Rollup merge of #94714 - ChrisDenton:win-close_read_wakes_up, r=Mark-Simulacrum
Enable `close_read_wakes_up` test on Windows

I wonder if we could/should try enabling this again? It was closed by #38867 due to #31657. I've tried running this test (along with other tests) on my machine a number of times and haven't seen this fail yet,

Caveat: the worst that can happen is this succeeds initially but then causes random hangs in CI. This is not a great failure mode and would be a reason not to do this.

If this does work out, closes #39006

r? `@Mark-Simulacrum`
2022-03-08 22:43:57 +01:00
Josh Stone
e8b9ba84be unix: reduce the size of DirEntry
On platforms where we call `readdir` instead of `readdir_r`, we store
the name as an allocated `CString` for variable length. There's no point
carrying around a full `dirent64` with its fixed-length `d_name` too.
2022-03-08 13:36:01 -08:00
Ralf Jung
2a2b212ea3 remove_dir_all: use fallback implementation on Miri 2022-03-08 16:26:10 -05:00
David Tolnay
b2473e988f
Add core::hint::must_use 2022-03-08 10:58:03 -08:00
Matthias Krüger
a077e44c14
Rollup merge of #94712 - kckeiks:remove-rwlock-read-error-assumption, r=Mark-Simulacrum
promot debug_assert to assert

Fixes #94705
2022-03-08 11:04:55 +01:00
Matthias Krüger
aec535f805
Rollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, r=Mark-Simulacrum
Remove argument from closure in thread::Scope::spawn.

This implements ```@danielhenrymantilla's``` [suggestion](https://github.com/rust-lang/rust/issues/93203#issuecomment-1040798286) for improving the scoped threads interface.

Summary:

The `Scope` type gets an extra lifetime argument, which represents basically its own lifetime that will be used in `&'scope Scope<'scope, 'env>`:

```diff
- pub struct Scope<'env> { .. };
+ pub struct Scope<'scope, 'env: 'scope> { .. }

  pub fn scope<'env, F, T>(f: F) -> T
  where
-     F: FnOnce(&Scope<'env>) -> T;
+     F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T;
```

This simplifies the `spawn` function, which now no longer passes an argument to the closure you give it, and now uses the `'scope` lifetime for everything:

```diff
-     pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
+     pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
      where
-         F: FnOnce(&Scope<'env>) -> T + Send + 'env,
+         F: FnOnce() -> T + Send + 'scope,
-         T: Send + 'env;
+         T: Send + 'scope;
```

The only difference the user will notice, is that their closure now takes no arguments anymore, even when spawning threads from spawned threads:

```diff
  thread::scope(|s| {
-     s.spawn(|_| {
+     s.spawn(|| {
          ...
      });
-     s.spawn(|s| {
+     s.spawn(|| {
          ...
-         s.spawn(|_| ...);
+         s.spawn(|| ...);
      });
  });
```

<details><summary>And, as a bonus, errors get <em>slightly</em> better because now any lifetime issues point to the outermost <code>s</code> (since there is only one <code>s</code>), rather than the innermost <code>s</code>, making it clear that the lifetime lasts for the entire <code>thread::scope</code>.

</summary>

```diff
  error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
   --> src/main.rs:9:21
    |
- 7 |         s.spawn(|s| {
-   |                  - has type `&Scope<'1>`
+ 6 |     thread::scope(|s| {
+   |                    - lifetime `'1` appears in the type of `s`
  9 |             s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
    |                     ^^                  - `a` is borrowed here
    |                     |
    |                     may outlive borrowed value `a`
    |
  note: function requires argument type to outlive `'1`
   --> src/main.rs:9:13
    |
  9 |             s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword
    |
  9 |             s.spawn(move || println!("{:?}", a)); // might run after `a` is dropped
    |                     ++++
"
```
</details>

The downside is that the signature of `scope` and `Scope` gets slightly more complex, but in most cases the user wouldn't need to write those, as they just use the argument provided by `thread::scope` without having to name its type.

Another downside is that this does not work nicely in Rust 2015 and Rust 2018, since in those editions, `s` would be captured by reference and not by copy. In those editions, the user would need to use `move ||` to capture `s` by copy. (Which is what the compiler suggests in the error.)
2022-03-08 11:04:51 +01:00
Matthias Krüger
e22331ce02
Rollup merge of #92385 - clarfonthey:const_option, r=fee1-dead
Add Result::{ok, err, and, or, unwrap_or} as const

Already opened tracking issue #92384.

I don't think that this should actually cause any issues as long as the constness is unstable, but we may want to double-check that this doesn't get interpreted as a weird `Drop` bound even for non-const usages.
2022-03-08 11:04:50 +01:00
Miguel Perez
b795ae5280 Fix for issue #93283 2022-03-08 10:16:18 +01:00
Sandeep Bansal
d8e75bc1b7 Reverted atomic-mut-ptr feature removal causing compilation break 2022-03-07 23:41:52 -08:00
Josh Stone
ef3e33bd16 unix: Avoid name conversions in remove_dir_all_recursive
Each recursive call was creating an `OsString` for a `&Path`, only for
it to be turned into a `CString` right away. Instead we can directly
pass `.name_cstr()`, saving two allocations each time.
2022-03-07 18:51:53 -08:00
Chris Denton
24ec0f223d
Enable close_read_wakes_up on Windows 2022-03-07 22:35:17 +00:00
Mara Bos
a3d269e91c
Use f instead of || f().
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2022-03-07 22:14:02 +00:00
Fausto
776be7e73e promot debug_assert to assert 2022-03-07 15:48:35 -05:00
Matthias Krüger
9d7166c66f
Rollup merge of #93827 - eholk:stabilize-const_fn-features, r=wesleywiser
Stabilize const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait

# Stabilization Report

This PR serves as a request for stabilization for three const evaluation features:

1. `const_fn_fn_ptr_basics`
2. `const_fn_trait_bound`
3. `const_impl_trait`

These are being stabilized together because they are relatively minor and related updates to existing functionality.

## `const_fn_fn_ptr_basics`

Allows creating, passing, and casting function pointers in a `const fn`.

The following is an example of what is now allowed:

```rust
const fn get_function() -> fn() {
    fn foo() {
        println!("Hello, World!");
    }

    foo
}
```

Casts between function pointer types are allowed, as well as transmuting from integers:

```rust
const fn get_function() -> fn() {
    unsafe {
        std::mem::transmute(0x1234usize)
    }
}
```

However, casting from a function pointer to an integer is not allowed:

```rust
const fn fn_to_usize(f: fn()) -> usize {
    f as usize  //~ pointers cannot be cast to integers during const eval
}
```

Calling function pointers is also not allowed.

```rust
const fn call_fn_ptr(f: fn()) {
    f() //~ function pointers are not allowed in const fn
}
```

### Test Coverage

The following tests include code that exercises this feature:

- `src/test/ui/consts/issue-37550.rs`
- `src/test/ui/consts/issue-46553.rs`
- `src/test/ui/consts/issue-56164.rs`
- `src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs`
- `src/test/ui/consts/min_const_fn/cast_fn.rs`
- `src/test/ui/consts/min_const_fn/cmp_fn_pointers.rs`

## `const_fn_trait_bound`

Allows trait bounds in `const fn`. Additionally, this feature allows creating and passing `dyn Trait` objects.

Examples such as the following are allowed by this feature:

```rust
const fn do_thing<T: Foo>(_x: &T) {
    // ...
}
```

Previously only `Sized` was allowed as a trait bound.

There is no way to call methods from the trait because trait methods cannot currently be marked as const. Allowing trait bounds in const functions does allow the const function to use the trait's associated types and constants.

This feature also allowes `dyn Trait` types. These work equivalently to non-const code. Similar to other pointers in const code, the value of a `dyn Trait` pointer cannot be observed.

Note that due to https://github.com/rust-lang/rust/issues/90912, it was already possible to do the example above as follows:

```rust
const fn do_thing<T>(_x: &T) where (T,): Foo {
    // ...
}
```

### Test Coverage

The following tests include code that exercises `const_fn_trait_bound`:

- `src/test/ui/consts/const-fn.rs`
- `src/test/ui/consts/issue-88071.rs`
- `src/test/ui/consts/min_const_fn/min_const_fn.rs`
- `src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs`
- `src/test/ui/nll/issue-55825-const-fn.rs`
- Many of the tests in `src/test/ui/rfc-2632-const-trait-impl/` also exercise this feature.

## `const_impl_trait`

Allows argument and return position `impl Trait` in a `const fn`, such as in the following example:

```rust
const fn do_thing(x: impl Foo) -> impl Foo {
    x
}
```

Similar to generic parameters and function pointers, this allows the creation of such opaque types, but not doing anything with them beyond accessing associated types and constants.

### Test Coverage

The following tests exercise this feature:

- `src/test/ui/type-alias-impl-trait/issue-53096.rs`
- `src/test/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs`

## Documentation

These features are documented along with the other const evaluation features in the Rust Reference at https://doc.rust-lang.org/stable/reference/const_eval.html.

There is a PR that updates this documentation to reflect the capabilities enabled by these features at https://github.com/rust-lang/reference/pull/1166.

Tracking issues: #57563, #63997, #93706
2022-03-07 18:39:02 +01:00
Matthias Krüger
1ca8d0bf8c
Rollup merge of #93350 - gburgessiv:master, r=Mark-Simulacrum
libunwind: readd link attrs to _Unwind_Backtrace

It seems the removal of these in 1c07096a45 was unintended; readding them fixes the build.

fixes rust-lang/rust#93349

r? `@alexcrichton`
2022-03-07 18:39:02 +01:00
Eric Holk
8700b45b67 Stabilize const_impl_trait as well 2022-03-07 08:47:18 -08:00
Eric Holk
7723506d13 Stabilize const_fn_fn_ptr_basics and const_fn_trait_bound 2022-03-07 08:47:15 -08:00
Guillaume Gomez
5b5649fd73 Add missing documentation for std::char types 2022-03-07 13:59:10 +01:00
Stein Somers
36bb53d497 BTree: remove dead data needlessly complicating insert 2022-03-07 13:57:56 +01:00
bors
2631aeef82 Auto merge of #94272 - tavianator:readdir-reclen-for-real, r=cuviper
fs: Don't dereference a pointer to a too-small allocation

ptr::addr_of!((*ptr).field) still requires ptr to point to an
appropriate allocation for its type.  Since the pointer returned by
readdir() can be smaller than sizeof(struct dirent), we need to entirely
avoid dereferencing it as that type.

Link: https://github.com/rust-lang/miri/pull/1981#issuecomment-1048278492
Link: https://github.com/rust-lang/rust/pull/93459#discussion_r795089971
2022-03-07 04:48:23 +00:00
Matthias Krüger
e8f38a03b5
Rollup merge of #94671 - csmoe:pin-typo, r=m-ou-se
fix pin doc typo

r? `@m-ou-se`
2022-03-06 19:08:38 +01:00
csmoe
bf089331b4 fix pin doc typo 2022-03-06 21:40:30 +08:00
fee1-dead
8ea3f236dc
Rollup merge of #94649 - ChrisDenton:unix-absolute-fix, r=Dylan-DPC
Unix path::absolute: Fix leading "." component

Testing leading `.` and `..` components were missing from the unix tests.

This PR adds them and fixes the leading `.` case. It also fixes the test cases so that they do an exact comparison.

This problem reported by ``@axetroy``
2022-03-06 22:35:31 +11:00
Deadbeef
4654a91001
Constify slice index for strings 2022-03-06 17:28:50 +11:00
Gentoli
62a65945b7
doc: Iterator::partition use partial type hints 2022-03-05 19:40:40 -05:00
bors
c274e4969f Auto merge of #94648 - RalfJung:rollup-4iorcrd, r=RalfJung
Rollup of 4 pull requests

Successful merges:

 - #94630 (Update note about tier 2 docs.)
 - #94633 (Suggest removing a semicolon after derive attributes)
 - #94642 (Fix source code pages scroll)
 - #94645 (do not attempt to open cgroup files under Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-05 19:53:45 +00:00
Chris Denton
3009eec10d
Use as_os_str to compare exact paths 2022-03-05 18:15:58 +00:00
Chris Denton
27f6d2c7f6
Relax tests for Windows dos device names
Windows 11 no longer turn paths ending with dos device names into device paths.

E.g. `C:\path\to\COM1.txt` used to get turned into `\\.\COM1`. Whereas now the path is left as is.
2022-03-05 18:14:34 +00:00
Chris Denton
0421af9a46
Use as_os_str to compare exact paths 2022-03-05 17:58:08 +00:00
Chris Denton
e8b7371a23
Unix path::absolute: Fix leading "." component
Testing leading `.` and `..` components were missing from the unix tests.
2022-03-05 17:57:12 +00:00
Ralf Jung
51b4ea2ba1 do not attempt to open cgroup files under Miri 2022-03-05 11:23:25 -05:00
Mara Bos
3b9e214c40 Small fixes in thread local code. 2022-03-05 11:39:03 +01:00
Mara Bos
c68c384b88 Update documentation in thread/local.rs. 2022-03-05 11:39:03 +01:00
Mara Bos
36c904594e Add debug asserts in thread local cell set methods. 2022-03-05 11:39:03 +01:00
Mara Bos
93c409d6e2 Add tracking issue number for local_key_cell_methods. 2022-03-05 11:39:03 +01:00
Mara Bos
88a693c4f4 Rename LocalKey's with_{ref,mut} to with_borrow{,_mut}. 2022-03-05 11:39:03 +01:00
Mara Bos
52ce11996b Implement RFC 3184 - thread local cell methods. 2022-03-05 11:39:03 +01:00
bors
86067bb461 Auto merge of #94546 - JmPotato:std-features-cleanup, r=m-ou-se
Clean up the std library's #![feature]s

Signed-off-by: JmPotato <ghzpotato@gmail.com>

This is part of https://github.com/rust-lang/rust/issues/87766.

r? `@m-ou-se`
2022-03-05 07:26:54 +00:00
Dylan DPC
a3fe63e9fe
Rollup merge of #94620 - pierwill:partialord-constistency, r=yaahc
Edit docs on consistency of `PartialOrd` and `PartialEq`

Use ordered list to make the information about implementations more readable.
2022-03-05 04:46:38 +01:00
Dylan DPC
3e1e9b4866
Rollup merge of #94446 - rusticstuff:remove_dir_all-illumos-fix, r=cuviper
UNIX `remove_dir_all()`: Try recursing first on the slow path

This only affects the _slow_ code path - if there is no `dirent.d_type` or if it is `DT_UNKNOWN`.

POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory is allowed to succeed:
> The _path_ argument shall not name a directory unless the process has appropriate privileges and the implementation supports using _unlink()_ on directories.

This however can cause dangling inodes requiring an fsck e.g. on Illumos UFS, so we have to avoid that in the common case. We now just try to recurse into it first and unlink() if we can't open it as a directory.

The other two commits integrate the Macos x86-64 implementation reducing redundancy. Split into two commits for better reviewing.

Fixes #94335.
2022-03-05 04:46:37 +01:00
JmPotato
9b952b7d3a Clean up the std library's #![feature]s
Signed-off-by: JmPotato <ghzpotato@gmail.com>
2022-03-05 11:17:43 +08:00
bors
69f11fff33 Auto merge of #94628 - Dylan-DPC:rollup-v2slupe, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #94362 (Add well known values to `--check-cfg` implementation)
 - #94577 (only disable SIMD for doctests in Miri (not for the stdlib build itself))
 - #94595 (Fix invalid `unresolved imports` errors for a single-segment import)
 - #94596 (Delay bug in expr adjustment when check_expr is called multiple times)
 - #94618 (Don't round stack size up for created threads in Windows)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-05 00:15:54 +00:00
Dylan DPC
629e7aa718
Rollup merge of #94618 - lewisclark:remove-stack-size-rounding, r=yaahc
Don't round stack size up for created threads in Windows

Fixes #94454

Windows does the rounding itself, so there isn't a need to explicity do the rounding beforehand, as mentioned by ```@ChrisDenton``` in #94454

> The operating system rounds up the specified size to the nearest multiple of the system's allocation granularity (typically 64 KB). To retrieve the allocation granularity of the current system, use the [GetSystemInfo](https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo) function.

https://docs.microsoft.com/en-us/windows/win32/procthread/thread-stack-size
2022-03-04 22:58:37 +01:00
Dylan DPC
18a07a78a5
Rollup merge of #94577 - RalfJung:simd-miri, r=scottmcm
only disable SIMD for doctests in Miri (not for the stdlib build itself)

Also we can enable library/core/tests/simd.rs now, Miri supports enough SIMD for that.
2022-03-04 22:58:34 +01:00
bors
5a7e4c6b5a Auto merge of #94298 - Urgau:rustbuild-check-cfg, r=Mark-Simulacrum
Enable conditional compilation checking on the Rust codebase

This pull-request enable conditional compilation checking on every rust project build by the `bootstrap` tool.

To be more specific, this PR only enable well known names checking + extra names (bootstrap, parallel_compiler, ...).

r? `@Mark-Simulacrum`
2022-03-04 21:52:34 +00:00
pierwill
f0257b1b4c Edit docs on consistency of PartialOrd and PartialEq
Use ordered list to make the information about implementations more readable.
2022-03-04 13:31:32 -06:00
Lewis Clark
6843dd5013 Don't round stack size up for created threads 2022-03-04 18:04:43 +00:00
Matthias Krüger
ee3a2c7a8c
Rollup merge of #94549 - m-ou-se:thread-is-finished, r=yaahc
Rename JoinHandle::is_running to is_finished.

This is renaming `is_running` to `is_finished` as discussed on the tracking issue here: https://github.com/rust-lang/rust/issues/90470#issuecomment-1050188499

Taking some of the docs suggestions from https://github.com/rust-lang/rust/pull/94033
2022-03-04 17:31:06 +01:00
Matthias Krüger
904c6ca95c
Rollup merge of #94236 - reez12g:add_track_caller_87707, r=yaahc
Add #[track_caller] to track callers when initializing poisoned Once

This PR is for this Issue.
https://github.com/rust-lang/rust/issues/87707

With this fix, we expect to be able to track the caller when poisoned Once is initialized.
2022-03-04 17:31:04 +01:00
Jeff
b363f13069 Add suggested changes to the docs 2022-03-04 09:48:51 -05:00
Jeff
5f34c04de6 Make use statement visible 2022-03-04 09:45:18 -05:00
Dan Gohman
7ddf41c7b1 Remove redundant code for handling NULL handles on Windows.
Before calling `CreateProcessW`, stdio handles are passed through
`stdio::get_handle`, which already converts NULL to
`INVALID_HANDLE_VALUE`, so we don't need extra checks for NULL after
that point.
2022-03-04 05:09:40 -08:00
Dan Gohman
7dd32469e5 Fix a compilation error. 2022-03-04 05:09:40 -08:00
Dan Gohman
ee02f01ea6 Consistently present absent stdio handles on Windows as NULL handles.
This addresses #90964 by making the std API consistent about presenting
absent stdio handles on Windows as NULL handles. Stdio handles may be
absent due to `#![windows_subsystem = "windows"]`, due to the console
being detached, or due to a child process having been launched from a
parent where stdio handles are absent.

Specifically, this fixes the case of child processes of parents with absent
stdio, which previously ended up with `stdin().as_raw_handle()` returning
`INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an
unrelated valid handle value. With this patch, `stdin().as_raw_handle()`
now returns null in these situation, which is consistent with what it
does in the parent process.

And, document this in the "Windows Portability Considerations" sections of
the relevant documentation.
2022-03-04 05:09:38 -08:00
Hans Kratz
735f60c34f Integrate macos x86-64 remove_dir_all() impl. Step 2: readd 2022-03-04 13:47:50 +01:00
Hans Kratz
41b4423cdf Integrate macos x86-64 remove_dir_all() impl. Step 1: remove 2022-03-04 13:47:36 +01:00
Hans Kratz
e427333071 remove_dir_all(): try recursing first instead of trying to unlink()
This only affects the `slow` code path, if there is no `dirent.d_type` or if
the type is `DT_UNKNOWN`.

POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory can
succeed:
> "The _path_ argument shall not name a directory unless the process has
> appropriate privileges and the implementation supports using _unlink()_ on
> directories."
This however can cause orphaned directories requiring an fsck e.g. on Illumos
UFS, so we have to avoid that in the common case. We now just try to recurse
into it first and unlink() if we can't open it as a directory.
2022-03-04 13:33:35 +01:00
Mara Bos
9099353ea8
Use '_ for irrelevant lifetimes in Debug impl.
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-03-04 10:41:39 +00:00
Loïc BRANSTETT
a93c7abc69 Add #![allow(unexpected_cfgs)] in preparation of global --check-cfg 2022-03-04 11:34:51 +01:00
reez12g
bca67fe02f Add #[track_caller] to track callers when initializing poisoned Once 2022-03-03 22:41:27 -05:00
Dylan DPC
308efafc77
Rollup merge of #94572 - sunfishcode:sunfishcode/handle-or, r=joshtriplett
Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.

Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced
as part of [I/O safety] in a few functions in the Windows FFI bindings.

This factors out an `unsafe` block and two `unsafe` function calls in the
Windows implementation code.

And, it helps test `HandleOrNull` and `HandleOrInvalid`, and indeed, it
turned up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`,
as it's used inside of `HandleOrNull` and `HandleOrInvalid` which are also
`#[repr(transparent)]`.

r? ```@joshtriplett```

[I/O safety]: https://github.com/rust-lang/rust/issues/87074
2022-03-04 02:06:42 +01:00
Dylan DPC
cdfb39ef07
Rollup merge of #93965 - Mark-Simulacrum:owned-stdio, r=dtolnay
Make regular stdio lock() return 'static handles

This also deletes the unstable API surface area previously added to expose this
functionality on new methods rather than built into the current set.

Closes #86845 (tracking issue for unstable API needed without this)

r? ``````@dtolnay`````` to kick off T-libs-api FCP
2022-03-04 02:06:39 +01:00
Dylan DPC
4c70200476
Rollup merge of #88805 - krhancoc:master, r=dtolnay
Clarification of default socket flags

This PR outlines the decision to disable inheritance of socket objects when possible to child processes in the documentation.
2022-03-04 02:06:37 +01:00
Jeff
c956fe5cea Document new recommended use of method 2022-03-03 19:45:53 -05:00
Ralf Jung
50e7450bac only disable SIMD for doctests in Miri (not for the stdlib build itself) 2022-03-03 15:11:06 -05:00
Ralf Jung
e9149b6773 Miri can run this test now 2022-03-03 14:54:18 -05:00
Ralf Jung
d233570fab fix a warning when building core tests with cfg(miri) 2022-03-03 14:54:18 -05:00
Dan Gohman
35606490ab Use HandleOrNull and HandleOrInvalid in the Windows FFI bindings.
Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced
as part of [I/O safety] in a few functions in the Windows FFI bindings.

This factors out an `unsafe` block and two `unsafe` function calls in the
Windows implementation code.

And, it helps test `HandleOrNull` and `HandleOrInvalid`, which indeed turned
up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`, as it's
used inside of `HandleOrNull` and `HandleOrInvalid` which are also
`#[repr(transparent)]`.

[I/O safety]: https://github.com/rust-lang/rust/issues/87074
2022-03-03 11:20:49 -08:00
Matthias Krüger
40c146cebd
Rollup merge of #94551 - darnuria:doc-map-backstick, r=dtolnay
Doc: Fix use of quote instead of backstick in Adapter::map.

A little commit to fix documentation rendering and semantics in https://doc.rust-lang.org/std/iter/struct.Map.html#notes-about-side-effects `"` where used around an expression instead \`.

Screenshot on doc.rust-lang.org:
![2022-03-03 11-21-43_backstick](https://user-images.githubusercontent.com/2827553/156546536-569b7692-7ac4-4388-8e93-c1628ddc6a0f.png)

Looking forward: Maybe reworking the doc to use assert_eq like the upper paragraph:
```
let v: Vec<i32> = vec![1, 2, 3].into_iter().map(|x| x + 1).rev().collect();

assert_eq!(v, [4, 3, 2]);
```
2022-03-03 20:01:47 +01:00
Matthias Krüger
a638f50d8d
Rollup merge of #92697 - the8472:cgroups, r=joshtriplett
Use cgroup quotas for calculating `available_parallelism`

Automated tests for this are possible but would require a bunch of assumptions. It requires root + a recent kernel, systemd and maybe docker. And even then it would need a helper binary since the test has to run in a separate process.

Limitations

* only supports cgroup v2 and assumes it's mounted under `/sys/fs/cgroup`
* procfs must be available
* the quota gets mixed into `sched_getaffinity`, so if the latter doesn't work then quota information gets ignored too

Manually tested via

```
// spawn a new cgroup scope for the current user
$ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS

// quota.rs
#![feature(available_parallelism)]
fn main() {
    println!("{:?}", std:🧵:available_parallelism()); // prints Ok(3)
}
```

strace:

```
sched_getaffinity(3041643, 32, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]) = 32
openat(AT_FDCWD, "/proc/self/cgroup", O_RDONLY|O_CLOEXEC) = 3
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0444, stx_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "0::/system.slice/run-u31477.serv"..., 128) = 36
read(3, "", 92)                         = 0
close(3)                                = 0
statx(AT_FDCWD, "/sys/fs/cgroup/system.slice/run-u31477.service/cgroup.controllers", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0444, stx_size=0, ...}) = 0
openat(AT_FDCWD, "/sys/fs/cgroup/system.slice/run-u31477.service/cpu.max", O_RDONLY|O_CLOEXEC) = 3
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "300000 100000\n", 20)          = 14
read(3, "", 6)                          = 0
close(3)                                = 0
openat(AT_FDCWD, "/sys/fs/cgroup/system.slice/cpu.max", O_RDONLY|O_CLOEXEC) = 3
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "max 100000\n", 20)             = 11
read(3, "", 9)                          = 0
close(3)                                = 0
openat(AT_FDCWD, "/sys/fs/cgroup/cpu.max", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
sched_getaffinity(0, 128, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]) = 40
```

r? ```````@joshtriplett```````
cc ```````@yoshuawuyts```````

Tracking issue and previous discussion: #74479
2022-03-03 20:01:43 +01:00
Mara Bos
6b46a52577 Fix doctests. 2022-03-03 15:23:12 +01:00
Amanieu d'Antras
aa36237e16 Add -Z oom={panic,abort} command-line option 2022-03-03 12:58:38 +00:00
bors
4566094913 Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obk
Miri/CTFE: properly treat overflow in (signed) division/rem as UB

To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.

r? `@oli-obk`
2022-03-03 12:56:24 +00:00
Mara Bos
24fe35a3e1 Remove argument from closure in thread::Scope::spawn. 2022-03-03 13:04:14 +01:00
Mara Bos
af86b55735 Remove unnecessary #![feature]s from doctest. 2022-03-03 12:09:18 +01:00
Mara Bos
c021ac35fa Update test. 2022-03-03 12:09:18 +01:00
Mara Bos
dadf2adbe9 Rename JoinHandle::is_running to is_finished and update docs.
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-03-03 12:09:17 +01:00
Axel Viala
37c1eb0a47 Doc: Fix use of quote instead of backstick in Adapter::map. 2022-03-03 11:25:01 +01:00
Matthias Krüger
6f1730c9e3
Rollup merge of #94534 - bstrie:cffistd, r=Mark-Simulacrum
Re-export (unstable) core::ffi types from std::ffi
2022-03-03 11:02:53 +01:00
Matthias Krüger
afd6f5c478
Rollup merge of #93562 - sunfishcode:sunfishcode/io-docs, r=joshtriplett
Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`.

This change weakens the descriptions of the
`{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that
they *do* express ownership relations to say that they are *typically used*
in ways that express ownership relations. This is needed since, for
example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of
the ownership relationships.

This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`,
adds the requirement that raw handles be not opened with the
`FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle`
comment into the main `FromRawHandle::from_raw_handle` comment.

And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement
`FromRawHandle`, since they are intended for limited use in FFI situations,
and not for generic use, and they have constraints that are stronger than
the those of `FromRawHandle`.

[`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-03-03 11:02:49 +01:00
Dan Gohman
8253cfef7a Remove the comment about FILE_FLAG_OVERLAPPED.
There may eventually be something to say about `FILE_FLAG_OVERLAPPED` here,
however this appears to be independent of the other changes in this PR,
so remove them from this PR so that it can be discussed separately.
2022-03-02 16:25:31 -08:00
Dylan DPC
878a4ff90e
Rollup merge of #94529 - GuillaumeGomez:unused-doc-comments-blocks, r=estebank
Unused doc comments blocks

Fixes #77030.
2022-03-03 01:09:15 +01:00
Dylan DPC
c9dc44be24
Rollup merge of #93663 - sunfishcode:sunfishcode/as-raw-name, r=joshtriplett
Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`.

Also, rename `BorrowedHandle::borrow_raw_handle` and
`BorrowedSocket::borrow_raw_socket` to `BorrowedHandle::borrow_raw` and
`BorrowedSocket::borrow_raw`.

This is just a minor rename to reduce redundancy in the user code calling
these functions, and to eliminate an inessential difference between
`BorrowedFd` code and `BorrowedHandle`/`BorrowedSocket` code.

While here, add a simple test exercising `BorrowedFd::borrow_raw_fd`.

r? ``````@joshtriplett``````
2022-03-03 01:09:10 +01:00
Dylan DPC
bc1a8905d6
Rollup merge of #93354 - sunfishcode:sunfishcode/document-borrowedfd-toowned, r=joshtriplett
Add documentation about `BorrowedFd::to_owned`.

Following up on #88564, this adds documentation explaining why
`BorrowedFd::to_owned` returns another `BorrowedFd` rather than an
`OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`.

r? `````@joshtriplett`````
2022-03-03 01:09:09 +01:00
The 8472
e18abbf2ac update available_parallelism docs since cgroups and sched_getaffinity are now taken into account 2022-03-03 00:43:46 +01:00
The 8472
af6d2ed245 hardcode /sys/fs/cgroup instead of doing a lookup via mountinfo
this avoids parsing mountinfo which can be huge on some systems and
something might be emulating cgroup fs for sandboxing reasons which means
it wouldn't show up as mountpoint

additionally the new implementation operates on a single pathbuffer, reducing allocations
2022-03-03 00:43:46 +01:00
The 8472
bac5523ea0 Use cgroup quotas for calculating available_parallelism
Manually tested via


```
// spawn a new cgroup scope for the current user
$ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS


// quota.rs
#![feature(available_parallelism)]
fn main() {
    println!("{:?}", std:🧵:available_parallelism()); // prints Ok(3)
}
```


Caveats

* cgroup v1 is ignored
* funky mountpoints (containing spaces, newlines or control chars) for cgroupfs will not be handled correctly since that would require unescaping /proc/self/mountinfo
  The escaping behavior of procfs seems to be undocumented. systemd and docker default to `/sys/fs/cgroup` so it should be fine for most systems.
* quota will be ignored when `sched_getaffinity` doesn't work
* assumes procfs is mounted under `/proc` and cgroupfs mounted and readable somewhere in the directory tree
2022-03-03 00:43:45 +01:00
Dan Gohman
af642bb466 Fix a broken doc link on Windows. 2022-03-02 12:39:36 -08:00
Guillaume Gomez
6f0eb2a4e1 Update stdarch submodule 2022-03-02 20:06:46 +01:00
Guillaume Gomez
628fbdf9b7 Fix unused_doc_comments lint errors 2022-03-02 20:06:35 +01:00
bstrie
9aed829fe6 Re-export core::ffi types from std::ffi 2022-03-02 13:52:31 -05:00
Sébastien Marie
fa8e1bedd3 merge the char signess list of archs with freebsd as it is the same 2022-03-02 12:12:28 +00:00
Sébastien Marie
3768f0b813 update char signess for openbsd
adds more archs for openbsd: arm, mips64, powerpc, powerpc64, and riscv64.
2022-03-02 10:33:50 +00:00
Nixon Enraght-Moony
3f04c85e24 Mark uint::wrapping_next_power_of_two as #[inline]
This brings it in line with `next_power_of_two` and
`checked_next_power_of_two`
2022-03-02 09:15:14 +00:00
Ralf Jung
6739299d18 Miri/CTFE: properly treat overflow in (signed) division/rem as UB 2022-03-01 20:39:51 -05:00
Josh Triplett
75c3e9c23f Temporarily make CStr not a link in the c_char docs
When CStr moves to core with an alias in std, this can link to
`crate::ffi::CStr`. However, linking in the reverse direction (from core
to std) requires a relative path, and that path can't work from both
core::ffi and std::os::raw (different number of `../` traversals
required).
2022-03-01 17:36:40 -08:00
Josh Triplett
335c9609c6 Provide C FFI types via core::ffi, not just in std
The ability to interoperate with C code via FFI is not limited to crates
using std; this allows using these types without std.

The existing types in `std::os::raw` become type aliases for the ones in
`core::ffi`. This uses type aliases rather than re-exports, to allow the
std types to remain stable while the core types are unstable.

This also moves the currently unstable `NonZero_` variants and
`c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving
them unstable.
2022-03-01 17:16:05 -08:00
Josh Triplett
0f505c6377 Add a copy of cfg_if to core's internal_macros.rs
core can't depend on external crates the way std can. Rather than revert
usage of cfg_if, add a copy of it to core. This does not export our
copy, even unstably; such a change could occur in a later commit.
2022-03-01 16:24:10 -08:00
Dylan DPC
4001d98019
Rollup merge of #94452 - workingjubilee:sync-simd-bitmasks, r=workingjubilee
Sync portable-simd for bitmasks &c.

In the ideal case, where everything works easily and nothing has to be rearranged, it is as simple as:
- `git subtree pull -P library/portable-simd https://github.com/rust-lang/portable-simd - ${branch}`
- write the commit message
- `python x.py test --stage 1` to make sure it runs
- `git push` to your PR-to-rustc branch

If anything borks up this flow, you can fix it with sufficient git wizardry but you are usually better off going back to the source, fixing it, and starting over, before you open the PR.

r? `@calebzulawski`
2022-03-01 03:41:53 +01:00
Dylan DPC
5bd119da84
Rollup merge of #94384 - cuviper:atomic-slice, r=dtolnay
Add Atomic*::from_mut_slice

Tracking issue #76314 for `from_mut` has a question about the possibility of `from_mut_slice`, and I found a real case for it. A user in the forum had a parallelism problem that could be solved by open-indexing updates to a vector of atomics, but they didn't want to affect the other code using that vector. Using `from_mut_slice`, they could borrow that data as atomics just long enough for their parallel loop.

ref: https://users.rust-lang.org/t/sharing-vector-with-rayon-par-iter-correctly/72022
2022-03-01 03:41:51 +01:00
Dylan DPC
06d47a414b
Rollup merge of #94094 - chrisnc:tcp-nodelay-windows-bool, r=dtolnay
use BOOL for TCP_NODELAY setsockopt value on Windows

This issue was found by the Wine project and mitigated there [^1].

Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY
[^2]. Windows itself is forgiving and will accept any positive optlen and
interpret the first byte of *optval as the value, so this bug does not
affect Windows itself, but does affect systems implementing Windows'
interface more strictly, such as Wine. Wine was previously passing this
through to the host's setsockopt, where, e.g., Linux requires that
optlen be correct for the chosen option, and TCP_NODELAY expects an int.

[^1]: d6ea38f32d
[^2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-03-01 03:41:50 +01:00
Matthias Krüger
9d23c320e4
Rollup merge of #92399 - Veeupup:fix_vec_typo, r=Dylan-DPC
fix typo in btree/vec doc: Self -> self

this pr fixes #92345
the documentation refers to the object the method is called for, not the type, so it should be using the lower case self.
2022-02-28 20:05:13 +01:00
Jubilee Young
4de99e187c Sync rust-lang/portable-simd@5f49d4c843 2022-02-28 10:17:40 -08:00
Matthias Krüger
770ee32b34
Rollup merge of #89793 - ibraheemdev:from_ptr_range, r=m-ou-se
Add `slice::{from_ptr_range, from_mut_ptr_range} `

Adds `slice::{from_ptr_range, from_mut_ptr_range}` as counterparts to `slice::{as_ptr_range, as_mut_ptr_range}`.
2022-02-28 12:57:44 +01:00
Ibraheem Ahmed
aac0281d30 add slice::{from_ptr_range, from_mut_ptr_range} 2022-02-27 16:53:26 -05:00
bors
6a70556616 Auto merge of #94412 - scottmcm:cfg-out-miri-from-swap, r=oli-obk
For MIRI, cfg out the swap vectorization logic from 94212

Because of #69488 the swap logic from #94212 doesn't currently work in MIRI.

Copying in smaller pieces is probably much worse for its performance anyway, so it'd probably rather just use the simple path regardless.

Part of #94371, though another PR will be needed for the CTFE aspect.

r? `@oli-obk`
cc `@RalfJung`
2022-02-27 17:42:48 +00:00
Thomas de Zeeuw
a84e77bebf Stabilize unix_socket_creation 2022-02-27 15:34:48 +01:00
Scott McMurray
b582bd388f For MIRI, cfg out the swap logic from 94212 2022-02-26 18:57:15 -08:00
bors
035a717ee8 Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrum
Make TLS __getit #[inline(always)] on non-Windows

This may improve perf, and/or stop `externs` perf benchmarks from being flaky.

r? `@ghost`
2022-02-27 01:23:48 +00:00
bors
12b71ed4c5 Auto merge of #94385 - matthiaskrgr:rollup-4pwegqk, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #93603 (Populate liveness facts when calling `get_body_with_borrowck_facts` without `-Z polonius`)
 - #93870 (Fix switch on discriminant detection in a presence of coverage counters)
 - #94355 (Add one more case to avoid ICE)
 - #94363 (Remove needless borrows from core::fmt)
 - #94377 (`check_used` should only look at actual `used` attributes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-26 02:09:29 +00:00
Matthias Krüger
0c9d5e3c77
Rollup merge of #94363 - aDotInTheVoid:fmt-needless-borrows, r=scottmcm
Remove needless borrows from core::fmt
2022-02-26 00:49:23 +01:00
bors
d973b358c6 Auto merge of #94342 - ibraheemdev:swap-regression, r=Dylan-DPC
Revert implementation of `slice::swap`

Due to the perf regressions noticed here, possible due to inlining? https://github.com/rust-lang/rust/pull/88540#issuecomment-944344343

r? `@kennytm`
2022-02-25 23:47:00 +00:00
Josh Stone
d3d2a279fe Add Atomic*::from_mut_slice 2022-02-25 15:30:29 -08:00
Erik Desjardins
2d6d30f4a8 Make TLS __getit #[inline(always)] on non-Windows
This may improve perf.
2022-02-25 15:21:27 -05:00
Erik Desjardins
4194d7537e Add #[inline] to trivial AsRef impls
These appeared uninlined in some perf runs, but they're trivial.
2022-02-25 15:18:16 -05:00
bors
d981633ed6 Auto merge of #94290 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini
Bump bootstrap to 1.60

This bumps the bootstrap compiler to 1.60 and cleans up cfgs and Span's rustc_pass_by_value (enabled by the bootstrap bump).
2022-02-25 18:34:02 +00:00
Nixon Enraght-Moony
6b68882e45 Remove needless borrows from core::fmt 2022-02-25 16:06:23 +00:00
Mark Rousskov
3c62f2f635 Re-add track_caller to panic_no_unwind in bootstrap
This function was updated in a recent PR (92911) to be called without the caller
information passed in, but the function signature itself was not altered with
cfg_attr at the time.
2022-02-25 08:00:53 -05:00
Mark Rousskov
22c3a71de1 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
Thomas de Zeeuw
7f44b3a118 Rename unix::net::SocketAddr::from_path to from_pathname
Matching SocketAddr::as_pathname.
2022-02-25 13:05:49 +01:00
Jethro Beekman
355d503ace Fix SGX docs build 2022-02-25 12:12:37 +01:00
Matthias Krüger
e5bd222c6b
Rollup merge of #94184 - ssomers:btree_tests, r=Dylan-DPC
BTree: simplify test code

Mostly, use `from` & `from_iter`.
2022-02-25 07:30:49 +01:00
Matthias Krüger
6ec5b056b0
Rollup merge of #92714 - yanganto:ignore-message, r=Mark-Simulacrum
Provide ignore message in the result of test

Provide ignore the message in the result of the test.

This PR does not need RFC, because it is about the presentation of the report of `cargo test`.

However, the following document listed here helps you to know about PR.

- [RFC](https://github.com/rust-lang/rfcs/pull/3217)
- [Rendered](https://github.com/yanganto/rfcs/blob/ignore-test-message/text/0000-ignore-test-message.md)
- [Previous discussion on IRLO](https://internals.rust-lang.org/t/pre-rfc-provide-ignore-message-when-the-test-ignored/15904)

If there is something improper, please let me know.
Thanks.
2022-02-25 07:30:47 +01:00
Ibraheem Ahmed
072d35dc2d revert implementation of slice::swap 2022-02-24 19:32:54 -05:00
Antonio Yang
bb3b5574cd Include ignore message in libtest output
As an example:

    #[test]
    #[ignore = "not yet implemented"]
    fn test_ignored() {
        ...
    }

Will now render as:

    running 2 tests
    test tests::test_ignored ... ignored, not yet implemented

    test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s
2022-02-24 17:36:36 -05:00
Dylan DPC
7fb55b4c3a
Rollup merge of #94212 - scottmcm:swapper, r=dtolnay
Stop manually SIMDing in `swap_nonoverlapping`

Like I previously did for `reverse` (#90821), this leaves it to LLVM to pick how to vectorize it, since it can know better the chunk size to use, compared to the "32 bytes always" approach we currently have.

A variety of codegen tests are included to confirm that the various cases are still being vectorized.

It does still need logic to type-erase in some cases, though, as while LLVM is now smart enough to vectorize over slices of things like `[u8; 4]`, it fails to do so over slices of `[u8; 3]`.

As a bonus, this change also means one no longer gets the spurious `memcpy`(s?) at the end up swapping a slice of `__m256`s: <https://rust.godbolt.org/z/joofr4v8Y>

<details>

<summary>ASM for this example</summary>

## Before (from godbolt)

note the `push`/`pop`s and `memcpy`

```x86
swap_m256_slice:
        push    r15
        push    r14
        push    r13
        push    r12
        push    rbx
        sub     rsp, 32
        cmp     rsi, rcx
        jne     .LBB0_6
        mov     r14, rsi
        shl     r14, 5
        je      .LBB0_6
        mov     r15, rdx
        mov     rbx, rdi
        xor     eax, eax
.LBB0_3:
        mov     rcx, rax
        vmovaps ymm0, ymmword ptr [rbx + rax]
        vmovaps ymm1, ymmword ptr [r15 + rax]
        vmovaps ymmword ptr [rbx + rax], ymm1
        vmovaps ymmword ptr [r15 + rax], ymm0
        add     rax, 32
        add     rcx, 64
        cmp     rcx, r14
        jbe     .LBB0_3
        sub     r14, rax
        jbe     .LBB0_6
        add     rbx, rax
        add     r15, rax
        mov     r12, rsp
        mov     r13, qword ptr [rip + memcpy@GOTPCREL]
        mov     rdi, r12
        mov     rsi, rbx
        mov     rdx, r14
        vzeroupper
        call    r13
        mov     rdi, rbx
        mov     rsi, r15
        mov     rdx, r14
        call    r13
        mov     rdi, r15
        mov     rsi, r12
        mov     rdx, r14
        call    r13
.LBB0_6:
        add     rsp, 32
        pop     rbx
        pop     r12
        pop     r13
        pop     r14
        pop     r15
        vzeroupper
        ret
```

## After (from my machine)

Note no `rsp` manipulation, sorry for different ASM syntax

```x86
swap_m256_slice:
	cmpq	%r9, %rdx
	jne	.LBB1_6
	testq	%rdx, %rdx
	je	.LBB1_6
	cmpq	$1, %rdx
	jne	.LBB1_7
	xorl	%r10d, %r10d
	jmp	.LBB1_4
.LBB1_7:
	movq	%rdx, %r9
	andq	$-2, %r9
	movl	$32, %eax
	xorl	%r10d, %r10d
	.p2align	4, 0x90
.LBB1_8:
	vmovaps	-32(%rcx,%rax), %ymm0
	vmovaps	-32(%r8,%rax), %ymm1
	vmovaps	%ymm1, -32(%rcx,%rax)
	vmovaps	%ymm0, -32(%r8,%rax)
	vmovaps	(%rcx,%rax), %ymm0
	vmovaps	(%r8,%rax), %ymm1
	vmovaps	%ymm1, (%rcx,%rax)
	vmovaps	%ymm0, (%r8,%rax)
	addq	$2, %r10
	addq	$64, %rax
	cmpq	%r10, %r9
	jne	.LBB1_8
.LBB1_4:
	testb	$1, %dl
	je	.LBB1_6
	shlq	$5, %r10
	vmovaps	(%rcx,%r10), %ymm0
	vmovaps	(%r8,%r10), %ymm1
	vmovaps	%ymm1, (%rcx,%r10)
	vmovaps	%ymm0, (%r8,%r10)
.LBB1_6:
	vzeroupper
	retq
```

</details>

This does all its copying operations as either the original type or as `MaybeUninit`s, so as far as I know there should be no potential abstract machine issues with reading padding bytes as integers.

<details>

<summary>Perf is essentially unchanged</summary>

Though perhaps with more target features this would help more, if it could pick bigger chunks

## Before

```
running 10 tests
test slice::swap_with_slice_4x_usize_30                            ... bench:         894 ns/iter (+/- 11)
test slice::swap_with_slice_4x_usize_3000                          ... bench:      99,476 ns/iter (+/- 2,784)
test slice::swap_with_slice_5x_usize_30                            ... bench:       1,257 ns/iter (+/- 7)
test slice::swap_with_slice_5x_usize_3000                          ... bench:     139,922 ns/iter (+/- 959)
test slice::swap_with_slice_rgb_30                                 ... bench:         328 ns/iter (+/- 27)
test slice::swap_with_slice_rgb_3000                               ... bench:      16,215 ns/iter (+/- 176)
test slice::swap_with_slice_u8_30                                  ... bench:         312 ns/iter (+/- 9)
test slice::swap_with_slice_u8_3000                                ... bench:       5,401 ns/iter (+/- 123)
test slice::swap_with_slice_usize_30                               ... bench:         368 ns/iter (+/- 3)
test slice::swap_with_slice_usize_3000                             ... bench:      28,472 ns/iter (+/- 3,913)
```

## After

```
running 10 tests
test slice::swap_with_slice_4x_usize_30                            ... bench:         868 ns/iter (+/- 36)
test slice::swap_with_slice_4x_usize_3000                          ... bench:      99,642 ns/iter (+/- 1,507)
test slice::swap_with_slice_5x_usize_30                            ... bench:       1,194 ns/iter (+/- 11)
test slice::swap_with_slice_5x_usize_3000                          ... bench:     139,761 ns/iter (+/- 5,018)
test slice::swap_with_slice_rgb_30                                 ... bench:         324 ns/iter (+/- 6)
test slice::swap_with_slice_rgb_3000                               ... bench:      15,962 ns/iter (+/- 287)
test slice::swap_with_slice_u8_30                                  ... bench:         281 ns/iter (+/- 5)
test slice::swap_with_slice_u8_3000                                ... bench:       5,324 ns/iter (+/- 40)
test slice::swap_with_slice_usize_30                               ... bench:         275 ns/iter (+/- 5)
test slice::swap_with_slice_usize_3000                             ... bench:      28,277 ns/iter (+/- 277)
```

</detail>
2022-02-24 21:42:14 +01:00
Matthias Krüger
bdcdd1b122
Rollup merge of #94300 - WaffleLapkin:patch-4, r=scottmcm
Fix a typo in documentation of `array::IntoIter::new_unchecked`

🌸
2022-02-24 07:48:12 +01:00
Matthias Krüger
f3433d1b59
Rollup merge of #94283 - hellow554:stable_flow_control, r=Dylan-DPC
remove feature gate in control_flow examples

Stabilization was done in https://github.com/rust-lang/rust/pull/91091, but the two examples weren't updated accordingly.

Probably too late to put it into stable, but it should be in the next release :)
2022-02-24 07:48:08 +01:00
Matthias Krüger
aa0b7ac0bf
Rollup merge of #94273 - Dylan-DPC:doc/errorkind, r=joshtriplett
add matching doc to errorkind

Rework of #90706
2022-02-24 07:48:07 +01:00
Dylan DPC
3f4b039e33 word wrpa 2022-02-24 00:37:06 +01:00
Dylan DPC
eb795c24fb word wrpa 2022-02-24 00:30:07 +01:00
Dylan DPC
c46d9f6c89
Update library/std/src/io/error.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-23 23:18:42 +01:00
Waffle Maybe
715262f151
Fix a typo in documentation of array::IntoIter::new_unchecked 2022-02-23 21:10:04 +03:00
Tavian Barnes
478cf8b3a4 fs: Don't dereference a pointer to a too-small allocation
ptr::addr_of!((*ptr).field) still requires ptr to point to an
appropriate allocation for its type.  Since the pointer returned by
readdir() can be smaller than sizeof(struct dirent), we need to entirely
avoid dereferencing it as that type.

Link: https://github.com/rust-lang/miri/pull/1981#issuecomment-1048278492
Link: https://github.com/rust-lang/rust/pull/93459#discussion_r795089971
2022-02-23 09:51:02 -05:00
Matthias Krüger
efe6a979b5
Rollup merge of #94264 - NyantasticUwU:patch-1, r=yaahc
Fix typo.

Yeah just a typo (probably some breaking changes in here be careful) :)
2022-02-23 12:26:45 +01:00
Matthias Krüger
40afbdd148
Rollup merge of #94240 - compiler-errors:pathbuf-display, r=lcnr
Suggest calling .display() on `PathBuf` too

Fixes #94210
2022-02-23 12:26:42 +01:00
Matthias Krüger
0c676a8a84
Rollup merge of #94128 - mqy:master, r=Dylan-DPC
rustdoc: several minor fixes

``@rustbot`` label A-docs
2022-02-23 12:26:40 +01:00
Marcel Hellwig
c403424203 remove feature gate in control_flow examples 2022-02-23 10:42:46 +01:00
Dylan DPC
057dc09eae add some more summary from pr discussion 2022-02-23 03:29:02 +01:00
Dylan DPC
37cbc7d120 add some more summary from pr discussion 2022-02-23 03:28:27 +01:00
Dylan DPC
4905814249 add matching to errorkind 2022-02-23 03:22:23 +01:00
bors
5bd1ec3283 Auto merge of #83706 - a1phyr:fix_vec_layout_calculation, r=JohnTitor
Fix a layout possible miscalculation in `alloc::RawVec`

A layout miscalculation could happen in `RawVec` when used with a type whose size isn't a multiple of its alignment. I don't know if such type can exist in Rust, but the Layout API provides ways to manipulate such types. Anyway, it is better to calculate memory size in a consistent way.
2022-02-22 20:50:38 +00:00
Jane Lusby
7bdad89f95 Stabilize Termination and ExitCode 2022-02-22 12:40:46 -08:00
NyantasticUwU
c61d5923f2
Fix typo.
Yeah just a typo (probably some breaking changes in here be careful) :)
2022-02-22 11:44:45 -06:00
Matthias Krüger
21fb81405e
Rollup merge of #94179 - devnexen:getexecname_directcall, r=kennytm
solarish current_exe using libc call directly
2022-02-22 12:16:30 +01:00
Deadbeef
5941fef292
Constify slice indexing 2022-02-22 12:39:36 +11:00
Michael Goulet
a08809ff7b Suggest calling .display() on PathBuf too 2022-02-21 16:58:12 -08:00
Matthias Krüger
ed3530925e
Rollup merge of #94220 - GuillaumeGomez:miniz-oxide-decl, r=Amanieu
Correctly handle miniz_oxide extern crate declaration

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

Follow-up of https://github.com/rust-lang/rust/pull/94122.

The `miniz_oxide` dependency is optional and therefore should allow be "imported" when it makes sense.

r? `@ivmarkov`
2022-02-21 19:36:55 +01:00
Matthias Krüger
74cb6b77a0
Rollup merge of #94186 - ehuss:pin-stable-1.61, r=m-ou-se
Update pin_static_ref stabilization version.

#93580 slipped into 1.61

cc `@m-ou-se`
2022-02-21 19:36:49 +01:00
Matthias Krüger
12705b4700
Rollup merge of #91192 - r00ster91:futuredocs, r=GuillaumeGomez
Some improvements to the async docs

The goal here is to make the docs overall a little bit more comprehensive and add more links between the things.

One thing that's not working yet is the links to the keywords. Somehow I couldn't get them to work.

r? ````@GuillaumeGomez```` do you know how I could get the keyword links to work?
2022-02-21 19:36:46 +01:00
Guillaume Gomez
910d46fd60 Correctly handle miniz_oxide extern crate declaration 2022-02-21 17:27:55 +01:00
Scott McMurray
8ca47d7ae4 Stop manually SIMDing in swap_nonoverlapping
Like I previously did for `reverse`, this leaves it to LLVM to pick how to vectorize it, since it can know better the chunk size to use, compared to the "32 bytes always" approach we currently have.

It does still need logic to type-erase where appropriate, though, as while LLVM is now smart enough to vectorize over slices of things like `[u8; 4]`, it fails to do so over slices of `[u8; 3]`.

As a bonus, this also means one no longer gets the spurious `memcpy`(s?) at the end up swapping a slice of `__m256`s: <https://rust.godbolt.org/z/joofr4v8Y>
2022-02-21 00:54:02 -08:00
Chris Copeland
b02698c7e6
use BOOL for TCP_NODELAY setsockopt value on Windows
This issue was found by the Wine project and mitigated there [1].

Windows' documented interface for `setsockopt` expects a `BOOL` (a
`typedef` for `int`) for `TCP_NODELAY` [2]. Windows is forgiving and
will accept any positive length and interpret the first byte of
`*option_value` as the value, so this bug does not affect Windows
itself, but does affect systems implementing Windows' interface more
strictly, such as Wine. Wine was previously passing this through to the
host's `setsockopt`, where, e.g., Linux requires that `option_len` be
correct for the chosen option, and `TCP_NODELAY` expects an `int`.

[1]: d6ea38f32d
[2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-02-20 21:27:36 -08:00
Chris Copeland
f2ebd0a11f
Remove assertion on output length for getsockopt.
POSIX allows `getsockopt` to set `*option_len` to a smaller value if
necessary. Windows will set `*option_len` to 1 for boolean options even
when the caller passes a `BOOL` (`int`) with `*option_len` as 4.
2022-02-20 21:27:36 -08:00
Chris Copeland
3eb983ed99
Fix setsockopt and getsockopt parameter names.
Previously `level` was named `opt` and `option_name` was named `val`,
then extra names of `payload` or `slot` were used for the option value.
This change aligns the wrapper parameters with their names in POSIX.
Winsock uses similar but more abbreviated names: `level`, `optname`,
`optval`, `optlen`.
2022-02-20 21:27:22 -08:00
Eric Huss
72a7e731e1 Update pin_static_ref stabilization version. 2022-02-20 06:42:20 -08:00
Stein Somers
7950ebcd8e BTree: simplify test code 2022-02-20 14:43:59 +01:00
David Carlier
f810314bc6 solarish current_exe using libc call directly 2022-02-20 08:53:18 +00:00
bors
25ad89e47b Auto merge of #94174 - matthiaskrgr:rollup-snyrlhy, r=matthiaskrgr
Rollup of 14 pull requests

Successful merges:

 - #93580 (Stabilize pin_static_ref.)
 - #93639 (Release notes for 1.59)
 - #93686 (core: Implement ASCII trim functions on byte slices)
 - #94002 (rustdoc: Avoid duplicating macros in sidebar)
 - #94019 (removing architecture requirements for RustyHermit)
 - #94023 (adapt static-nobundle test to use llvm-nm)
 - #94091 (Fix rustdoc const computed value)
 - #94093 (Fix pretty printing of enums without variants)
 - #94097 (Add module-level docs for `rustc_middle::query`)
 - #94112 (Optimize char_try_from_u32)
 - #94113 (document rustc_middle::mir::Field)
 - #94122 (Fix miniz_oxide types showing up in std docs)
 - #94142 (rustc_typeck: adopt let else in more places)
 - #94146 (Adopt let else in more places)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-20 02:19:41 +00:00
fren_gor
04b3162764
Add collect_into 2022-02-20 01:57:32 +01:00
Matthias Krüger
a69aaf4aee
Rollup merge of #94122 - GuillaumeGomez:miniz-oxide-std, r=notriddle
Fix miniz_oxide types showing up in std docs

Fixes #90526.

Thanks to ```````@camelid,``````` I rediscovered `doc(masked)`, allowing us to prevent `miniz_oxide` type to show up in std docs.

r? ```````@notriddle```````
2022-02-20 00:37:32 +01:00
Matthias Krüger
7cd857dc34
Rollup merge of #94112 - digama0:patch-3, r=scottmcm
Optimize char_try_from_u32

The optimization was proposed by ```````@falk-hueffner``````` in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Micro-optimizing.20char.3A.3Afrom_u32/near/272146171,  and I simplified it a bit and added an explanation of why the optimization is correct. The generated code is 2 instructions shorter and uses 2 registers instead of 4 on x86.
2022-02-20 00:37:30 +01:00
Matthias Krüger
6b69121d0d
Rollup merge of #94019 - hermitcore:target, r=Mark-Simulacrum
removing architecture requirements for RustyHermit

RustHermit and HermitCore is able to run on aarch64 and x86_64. In the future these operating systems will also support RISC-V. Consequently, the dependency to a specific target should be removed.

The build process of `hermit-abi` fails if the architecture isn't supported.
2022-02-20 00:37:25 +01:00
Matthias Krüger
575f6c5cc1
Rollup merge of #93686 - dbrgn:trim-on-byte-slices, r=joshtriplett
core: Implement ASCII trim functions on byte slices

Hi ````````@rust-lang/libs!```````` This is a feature that I wished for when implementing serial protocols with microcontrollers. Often these protocols may contain leading or trailing whitespace, which needs to be removed. Because oftentimes drivers will operate on the byte level, decoding to unicode and checking for unicode whitespace is unnecessary overhead.

This PR adds three new methods to byte slices:

- `trim_ascii_start`
- `trim_ascii_end`
- `trim_ascii`

I did not find any pre-existing discussions about this, which surprises me a bit. Maybe I'm missing something, and this functionality is already possible through other means? There's https://github.com/rust-lang/rfcs/issues/2547 ("Trim methods on slices"), but that has a different purpose.

As per the [std dev guide](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), this is a proposed implementation without any issue / RFC. If this is the wrong process, please let me know. However, I thought discussing code is easier than discussing a mere idea, and hacking on the stdlib was fun.

Tracking issue: https://github.com/rust-lang/rust/issues/94035
2022-02-20 00:37:23 +01:00
Matthias Krüger
7977af5975
Rollup merge of #93580 - m-ou-se:stabilize-pin-static-ref, r=scottmcm
Stabilize pin_static_ref.

FCP finished here: https://github.com/rust-lang/rust/issues/78186#issuecomment-1024987221

Closes #78186
2022-02-20 00:37:21 +01:00
bors
2690468727 Auto merge of #92911 - nbdd0121:unwind, r=Amanieu
Guard against unwinding in cleanup code

Currently the only safe guard we have against double unwind is the panic count (which is local to Rust). When double unwinds indeed happen (e.g. C++ exception + Rust panic, or two C++ exceptions), then the second unwind actually goes through and the first unwind is leaked. This can cause UB. cc rust-lang/project-ffi-unwind#6

E.g. given the following C++ code:
```c++
extern "C" void foo() {
    throw "A";
}

extern "C" void execute(void (*fn)()) {
    try {
        fn();
    } catch(...) {
    }
}
```

This program is well-defined to terminate:
```c++
struct dtor {
    ~dtor() noexcept(false) {
        foo();
    }
};

void a() {
    dtor a;
    dtor b;
}

int main() {
    execute(a);
    return 0;
}
```

But this Rust code doesn't catch the double unwind:
```rust
extern "C-unwind" {
    fn foo();
    fn execute(f: unsafe extern "C-unwind" fn());
}

struct Dtor;

impl Drop for Dtor {
    fn drop(&mut self) {
        unsafe { foo(); }
    }
}

extern "C-unwind" fn a() {
    let _a = Dtor;
    let _b = Dtor;
}

fn main() {
    unsafe { execute(a) };
}
```

To address this issue, this PR adds an unwind edge to an abort block, so that the Rust example aborts. This is similar to how clang guards against double unwind (except clang calls terminate per C++ spec and we abort).

The cost should be very small; it's an additional trap instruction (well, two for now, since we use TrapUnreachable, but that's a different issue) for each function with landing pads; if LLVM gains support to encode "abort/terminate" info directly in LSDA like GCC does, then it'll be free. It's an additional basic block though so compile time may be worse, so I'd like a perf run.

r? `@ghost`
`@rustbot` label: F-c_unwind
2022-02-19 23:25:06 +00:00
r00ster91
297364eb07 Some improvements to the async docs 2022-02-19 17:17:40 +01:00
bors
e08d569360 Auto merge of #94148 - matthiaskrgr:rollup-jgea68f, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92902 (Improve the documentation of drain members)
 - #93658 (Stabilize `#[cfg(panic = "...")]`)
 - #93954 (rustdoc-json: buffer output)
 - #93979 (Add debug assertions to validate NUL terminator in c strings)
 - #93990 (pre #89862 cleanup)
 - #94006 (Use a `Field` in `ConstraintCategory::ClosureUpvar`)
 - #94086 (Fix ScalarInt to char conversion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-19 12:15:10 +00:00
Matthias Krüger
26dd6ac830
Rollup merge of #93979 - SUPERCILEX:debug_check, r=dtolnay
Add debug assertions to validate NUL terminator in c strings

The `unchecked` variants from the stdlib usually perform the check anyway if debug assertions are on (for example, `unwrap_unchecked`). This PR does the same thing for `CStr` and `CString`, validating the correctness for the NUL byte in debug mode.
2022-02-19 06:45:30 +01:00
Matthias Krüger
f19adc7acc
Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplett
Stabilize `#[cfg(panic = "...")]`

[Stabilization PR](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr) for #77443
2022-02-19 06:45:29 +01:00
Matthias Krüger
4fa71ed0f0
Rollup merge of #92902 - ssomers:docter_drain, r=yaahc
Improve the documentation of drain members

hopefully fixes #92765
2022-02-19 06:45:28 +01:00
bors
cb4ee81ef5 Auto merge of #94105 - 5225225:destabilise-entry-insert, r=Mark-Simulacrum
Destabilise entry_insert

See: https://github.com/rust-lang/rust/pull/90345

I didn't revert the rename that was done in that PR, I left it as `entry_insert`.

Additionally, before that PR, `VacantEntry::insert_entry` seemingly had no stability attribute on it? I kept the attribute, just made it an unstable one, same as the one on `Entry`.

There didn't seem to be any mention of this in the RELEASES.md, so I don't think there's anything for me to do other than this?
2022-02-19 05:08:13 +00:00
Stein Somers
a677e60840 Collections: improve the documentation of drain members 2022-02-19 00:55:31 +01:00
Matthias Krüger
724cca6d7f
Rollup merge of #93847 - solid-rs:fix-kmc-solid-fs-ts, r=yaahc
kmc-solid: Use the filesystem thread-safety wrapper

Fixes the thread unsafety of the `std::fs` implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Neither the SOLID filesystem API nor built-in filesystem drivers guarantee thread safety by default. Although this may suffice in general embedded-system use cases, and in fact the API can be used from multiple threads without any problems in many cases, this has been a source of unsoundness in `std::sys::solid::fs`.

This commit updates the implementation to leverage the filesystem thread-safety wrapper (which uses a pluggable synchronization mechanism) to enforce thread safety. This is done by prefixing all paths passed to the filesystem API with `\TS`. (Note that relative paths aren't supported in this platform.)
2022-02-18 23:23:07 +01:00
mqy
997492538b rustdoc: several minor fixes 2022-02-19 03:47:41 +08:00
Guillaume Gomez
b78123cdcf Fix miniz_oxide types showing up in std 2022-02-18 17:31:38 +01:00
Matthias Krüger
f1c918f1f3
Rollup merge of #93613 - crlf0710:rename_to_async_iter, r=yaahc
Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`

Following amendments in https://github.com/rust-lang/rfcs/pull/3208/.

cc #79024
cc ``@yoshuawuyts`` ``@joshtriplett``
2022-02-18 16:23:32 +01:00
Mario Carneiro
7c3ebec0ca
fix 2022-02-17 22:14:54 -08:00
Mario Carneiro
0f14bea448
Optimize char_try_from_u32
The optimization was proposed by @falk-hueffner in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Micro-optimizing.20char.3A.3Afrom_u32/near/272146171,  and I simplified it a bit and added an explanation of why the optimization is correct.
2022-02-17 20:27:53 -08:00
bors
f838a425e3 Auto merge of #94095 - Amanieu:update_stdarch, r=dtolnay
Fix documentation for is_X_feature_detected!

These are now properly documented for all architectures and the
stability attributes in the docs are now correctly displayed.

This addresses this comment by `@ehuss:` https://github.com/rust-lang/rust/pull/90271#issuecomment-1038400916

cc `@adamgemmell`
2022-02-18 04:16:03 +00:00
5225225
319dd150fc Destabilise entry_insert 2022-02-17 22:23:31 +00:00
Matthias Krüger
a4be35e321
Rollup merge of #94041 - a-lafrance:try-collect, r=scottmcm
Add a `try_collect()` helper method to `Iterator`

Implement `Iterator::try_collect()` as a helper around `Iterator::collect()` as discussed [here](https://internals.rust-lang.org/t/idea-fallible-iterator-mapping-with-try-map/15715/5?u=a.lafrance).

First time contributor so definitely open to any feedback about my implementation! Specifically wondering if I should open a tracking issue for the unstable feature I introduced.

As the main participant in the internals discussion: r? `@scottmcm`
2022-02-17 23:01:00 +01:00
Matthias Krüger
09350d2cf0
Rollup merge of #93976 - SUPERCILEX:separator_str, r=yaahc
Add MAIN_SEPARATOR_STR

Currently, if someone needs access to the path separator as a str, they need to go through this mess:

```rust
unsafe {
    std::str::from_utf8_unchecked(slice::from_ref(&(MAIN_SEPARATOR as u8)))
}
```

This PR just re-exports an existing path separator str API.
2022-02-17 23:00:58 +01:00
Danilo Bargen
f7448a77e4 core: Implement trim functions on byte slices
Co-authored-by: Jubilee Young <workingjubilee@gmail.com>
2022-02-17 21:19:42 +01:00
Amanieu d'Antras
2b3fa06994 Fix documentation for is_X_feature_detected!
These are now properly documented for all architectures and the
stability attributes in the docs are now correctly displayed.
2022-02-17 18:17:15 +00:00
Chris Denton
93f627daa5
Keep the path after program_exists succeeds 2022-02-17 13:17:19 +00:00
Chris Denton
d4686c6066
Use verbatim paths for process::Command if necessary 2022-02-17 13:12:49 +00:00
Matthias Krüger
d855121a44
Rollup merge of #93479 - smoelius:master, r=yaahc
Use `optflag` for `--report-time`

Essentially, what is described here:
https://github.com/rust-lang/rust/issues/64888#issuecomment-1008047228

There is one difference. The comment proposes to add a
`--report-time-color` option. This change instead uses libtest's
existing `--color` option for that purpose.
2022-02-17 06:29:59 +01:00
Matthias Krüger
1cc0ae4cbb
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
Add documentation to more `From::from` implementations.

For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy.

Notes on specific cases:
* The new documentation for `From<T> for T` explains that it is not a conversion at all.
* Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion.
* The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set.
* I did not add documentation to conversions of a specific error type to a more general error type.
* I did not add documentation to unstable code.

This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2022-02-17 06:29:57 +01:00
Alex Saveau
80fde23a75
Add MAIN_SEPARATOR_STR
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-16 19:38:12 -08:00
Alex Saveau
897c8d0ab9
Add debug asserts to validate NUL terminator in c strings
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-16 18:34:17 -08:00
bors
930fc4f59d Auto merge of #94040 - Mark-Simulacrum:destabilize-load-store, r=Amanieu
Destabilize cfg(target_has_atomic_load_store = ...)

This was not intended to be stabilized yet.

This keeps the cfg_target_has_atomic feature gate name since compiler-builtins otherwise depends on it and I'd rather not try to manage a bump across a crates.io published repository given the time-sensitivity here (we need to land this quickly to avoid a beta backport).

Closes https://github.com/rust-lang/rust/issues/32976

r? `@Amanieu`
2022-02-17 01:56:40 +00:00
Arthur Lafrance
47d5196a00 Add a try_collect() helper method to Iterator
Tweaked `try_collect()` to accept more `Try` types

Updated feature attribute for tracking issue
2022-02-16 14:26:39 -08:00
bors
2ff7ea4de2 Auto merge of #91182 - ChrisDenton:command-broken-symlink, r=m-ou-se
Maintain broken symlink behaviour for the Windows exe resolver

When the resolver was updated to remove the current directory from the search path (see #87704), care was take to avoid unintentional changes that hadn't been discussed. However, I missed the broken symlink behaviour. This PR fixes that.

**Edit** This turned out to be more important than I first realised. There are some types of application stubs that will redirect to the actual process when run using `CreateProcessW`, but due to the way they're implemented they cannot be opened normally using a `File::open` that follows reparse points. So this doesn't work with our current `exists` and `try_exists` methods.

Fixes #91177
2022-02-16 22:11:22 +00:00
Matthias Krüger
9a42121135
Rollup merge of #93962 - joboet:branchless_slice_ord, r=Mark-Simulacrum
Make [u8]::cmp implementation branchless

The current implementation generates rather ugly assembly code, branching when the common parts are equal. By performing the comparison of the lengths upfront using a subtraction, the assembly gets much prettier: https://godbolt.org/z/4e5fnEKGd.

This will probably not impact speed too much, as the expensive part is in most cases the `memcmp`, but it sure looks better (I'm porting a sorting algorithm currently, and that branch just bothered me).
2022-02-16 18:59:29 +01:00
Mark Rousskov
fc01d2b854 Destabilize cfg(target_has_atomic_load_store = ...)
This was not intended to be stabilized yet.
2022-02-16 10:28:12 -05:00
Matthias Krüger
e1baa3d5b9
Rollup merge of #93949 - glaubitz:m68k-unwind, r=Mark-Simulacrum
Add basic platform support to library/{panic_}unwind for m68k

This PR adds basic platform support for m68k for library/{panic_}unwind for m68k.

Register information for UNWIND_DATA_REG has been extracted from LLVM.
2022-02-15 16:02:35 +01:00
Matthias Krüger
cdfdcfcf18
Rollup merge of #93899 - ssomers:vecdeque_naming, r=m-ou-se
Describe VecDeque with more consistent names

The public documentation of VecDeque starts describing itself as a "queue". In method descriptions, it's ~~never~~ sometimes named queue again, or `VecDeque` (IMO a sometimes useful and often noisy notation) or "deque" or "vector". In examples, `deque`, `v` (hidden in `range_mut`) or `vector`. Here is a subjective attempt at more consistency.
2022-02-15 16:02:34 +01:00
Stefan Lankes
227d106aec remove compiler warnings 2022-02-15 14:03:26 +01:00
Stefan Lankes
1ab5b0bc05 removing architecture requirements for RustyHermit
RustHermit and HermitCore is able to run on aarch64 and x86_64.
In the future these operating systems will also support RISC-V.
Consequently, the dependency to a specific target should be removed.
Building hermit-abi fails if the architecture isn't supported.
2022-02-15 13:57:07 +01:00
joboet
3960ce6ec5
Make [u8]::cmp implementation branchless 2022-02-14 23:16:35 +01:00
Daniel Henry-Mantilla
002f627d38 Add a comment to justify why the pointer field is pub.
Addresses https://github.com/rust-lang/rust/pull/93176/files#r795258110.
2022-02-14 17:35:27 +01:00
Daniel Henry-Mantilla
6df63cc148 Replace def_site-&-privacy implementation with a stability-based one.
Since `decl_macro`s and/or `Span::def_site()` is deemed quite unstable,
no public-facing macro that relies on it can hope to be, itself, stabilized.

We circumvent the issue by no longer relying on field privacy for safety and,
instead, relying on an unstable feature-gate to act as the gate keeper for
non users of the macro (thanks to `allow_internal_unstable`).

This is technically not correct (since a `nightly` user could technically enable
the feature and cause unsoundness with it); or, in other words, this makes the
feature-gate used to gate the access to the field be (technically unsound, and
in practice) `unsafe`. Hence it having `unsafe` in its name.

Back to the macro, we go back to `macro_rules!` / `mixed_site()`-span rules thanks
to declaring the `decl_macro` as `semitransparent`, which is a hack to basically have
`pub macro_rules!`

Co-Authored-By: Mara Bos <m-ou.se@m-ou.se>
2022-02-14 17:27:37 +01:00
Daniel Henry-Mantilla
54e443dceb Improve documentation.
Co-Authored-By: Mara Bos <m-ou.se@m-ou.se>
2022-02-14 17:27:32 +01:00
Daniel Henry-Mantilla
42d69e2793 Write {ui,} tests for pin_macro and pin! 2022-02-14 16:56:37 +01:00
Daniel Henry-Mantilla
ee9cd7bb6a Add a stack-pin!-ning macro to the pin module.
Add a type annotation to improve error messages with type mismatches

Add a link to the temporary-lifetime-extension section of the reference
2022-02-14 16:56:37 +01:00
Chris Denton
9a7a8b9255
Maintain broken symlink behaviour for the Windows exe resolver 2022-02-14 12:50:18 +00:00
Stein Somers
5d5359759d Describe VecDeque with more consistent names 2022-02-14 11:17:27 +01:00
Mark Rousskov
398cccd42e Make default stdio lock() return 'static handles
This also deletes the unstable API surface area previously added to expose this
functionality on new methods rather than built into the current set.
2022-02-13 10:23:16 -05:00
bors
1f4681ad7a Auto merge of #91673 - ChrisDenton:path-absolute, r=Mark-Simulacrum
`std::path::absolute`

Implements #59117 by adding a `std::path::absolute` function that creates an absolute path without reading the filesystem. This is intended to be a drop-in replacement for [`std::fs::canonicalize`](https://doc.rust-lang.org/std/fs/fn.canonicalize.html) in cases where it isn't necessary to resolve symlinks. It can be used on paths that don't exist or where resolving symlinks is unwanted. It can also be used to avoid circumstances where `canonicalize` might otherwise fail.

On Windows this is a wrapper around [`GetFullPathNameW`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew). On Unix it partially implements the POSIX [pathname resolution](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13) specification, stopping just short of actually resolving symlinks.
2022-02-13 12:03:52 +00:00
SaltyKitkat
ee87c80a85
allow const_mut_refs 2022-02-13 16:16:41 +08:00
SaltyKitkat
3c142b0ffe
stabilize const_ptr_offset 2022-02-13 15:26:14 +08:00
bors
1d9c262eea Auto merge of #95274 - jendrikw:slice-must-use, r=Dylan-DPC
add #[must_use] to functions of slice and its iterators.

Continuation of #92853.

Tracking issue: #89692.
2022-03-26 20:17:04 +00:00
bors
1fca19c8ca Auto merge of #95326 - lupd:std-iter-doc, r=Dylan-DPC
Remove mention of `HashMap<K, V>` not offering `iter_mut`

HashMap<K, V> does offer iter_mut. Fixes #94755.

r? rust-lang/libs
`@rustbot` label +A-docs +T-libs
2022-03-26 12:01:58 +00:00
Jendrik
5f88c23c39 add #[must_use] to functions of slice and its iterators. 2022-03-26 10:24:25 +01:00
dlup
15134249f4 Remove mention of HashMap<K, V> not offering iter_mut 2022-03-26 02:05:34 -04:00
est31
8c0e6a8f10 std::process docs: linkify references to output, spawn and status 2022-03-25 14:41:37 +01:00