Commit graph

1452 commits

Author SHA1 Message Date
Christiaan Dirkx
52fa9daa64 Rework wasm::thread to thread_atomics 2021-04-28 15:51:14 +02:00
Yuki Okushi
0e72e0fb7f
Rollup merge of #84624 - r00ster91:patch-5, r=JohnTitor
Make sentence in env::args_os' docs plain and simple

Follow-up to #84551. See https://github.com/rust-lang/rust/pull/84551#discussion_r620728070 on why this makes more sense.
2021-04-28 16:59:09 +09:00
r00ster
1778f30cd8
Make sentence in env::args_os' docs plain and simple 2021-04-27 21:31:04 +02:00
Dylan DPC
e7be5ddc4a
Rollup merge of #84521 - CDirkx:hermit-dedup, r=Mark-Simulacrum
Reuse modules on `hermit`

Reuse the following modules on `hermit`:
- `unix::path` (contents identical)
- `unsupported::io` (contents identical)
- `unsupported::thread_local_key` (contents functionally identical, only changes are the panic error messages)

`@rustbot` label: +T-libs-impl
2021-04-27 19:08:46 +02:00
Mara Bos
6d277c7694
Rollup merge of #84551 - r00ster91:patch-4, r=yaahc
Unify the docs of std::env::{args_os, args} more

I noticed that `args_os` was missing some information and I thought it should mention `args` for when you want more safety just like how `args` mentions `args_os` if you don't want it to panic on invalid Unicode.
2021-04-26 21:06:48 +02:00
Dylan DPC
25508ebe68
Rollup merge of #84541 - KaiJewson:inline-raw, r=m-ou-se
Inline most raw socket, fd and handle conversions

Now that file descriptor types on Unix have niches, it is advantageous for user libraries which provide file descriptor wrappers (e.g. `Socket` from socket2) to store a `File` internally instead of a `RawFd`, so that the niche can be taken advantage of. However, doing so will currently result in worse performance as `IntoRawFd`, `FromRawFd` and `AsRawFd` are not inlined. This change adds `#[inline]` to those methods on std types that wrap file descriptors, handles or sockets.
2021-04-25 23:15:17 +02:00
r00ster
82b6983aca
Change wording 2021-04-25 15:48:24 +02:00
r00ster
22ec96135d
Unify the docs of std::env::{args_os, args} more 2021-04-25 14:45:48 +02:00
bors
06f0adb345 Auto merge of #84216 - RalfJung:black-box, r=Mark-Simulacrum
move core::hint::black_box under its own feature gate

The `black_box` function had its own RFC and is tracked separately from the `test` feature at https://github.com/rust-lang/rust/issues/64102. Let's reflect this in the feature gate.

To avoid breaking all the benchmarks, libtest's `test::black_box` is a wrapping definition, not a reexport -- this means it is still under the `test` feature gate.
2021-04-25 10:35:24 +00:00
Ralf Jung
23d54ad96f move core::hint::black_box under its own feature gate 2021-04-25 11:08:12 +02:00
bors
13a2615883 Auto merge of #84147 - cuviper:array-method-dispatch, r=nikomatsakis,m-ou-se
Cautiously add IntoIterator for arrays by value

Add the attribute described in #84133, `#[rustc_skip_array_during_method_dispatch]`, which effectively hides a trait from method dispatch when the receiver type is an array.

Then cherry-pick `IntoIterator for [T; N]` from #65819 and gate it with that attribute. Arrays can now be used as `IntoIterator` normally, but `array.into_iter()` has edition-dependent behavior, returning `slice::Iter` for 2015 and 2018 editions, or `array::IntoIter` for 2021 and later.

r? `@nikomatsakis`
cc `@LukasKalbertodt` `@rust-lang/libs`
2021-04-25 07:26:49 +00:00
KaiJewson
fbc2aadbfc Inline most raw socket, fd and handle conversions 2021-04-25 07:39:09 +01:00
Josh Stone
f6a90ca168 Ignore array IntoIterator tests in bootstrap 2021-04-24 22:33:51 -07:00
bors
5da10c0121 Auto merge of #84115 - CDirkx:rt, r=m-ou-se
Rework `init` and `cleanup`

This PR reworks the code in `std` that runs before and after `main` and centralizes this code respectively in the functions `init` and `cleanup` in both `sys_common` and `sys`. This makes is easy to see what code is executed during initialization and cleanup on each platform just by looking at e.g. `sys::windows::init`.

Full list of changes:
- new module `rt` in `sys_common` to contain `init` and `cleanup` and the runtime macros.
- `at_exit` and the mechanism to register exit handlers has been completely removed. In practice this was only used for closing sockets on windows and flushing stdout, which have been moved to `cleanup`.
- <s>On windows `alloc` and `net` initialization is now done in `init`, this saves a runtime check in every allocation and network use.</s>
2021-04-25 04:45:39 +00:00
Yuki Okushi
78306f03ef
Rollup merge of #84179 - CDirkx:dont_send_sync, r=m-ou-se
Explicitly implement `!Send` and `!Sync` for `sys::{Args, Env}`

Remove the field `_dont_send_or_sync_me: PhantomData<*mut ()>` in favor of an explicit implementation of `!Send` and `!Sync`.
2021-04-25 01:53:11 +09:00
Christiaan Dirkx
36e9382449 Reuse unix::path and unsupported::{io, thread_local_key} on hermit 2021-04-24 17:32:25 +02:00
Yuki Okushi
ace3bd4f8b
Rollup merge of #84387 - CDirkx:poison, r=m-ou-se
Move `sys_common::poison` to `sync::poison`

`sys_common` should not contain publicly exported types, only platform-independent abstractions on top of `sys`, which `sys_common::poison` is not. There is thus no reason for the module to not live under `sync`.

Part of #84187.
2021-04-24 03:44:09 +09:00
Christiaan Dirkx
dc110af7fc Explicitly implement !Send and !Sync for sys::{Args, Env} 2021-04-23 00:15:35 +02:00
Dylan DPC
d1f5fc6017
Rollup merge of #84413 - CDirkx:args_inner_debug, r=m-ou-se
Remove `sys::args::Args::inner_debug` and use `Debug` instead

This removes the method `sys::args::Args::inner_debug` on all platforms and implements `Debug` for `Args` instead.

I believe this creates a more natural API for the different platforms under `sys`: export a type `Args: Debug + Iterator + ...` vs. `Args: Iterator + ...` and with a method `inner_debug`.
2021-04-22 18:14:43 +02:00
Dylan DPC
aac5125da4
Rollup merge of #84402 - CDirkx:rwlock, r=dtolnay
Move `sys_common::rwlock::StaticRWLock` etc. to `sys::unix::rwlock`

This moves `sys_common::rwlock::StaticRwLock`, `RWLockReadGuard` and `RWLockWriteGuard` to `sys::unix::rwlock`. They are already `#[cfg(unix)]` and don't need to be in `sys_common`.
2021-04-22 18:14:41 +02:00
Christiaan Dirkx
7171fec13f Remove Once from init 2021-04-22 18:00:18 +02:00
Christiaan Dirkx
e1b1081d2f Document that init and cleanup are not guaranteed to run 2021-04-22 18:00:18 +02:00
Christiaan Dirkx
8aeea227da Apply suggestions from review 2021-04-22 18:00:17 +02:00
Christiaan Dirkx
11445c10ab Move most init to sys::init 2021-04-22 18:00:12 +02:00
Christiaan Dirkx
1a6de8450e Remove sys::args::Args::inner_debug and use Debug instead 2021-04-22 11:04:29 +02:00
Christiaan Dirkx
cf470197ad Move all cleanup to sys::cleanup 2021-04-22 10:44:44 +02:00
Christiaan Dirkx
5b30662741 Rework at_exit to cleanup 2021-04-22 10:34:48 +02:00
Christiaan Dirkx
9cabbd0afc Move sys_common::poison to sync::poison 2021-04-22 10:27:21 +02:00
Mara Bos
31b83802a4
Rollup merge of #84212 - CDirkx:void, r=m-ou-se
Replace `Void` in `sys` with never type

This PR replaces several occurrences in `sys` of the type `enum Void {}` with the Rust never type (`!`).
The name `Void` is unfortunate because in other languages (C etc.) it refers to a unit type, not an uninhabited type.

Note that the previous stabilization of the never type was reverted, however all uses here are implementation details and not publicly visible.
2021-04-21 23:06:14 +02:00
Mara Bos
3897ad1128
Rollup merge of #84119 - CDirkx:vxworks, r=m-ou-se
Move `sys::vxworks` code to `sys::unix`

Follow-up to #77666, `sys::vxworks` is almost identical to `sys::unix`, the only differences are the `rand`, `thread_local_dtor`, and `process` implementation. Since `vxworks` is `target_family = unix` anyway, there is no reason for the code not to live inside of `sys::unix` like all the other unix-OSes.

e41f378f82/compiler/rustc_target/src/spec/vxworks_base.rs (L12)

``@rustbot`` label: +T-libs-impl
2021-04-21 23:06:12 +02:00
Mara Bos
a7a7737114
Rollup merge of #84013 - CDirkx:fmt, r=m-ou-se
Replace all `fmt.pad` with `debug_struct`

This replaces any occurrence of:
- `f.pad("X")` with `f.debug_struct("X").finish()`
- `f.pad("X { .. }")` with `f.debug_struct("X").finish_non_exhaustive()`

This is in line with existing formatting code such as
1255053067/library/std/src/sync/mpsc/mod.rs (L1470-L1475)
2021-04-21 23:06:11 +02:00
Christiaan Dirkx
eb9b0f6ab7 Move sys_common::rwlock::StaticRWLock etc. to sys::unix::rwlock 2021-04-21 17:53:00 +02:00
Christiaan Dirkx
aa46f08abd Apply suggestions from code review 2021-04-21 16:06:32 +02:00
Christiaan Dirkx
1fb3256fcb Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
Christiaan Dirkx
d45e1314f3 Change uses of never type 2021-04-20 20:53:07 +02:00
Christiaan Dirkx
389fef3b30 Replace Void with never type 2021-04-20 20:53:07 +02:00
Dylan DPC
761243572e
Rollup merge of #84291 - RalfJung:thread-local-const-init, r=alexcrichton
fix aliasing violations in thread_local_const_init

Fixes https://github.com/rust-lang/rust/pull/83416#discussion_r615364774

r? `@alexcrichton` `@sfackler`
2021-04-19 22:00:09 +02:00
Dylan DPC
fb78dc05e4
Rollup merge of #84256 - tspiteri:pretty-minus-zero, r=workingjubilee
doc: use U+2212 for minus sign in floating-point -0.0 remarks

Also remove plus sign in `-0.0 == +0.0` to make it a valid expression.
2021-04-19 22:00:08 +02:00
Christiaan Dirkx
9bd9cbb28e Fix vxworks compilation errors 2021-04-19 13:29:35 +02:00
Christiaan Dirkx
12120409d5 Move sys::vxworks code to sys::unix 2021-04-19 13:29:22 +02:00
Trevor Spiteri
4c6477026d
Update library/std/src/primitive_docs.rs
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2021-04-19 02:58:38 +02:00
bors
5a4ab26459 Auto merge of #78880 - CDirkx:not_supported, r=joshtriplett
Add `Unsupported` to `std::io::ErrorKind`

I noticed a significant portion of the uses of `ErrorKind::Other` in std is for unsupported operations.
The notion that a specific operation is not available on a target (and will thus never succeed) seems semantically distinct enough from just "an unspecified error occurred", which is why I am proposing to add the variant `Unsupported` to `std::io::ErrorKind`.

**Implementation**:

The following variant will be added to `std::io::ErrorKind`:

```rust
/// This operation is unsupported on this platform.
Unsupported
```
`std::io::ErrorKind::Unsupported` is an error returned when a given operation is not supported on a platform, and will thus never succeed; there is no way for the software to recover. It will be used instead of `Other` where appropriate, e.g. on wasm for file and network operations.

`decode_error_kind` will be updated  to decode operating system errors to `Unsupported`:
- Unix and VxWorks: `libc::ENOSYS`
- Windows: `c::ERROR_CALL_NOT_IMPLEMENTED`
- WASI: `wasi::ERRNO_NOSYS`

**Stability**:
This changes the kind of error returned by some functions on some platforms, which I think is not covered by the stability guarantees of the std? User code could depend on this behavior, expecting `ErrorKind::Other`, however the docs already mention:

> Errors that are `Other` now may move to a different or a new `ErrorKind` variant in the future. It is not recommended to match an error against `Other` and to expect any additional characteristics, e.g., a specific `Error::raw_os_error` return value.

The most recent variant added to `ErrorKind` was `UnexpectedEof` in `1.6.0` (almost 5 years ago), but `ErrorKind` is marked as `#[non_exhaustive]` and the docs warn about exhaustively matching on it, so adding a new variant per se should not be a breaking change.

The variant `Unsupported` itself could be marked as `#[unstable]`, however, because this PR also immediately uses this new variant and changes the errors returned by functions I'm inclined to agree with the others in this thread that the variant should be insta-stabilized.
2021-04-18 20:03:54 +00:00
Ralf Jung
7a5418dae1 fix aliasing violations in thread_local_const_init 2021-04-18 10:55:09 +02:00
CDirkx
b42e52f2cc Bump to 1.53.0
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-04-18 09:29:24 +02:00
Christiaan Dirkx
0895a693bd Fix test metadata_access_times to also check for Unsupported 2021-04-18 09:29:24 +02:00
Christiaan Dirkx
af0dec2795 Rename NotSupported to Unsupported 2021-04-18 09:29:23 +02:00
Christiaan Dirkx
1b5f117c47 Use NotSupported in more places 2021-04-18 09:29:23 +02:00
CDirkx
86592b9939 Bump since to 1.52.0 2021-04-18 09:29:22 +02:00
Christiaan Dirkx
9f589b023f Update decode_error_kind to decode os errors to NotSupported 2021-04-18 09:29:22 +02:00
Christiaan Dirkx
4a15bd8eaf Add and insta-stabilize std::io::ErrorKind::NotSupported 2021-04-18 09:29:22 +02:00