Commit graph

2669 commits

Author SHA1 Message Date
Thom Chiovoloni 554918e311
Hide Repr details from io::Error, and rework io::Error::new_const. 2022-02-04 18:47:29 -08:00
Matthias Krüger f070e0b5a6
Rollup merge of #93555 - ChrisDenton:fs-try-exists-doc, r=Mark-Simulacrum
Link `try_exists` docs to `Path::exists`

Links to the existing `Path::exists` method from both `std::Path::try_exists` and `std::fs:try_exists`.

Tracking issue for `path_try_exists`: #83186
2022-02-04 14:59:02 +01:00
bors 796bf14f2e Auto merge of #93146 - workingjubilee:use-std-simd, r=Mark-Simulacrum
pub use std::simd::StdFloat;

Syncs portable-simd up to commit rust-lang/portable-simd@03f6fbb21e,
Diff: 533f0fc81a...03f6fbb21e

This sync requires a little bit more legwork because it also introduces a trait into `std::simd`, so that it is no longer simply a reexport of `core::simd`. Out of simple-minded consistency and to allow more options, I replicated the pattern for the way `core::simd` is integrated in the first place, however this is not necessary if it doesn't acquire any interdependencies inside `std`: it could be a simple crate reexport. I just don't know yet if that will happen or not.

To summarize other misc changes:
- Shifts no longer panic, now wrap on too-large shifts (like `Simd` integers usually do!)
- mask16x32 will now be many i16s, not many i32s... 🙃
- `#[must_use]` is spread around generously
- Adjusts division, float min/max, and `Mask::{from,to}_array` internally to be faster
- Adds the much-requested `Simd::cast::<U>` function (equivalent to `simd.to_array().map(|lane| lane as U)`)
2022-02-03 09:15:16 +00:00
bors b3800860e1 Auto merge of #93101 - Mark-Simulacrum:library-backtrace, r=yaahc
Support configuring whether to capture backtraces at runtime

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

This adds a new API to the `std::panic` module which configures whether and how the default panic hook will emit a backtrace when a panic occurs.

After discussion with `@yaahc` on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/backtrace.20lib.20vs.2E.20panic), this PR chooses to avoid adjusting or seeking to provide a similar API for the (currently unstable) std::backtrace API. It seems likely that the users of that API may wish to expose more specific settings rather than just a global one (e.g., emulating the `env_logger`, `tracing` per-module configuration) to avoid the cost of capture in hot code. The API added here could plausibly be copied and/or re-exported directly from std::backtrace relatively easily, but I don't think that's the right call as of now.

```rust
mod panic {
    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
    #[non_exhaustive]
    pub enum BacktraceStyle {
        Short,
        Full,
        Off,
    }
    fn set_backtrace_style(BacktraceStyle);
    fn get_backtrace_style() -> Option<BacktraceStyle>;
}
```

Several unresolved questions:

* Do we need to move to a thread-local or otherwise more customizable strategy for whether to capture backtraces? See [this comment](https://github.com/rust-lang/rust/pull/79085#issuecomment-727845826) for some potential use cases for this.
   * Proposed answer: no, leave this for third-party hooks.
* Bikeshed on naming of all the options, as usual.
* Should BacktraceStyle be moved into `std::backtrace`?
   * It's already somewhat annoying to import and/or re-type the `std::panic::` prefix necessary to use these APIs, probably adding a second module to the mix isn't worth it.

Note that PR #79085 proposed a much simpler API, but particularly in light of the desire to fully replace setting environment variables via `env::set_var` to control the backtrace API, a more complete API seems preferable. This PR likely subsumes that one.
2022-02-02 22:03:23 +00:00
Mark Rousskov 85930c8f44 Configure panic hook backtrace behavior 2022-02-02 13:46:42 -05:00
Matthias Krüger b836b281a8
Rollup merge of #93531 - TheColdVoid:patch-1, r=m-ou-se
Fix incorrect panic message in example

The panic message when calling the `connect()` should probably be a  message about connection failure, not a message about binding address failure.
2022-02-02 07:11:07 +01:00
Matthias Krüger a3deca4675
Rollup merge of #93493 - GKFX:char-docs-2, r=scottmcm
Document valid values of the char type

As discussed at #93392, the current documentation on what constitutes a valid char isn't very detailed and is partly on the MAX constant rather than the type itself.

This PR expands on that information, stating the actual numerical range, giving examples of what won't work, and also mentions how a `char` might be a valid USV but still not be a defined character (terminology checked against [Unicode 14.0, table 2-3](https://www.unicode.org/versions/Unicode14.0.0/ch02.pdf#M9.61673.TableTitle.Table.22.Types.of.Code.Points)).
2022-02-02 07:11:07 +01:00
George Bateman d372baf3f9
Fix annotation of code blocks 2022-02-01 21:44:53 +00:00
bors 2681f253bc Auto merge of #93442 - yaahc:Termination-abstraction, r=Mark-Simulacrum
Change Termination::report return type to ExitCode

Related to https://github.com/rust-lang/rust/issues/43301

The goal of this change is to minimize the forward compatibility risks in stabilizing Termination. By using the opaque type `ExitCode` instead of an `i32` we leave room for us to evolve the API over time to provide what cross-platform consistency we can / minimize footguns when working with exit codes, where as stabilizing on `i32` would limit what changes we could make in the future in how we represent and construct exit codes.
2022-02-01 20:05:46 +00:00
Chris Denton 1bc8f0b49f
Link try_exists docs to Path::exists 2022-02-01 18:40:29 +00:00
Matthias Krüger 019c140244
Rollup merge of #93436 - dcsommer:master, r=Mark-Simulacrum
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310

See also https://github.com/rust-lang/compiler-builtins/issues/449 and https://github.com/rust-lang/compiler-builtins/pull/450
2022-02-01 16:08:06 +01:00
Matthias Krüger 741b62af07
Rollup merge of #92584 - lcnr:query-stable-lint, r=estebank
add rustc lint, warning when iterating over hashmaps 2

first introduced in #89558 and reverted in #90380 due to its perf impact

r? ``@estebank``
2022-02-01 16:08:03 +01:00
lcnr a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Eric Huss 8a70ea2394
Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisa
kmc-solid: Increase the default stack size

This PR increases the default minimum stack size on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets to 64KiB (Arm) and 128KiB (AArch64).

This value was chosen as a middle ground between supporting a relatively complex program (e.g., an application using a full-fledged off-the-shelf web server framework) with no additional configuration and minimizing resource consumption for the embedded platform that doesn't support lazily-allocated pages nor over-commitment (i.e., wasted stack spaces are wasted physical memory). If the need arises, the users can always set the `RUST_MIN_STACK` environmental variable to override the default stack size or use the platform API directly.
2022-01-31 20:12:59 -08:00
Eric Huss 8604161d75
Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnay
`impl Display for io::ErrorKind`

This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2022-01-31 20:12:56 -08:00
TheVoid 76aa92906b
Fix incorrect panic message in example 2022-02-01 10:19:08 +08:00
George Bateman 5357ec1473
(#93493) Add items from code review 2022-01-31 23:49:16 +00:00
Jane Lusby 19db85d6cd add inline attribute to new method 2022-01-31 11:57:17 -08:00
Tomoaki Kawada 1a77d6227c kmc-solid: Increase the default stack size 2022-01-31 17:39:38 +09:00
Matthias Krüger 4757a931cd
Rollup merge of #93494 - solid-rs:fix-kmc-solid-spawned-task-priority, r=Mark-Simulacrum
kmc-solid: Inherit the calling task's base priority in `Thread::new`

This PR fixes the initial priority calculation of spawned threads on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Fixes a spawned task (an RTOS object on top of which threads are implemented for this target; unrelated to async tasks) getting an unexpectedly higher priority if it's spawned by a task whose priority is temporarily boosted by a priority-protection mutex.
2022-01-31 07:00:47 +01:00
Matthias Krüger cd27f1b56e
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
unix: Use metadata for `DirEntry::file_type` fallback

When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
2022-01-31 07:00:44 +01:00
Matthias Krüger bc2c4feaeb
Rollup merge of #93462 - ChrisDenton:systime-doc, r=joshtriplett
Document `SystemTime` platform precision

Fixes #88822
2022-01-31 07:00:43 +01:00
Tomoaki Kawada 09233ce3c0 kmc-solid: Inherit the calling task's base priority in Thread::new
Fixes a spawned task getting an unexpectedly higher priority if it's
spawned by a task whose priority is temporarily boosted by a priority-
protection mutex.
2022-01-31 11:31:55 +09:00
George Bateman 4d4ec97e0a
Document char validity 2022-01-30 22:16:41 +00:00
Eric Huss 0610d4fa66
Rollup merge of #92887 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bootstrap compiler update

r? ``@Mark-Simulacrum``
2022-01-30 08:37:46 -08:00
Josh Stone d70b9c03ec unix: Use metadata for DirEntry::file_type fallback
When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
2022-01-29 16:58:18 -08:00
Matthias Krüger 0d08bbc8c8
Rollup merge of #93459 - tavianator:dirent-copy-only-reclen, r=cuviper
fs: Don't copy d_name from struct dirent

The dirent returned from readdir() is only guaranteed to be valid for
d_reclen bytes on common platforms.  Since we copy the name separately
anyway, we can copy everything except d_name into DirEntry::entry.

Fixes #93384.
2022-01-30 00:04:16 +01:00
Matthias Krüger 329753e248
Rollup merge of #93414 - Amanieu:std_arch_detect, r=m-ou-se
Move unstable is_{arch}_feature_detected! macros to std::arch

These macros are unstable, except for `is_x86_feature_detected` which is still exported from the crate root for backwards-compatibility.

This should unblock the stabilization of `is_aarch64_feature_detected`.

r? ```@m-ou-se```
2022-01-30 00:04:14 +01:00
Tavian Barnes d0c8b29ec6 fs: Add a regression test for #93384 2022-01-29 16:37:21 -05:00
Tavian Barnes f8f4c40527 fs: Don't copy d_name from struct dirent
The dirent returned from readdir() is only guaranteed to be valid for
d_reclen bytes on common platforms.  Since we copy the name separately
anyway, we can copy everything except d_name into DirEntry::entry.

Fixes #93384.
2022-01-29 16:37:21 -05:00
Chris Denton 0189a21c19
Document SystemTime platform precision 2022-01-29 20:41:18 +00:00
Daniel Sommermann 746b3d87b3 Update compiler_builtins to fix duplicate symbols in armv7-linux-androideabi rlib
I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310
2022-01-29 08:28:52 -08:00
Matthias Krüger 2836dcd2df
Rollup merge of #93410 - solid-rs:feat-kmc-solid-net-dup, r=dtolnay
kmc-solid: Implement `net::FileDesc::duplicate`

This PR implements `std::sys::solid::net::FileDesc::duplicate`, which was accidentally left out when this target was added by #86191.
2022-01-29 14:46:32 +01:00
bors ca43894e0e Auto merge of #93351 - anp:fuchsia-remove-dir-all, r=tmandry
Bump libc and fix remove_dir_all on Fuchsia after CVE fix

With the previous `is_dir` impl, we would attempt to unlink
a directory in the None branch, but Fuchsia supports returning
ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because
we don't currently differentiate unlinking files and directories
by default.

On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss
whether this is the correct behavior, but it doesn't seem like
addressing the error code is necessary to make our tests happy.

Depends on https://github.com/rust-lang/libc/pull/2654 since we
apparently haven't needed to reference DT_UNKNOWN before this.
2022-01-29 09:01:01 +00:00
Jane Lusby 91ffbc43b1 Change Termination::report return type to ExitCode 2022-01-28 12:53:36 -08:00
Adam Perry 8c9944c50d Fix remove_dir_all on Fuchsia after CVE fix.
With the previous `is_dir` impl, we would attempt to unlink
a directory in the None branch, but Fuchsia supports returning
ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because
we don't currently differentiate unlinking files and directories
by default.

On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss
whether this is the correct behavior, but it doesn't seem like
addressing the error code is necessary to make our tests happy.

Updates std's libc crate to include DT_UNKNOWN for Fuchsia.
2022-01-28 20:38:39 +00:00
Matthias Krüger 4f2e2ceeb7
Rollup merge of #93295 - ChrisDenton:tempdir-double-panic, r=dtolnay
Avoid double panics when using `TempDir` in tests

`TempDir` could panic on drop if `remove_dir_all` returns an error. If this happens while already panicking, the test process would abort and therefore not show the test results.

This PR tries to avoid such double panics.
2022-01-28 15:20:25 +01:00
Matthias Krüger 18c8d0da64
Rollup merge of #93239 - Thomasdezeeuw:socketaddr_creation, r=m-ou-se
Add os::unix::net::SocketAddr::from_path

Creates a new SocketAddr from a path, supports both regular paths and
abstract namespaces.

Note that `SocketAddr::from_abstract_namespace` could be removed after this as `SocketAddr::unix` also supports abstract namespaces.

Updates #65275
Unblocks https://github.com/tokio-rs/mio/issues/1527

r? `@m-ou-se`
2022-01-28 15:20:23 +01:00
Pietro Albini 5b3462c556
update cfg(bootstrap)s 2022-01-28 15:01:07 +01:00
Thomas de Zeeuw 35f578fc78 Update tracking issue for unix_socket_creation 2022-01-28 15:00:17 +01:00
Harald Hoyer d2a13693c2 wasi: enable TcpListener and TcpStream
With the addition of `sock_accept()` to snapshot1, simple networking via
a passed `TcpListener` is possible. This patch implements the basics to
make a simple server work.

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28 13:27:30 +01:00
Harald Hoyer 00cbc8d0c8 wasi: update to wasi 0.11.0
To make use of `sock_accept()`, update the wasi crate to `0.11.0`.

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28 13:27:29 +01:00
Amanieu d'Antras 2188c551cd Move unstable is_{arch}_feature_detected! macros to std::arch 2022-01-28 09:51:46 +00:00
Tomoaki Kawada da0d506ace kmc-solid: Implement FileDesc::duplicate 2022-01-28 15:02:44 +09:00
Matthias Krüger 4af3930f28
Rollup merge of #91641 - dtolnay:cchar-if, r=Mark-Simulacrum
Define c_char using cfg_if rather than repeating 40-line cfg

Libstd has a 40-line cfg that defines the targets on which `c_char` is unsigned, and then repeats the same cfg with `not(…)` for the targets on which `c_char` is signed.

This PR replaces it with a `cfg_if!` in which an `else` takes care of the signed case.

I confirmed that `x.py doc library/std` inlines the type alias because c_char_definition is not a publicly accessible path:

![Screenshot from 2021-12-07 13-42-07](https://user-images.githubusercontent.com/1940490/145110596-f1058406-9f32-44ff-9a81-1dfd19b4a24f.png)
2022-01-27 22:32:23 +01:00
Jubilee Young e96159e9af pub use std::simd::StdFloat;
Make available the remaining float intrinsics that require runtime support
from a platform's libm, and thus cannot be included in a no-deps libcore,
by exposing them through a sealed trait, `std::simd::StdFloat`.

We might use the trait approach a bit more in the future, or maybe not.
Ideally, this trait doesn't stick around, even if so.
If we don't need to intermesh it with std, it can be used as a crate,
but currently that is somewhat uncertain.
2022-01-27 11:50:58 -08:00
Thomas de Zeeuw 4acb8ac46c Use sockaddr_un in unix SocketAddr::from_path 2022-01-27 09:54:28 +01:00
Thomas de Zeeuw ca9a3c9a9f Make sockaddr_un safe and use copy_nonoverlapping
The creation of libc::sockaddr_un is a safe operation, no need for it to
be unsafe.

This also uses the more performant copy_nonoverlapping instead of an
iterator.
2022-01-27 09:52:59 +01:00
Matthias Krüger 253f64c9c6
Rollup merge of #92778 - tavianator:linux-readdir-no-r, r=joshtriplett
fs: Use readdir() instead of readdir_r() on Linux and Android

See #40021 for more details.  Fixes #86649.  Fixes #34668.
2022-01-26 23:45:23 +01:00
Артём Павлов [Artyom Pavlov] e0bcf771d6 Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa 2022-01-26 18:14:25 +03:00