Commit graph

7088 commits

Author SHA1 Message Date
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
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
Matthias Krüger 2b7f3ee89d
Rollup merge of #93930 - name1e5s:chore/docs, r=Mark-Simulacrum
add link to format_args! when mention it in docs

close #93904
2022-02-13 06:44:18 +01:00
Matthias Krüger 5699f683a4
Rollup merge of #93886 - clarfonthey:stable_ascii_escape, r=Mark-Simulacrum
Stabilise inherent_ascii_escape (FCP in #77174)

Implements #77174, which completed its FCP.

This does *not* deprecate any existing methods or structs, as that is tracked in #93887. That stated, people should prefer using `u8::escape_ascii` to `std::ascii::escape_default`.
2022-02-13 06:44:17 +01:00
Matthias Krüger 783b56ba68
Rollup merge of #93851 - cyqsimon:option-examples, r=scottmcm
More practical examples for `Option::and_then` & `Result::and_then`

To be blatantly honest, I think the current example given for `Option::and_then` is objectively terrible. (No offence to whoever wrote them initially.)

```rust
fn sq(x: u32) -> Option<u32> { Some(x * x) }
fn nope(_: u32) -> Option<u32> { None }

assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16));
assert_eq!(Some(2).and_then(sq).and_then(nope), None);
assert_eq!(Some(2).and_then(nope).and_then(sq), None);
assert_eq!(None.and_then(sq).and_then(sq), None);
```

Current example:
 - does not demonstrate that `and_then` converts `Option<T>` to `Option<U>`
 - is far removed from any realistic code
 - generally just causes more confusion than it helps

So I replaced them with two blocks:
 - the first one shows basic usage (including the type conversion)
 - the second one shows an example of typical usage

Same thing with `Result::and_then`.

Hopefully this helps with clarity.
2022-02-13 06:44:15 +01:00
Matthias Krüger 953c4dcc30
Rollup merge of #90532 - fee1-dead:improve-const-fn-err-msg, r=oli-obk
More informative error message for E0015

Helps with #92380
2022-02-13 06:44:13 +01:00
Matthias Krüger 92613a25fc
Rollup merge of #89926 - the8472:saturate-instant, r=Mark-Simulacrum
make `Instant::{duration_since, elapsed, sub}` saturating and remove workarounds

This removes all mutex/atomic-based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead. Additionally `saturating_duration_since` becomes deprecated since `duration_since` now fills that role.

Effectively this moves the fixup from `Instant` construction to the comparisons.

This has some observable effects, especially on platforms without monotonic clocks:

* Incorrectly ordered Instant comparisons no longer panic in release mode. This could hide some programming errors, but since debug mode still panics tests can still catch them.
* `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or manually created ones. Now it also does on backslides.
* non-monotonic intervals will not be transitive, i.e. `b.duration_since(a) + c.duration_since(b) != c.duration_since(a)`

The upsides are reduced complexity and lower overhead of `Instant::now`.

## Motivation

Currently we must choose between two poisons. One is high worst-case latency and jitter of `Instant::now()` due to explicit synchronization; see #83093 for benchmarks, the worst-case overhead is > 100x. The other is sporadic panics on specific, rare combinations of CPU/hypervisor/operating system due to platform bugs.

Use-cases where low-overhead, fine-grained timestamps are needed - such as syscall tracing, performance profiles or sensor data acquisition (drone flight controllers were mentioned in a libs meeting) in multi-threaded programs - are negatively impacted by the synchronization.

The panics are user-visible (program crashes), hard to reproduce and can be triggered by any dependency that might be using Instants for any reason.

A solution that is fast _and_ doesn't panic is desirable.

----

closes #84448
closes #86470
2022-02-13 06:44:12 +01:00
Gary Guo f74e8c7afc Guard against unwinding in cleanup code 2022-02-13 03:10:09 +00:00
bors 01c4c41301 Auto merge of #93696 - Amanieu:compiler-builtins-0.1.68, r=Mark-Simulacrum
Bump compiler-builtins to 0.1.69

This includes https://github.com/rust-lang/compiler-builtins/pull/452 which should fix some issues with duplicate symbol defintions of some intrinsics.
2022-02-13 02:40:56 +00:00
Josh Triplett 37a1fc542f Capitalize "Rust"
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2022-02-13 01:06:36 +01:00
The 8472 376d955a32 Add panic docs describing old, current and possible future behavior 2022-02-13 01:06:34 +01:00
The 8472 bda2693e9b Add caveat about the monotonicity guarantee by linking to the later section 2022-02-13 01:05:00 +01:00
The8472 9d8ef11607 make Instant::{duration_since, elapsed, sub} saturating and remove workarounds
This removes all mutex/atomics based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead.

Effectively this moves the monotonization from `Instant` construction to the comparisons.

This has some observable effects, especially on platforms without monotonic clocks:

* Incorrectly ordered Instant comparisons no longer panic. This may hide some programming errors until someone actually looks at the resulting `Duration`
* `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or
  manually created ones. Now it also does on backslides.

The upside is reduced complexity and lower overhead of `Instant::now`.
2022-02-13 01:04:55 +01:00
John Paul Adrian Glaubitz c26d5b3f9c library/unwind: Define unwinder_private_data_size for m68k 2022-02-12 20:21:10 +00:00
John Paul Adrian Glaubitz 990326fa74 library/panic_unwind: Define UNWIND_DATA_REG for m68k 2022-02-12 20:19:06 +00:00
ltdk de6e973176 Stabilise inherent_ascii_escape (FCP in #77174) 2022-02-12 13:21:59 -05:00
ltdk 9efe61df7f Fix signature of u8::escape_ascii 2022-02-12 13:15:10 -05:00
bors 9c3a3e3d5b Auto merge of #93697 - the8472:fix-windows-path-hash, r=Mark-Simulacrum
Fix hashing for windows paths containing a CurDir component

* the logic only checked for / but not for \
* verbatim paths shouldn't skip items at all since they don't get normalized
* the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false
* tests lacked windows coverage for these cases

That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-12 14:01:13 +00:00
Alphyr fe7d7c2004 Fix typo
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-12 12:31:33 +01:00
Benoît du Garreau d3e2ffcbc6 Fix shrink and capacity_from_bytes 2022-02-12 11:51:15 +01:00
Benoît du Garreau 6027182328 Fix a layout miscalculation in alloc::RawVec 2022-02-12 11:40:59 +01:00
Deadbeef f7f0f843b7
Improve error messages even more 2022-02-12 19:24:08 +11:00
cyqsimon f6f93fd7ba
Add note on Windows path behaviour 2022-02-12 12:52:42 +08:00
yuhaixin.hx daa3c795dc add link to format_args! when being mentioned in doc 2022-02-12 12:35:30 +08:00
cyqsimon 160faf1b30
Option::and_then basic example: show failure 2022-02-12 12:23:38 +08:00
cyqsimon adfac00f45
Result::and_then: show type conversion 2022-02-12 12:19:03 +08:00
cyqsimon 7eaecc6508
Result::and_then: improve basic example 2022-02-12 12:12:11 +08:00
bors f19851069e Auto merge of #93921 - matthiaskrgr:rollup-wn3jlxj, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #90955 (Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`)
 - #91607 (Make `span_extend_to_prev_str()` more robust)
 - #92895 (Remove some unused functionality)
 - #93635 (Add missing platform-specific information on current_dir and set_current_dir)
 - #93660 (rustdoc-json: Add some tests for typealias item)
 - #93782 (Split `pauth` target feature)
 - #93868 (Fix incorrect register conflict detection in asm!)
 - #93888 (Implement `AsFd` for `&T` and `&mut T`.)
 - #93909 (Fix typo: explicitely -> explicitly)
 - #93910 (fix mention of moved function in `rustc_hir` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-11 23:01:50 +00:00
Matthias Krüger 34997f0114
Rollup merge of #93888 - sunfishcode:sunfishcode/impl-asfd-for-ref, r=joshtriplett
Implement `AsFd` for `&T` and `&mut T`.

Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
write code like this:

```rust
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
```

with `fd: F` rather than `fd: &F`.

And similar for `AsHandle` and `AsSocket` on Windows.

Also, adjust the `fchown` example to pass the file by reference. The
code can work either way now, but passing by reference is more likely
to be what users will want to do.

This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
and it prevents a pitfall in the case where users write `fd: F` instead
of `fd: &F`.

r? ```@joshtriplett```
2022-02-11 21:48:50 +01:00
Matthias Krüger 15d71cff2d
Rollup merge of #93635 - GuillaumeGomez:missing-platform-spec-info, r=Amanieu
Add missing platform-specific information on current_dir and set_current_dir

Fixes #93598.
2022-02-11 21:48:46 +01:00
Matthias Krüger ce4df92c8c
Rollup merge of #90955 - JohnTitor:os-error-123-as-invalid-input, r=m-ou-se
Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`

Address https://github.com/rust-lang/rust/issues/90940#issuecomment-970157931
`ERROR_INVALID_NAME` (i.e. "The filename, directory name, or volume label syntax is incorrect") happens if we pass an invalid filename, directory name, or label syntax, so mapping as `InvalidInput` is reasonable to me.
2022-02-11 21:48:42 +01:00
bors e789f3a3a3 Auto merge of #90271 - adamgemmell:dev/feat-detect-stabilise, r=Amanieu
Stabilise `is_aarch64_feature_detected!` under `simd_aarch64` feature

Initial implementation, looking for feedback on the approach here. https://github.com/rust-lang/rust/issues/86941

One point I noticed was that I haven't seen different "since" versions for the same feature - does this mean that other features can't be added to to the `simd_aarch64` feature once this is in stable? If so it might need a more specific name.

r? `@Amanieu`
2022-02-11 20:41:51 +00:00
Guillaume Gomez 22a24c98d3 Add missing platform-specific information on current_dir and set_current_dir 2022-02-11 16:33:02 +01:00
Dan Gohman 1f98ef7793 Implement AsFd for &T and &mut T.
Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
write code like this:

```rust
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
```

with `fd: F` rather than `fd: &F`.

And similar for `AsHandle` and `AsSocket` on Windows.

Also, adjust the `fchown` example to pass the file by reference. The
code can work either way now, but passing by reference is more likely
to be what users will want to do.

This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
and it prevents a pitfall in the case where users write `fd: F` instead
of `fd: &F`.
2022-02-10 18:26:12 -08:00
cyqsimon 942eaa7ffc
Add negative example for Result::and_then 2022-02-11 09:57:19 +08:00
Charisee dbeab9c532 added space 2022-02-10 22:30:51 +00:00
Charisee a889079b29 add cfg_panic bootstrap 2022-02-10 22:10:08 +00:00
Charisee d018a8b624 remove mention of cfg_panic from library tests 2022-02-10 22:09:11 +00:00
Charisee 5e6be7df94 replace feature expression (cfg_panic) in lib and remove expression from tests
Rebase commit
2022-02-10 22:06:47 +00:00
Adam Gemmell 93b5bfbc48 Update stdarch submodule 2022-02-10 15:24:13 +00:00
Adam Gemmell 102a0ffd37 Move is_aarch64_feature_detected! to simd_aarch64 feature and stabilise 2022-02-10 15:24:13 +00:00
Yuki Okushi a898b31662
Rename to InvalidFilename 2022-02-10 23:49:27 +09:00
Josh Triplett 861f3c70a2
Fix description of FilenameInvalid
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-02-10 23:42:27 +09:00
Yuki Okushi cc9407924d
Map ERROR_INVALID_NAME to FilenameInvalid 2022-02-10 23:42:27 +09:00
Yuki Okushi 755e475c8b
Rename FilenameTooLong to FilenameInvalid 2022-02-10 23:42:26 +09:00
Yuki Okushi 1115f15e1c
windows: Map ERROR_INVALID_NAME as InvalidInput 2022-02-10 23:42:23 +09:00
Matthias Krüger 8c60f44877
Rollup merge of #93843 - solid-rs:fix-kmc-solid-condvar, r=m-ou-se
kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation

This PR fixes a number of bugs in the `Condvar` wait queue implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. These bugs can occur when there are multiple threads waiting on the same `Condvar` and sometimes manifest as an `unwrap` failure.
2022-02-10 12:10:02 +01:00
Matthias Krüger aa2095936a
Rollup merge of #93824 - Amanieu:stable_cfg_target_has_atomic, r=davidtwco
Stabilize cfg_target_has_atomic

`target_has_atomic_equal_alignment` is now tracked separately in #93822.

Closes #32976
2022-02-10 12:10:00 +01:00
cyqsimon bd421e2880
More practical examples for Result::and_then 2022-02-10 17:59:46 +08:00
cyqsimon 73a5f01263
Use 0-based idx for array content 2022-02-10 16:32:53 +08:00
cyqsimon a8e9708aeb
More practical examples for Option::and_then 2022-02-10 16:09:49 +08:00
Tomoaki Kawada 64406c5996 kmc-solid: Use the filesystem thread-safety wrapper
Neither the SOLID filesystem API nor built-in filesystems 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 `std` code to leverage the filesystem thread-
safety wrapper 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-10 13:33:35 +09:00
Tomoaki Kawada 1d180caf1a kmc-solid: Wait queue should be sorted in the descending order of task priorities
In ITRON, lower priority values mean higher priorities.
2022-02-10 11:35:37 +09:00
Tomoaki Kawada bdc9508bb6 kmc-solid: Fix wait queue manipulation errors in the Condvar implementation 2022-02-10 10:21:39 +09:00
Matthias Krüger 6db0f9ca0d
Rollup merge of #93799 - wooorm:patch-1, r=dtolnay
Fix typo in `std::fmt` docs

Hey!

Reading the docs (https://doc.rust-lang.org/std/fmt/#named-parameters), this seems like a typo?

The docs here also seem to mix “named argument” and “named parameter”? Intentional? Mistake?
2022-02-09 23:29:58 +01:00
Amanieu d'Antras 7b8f6ac5ab Bump compiler-builtins to 0.1.69 2022-02-09 21:03:13 +00:00
Amanieu d'Antras 49d4823112 Stabilize cfg_target_has_atomic
Closes #32976
2022-02-09 18:45:44 +00:00
Michael Goulet fea0015f93 Suggest collecting into Vec<_> when collecting into [_] 2022-02-09 09:35:46 -08:00
Titus 3d3318b406
Fix typo in std::fmt docs 2022-02-09 11:26:10 +01:00
Yuki Okushi 56094651b8
Rollup merge of #93735 - m-ou-se:stabilize-int-abs-diff, r=joshtriplett
Stabilize int_abs_diff in 1.60.0.

FCP finished here: https://github.com/rust-lang/rust/issues/89492#issuecomment-1030694522
2022-02-09 14:12:21 +09:00
Yuki Okushi ec2fd8a35f
Rollup merge of #93445 - yaahc:exitcode-constructor, r=dtolnay
Add From<u8> for ExitCode

This should cover a mostly cross-platform subset of supported exit codes.

We decided to stick with `u8` initially since its the common subset between all platforms that we support (excluding wasm which I think only works with `true` or `false`). Posix is supposed to take i32s, but in practice many unix platforms mask out all but the low 8 bits or in some cases the 8-15th bits. Windows takes a u32 instead of an i32. Bourne-compatible shells also report signals as exitcode 128 + `signal_no`, so there's some ambiguity there when returning exit codes > 127, but it is possible to disambiguate them on the other side so we decided against restricting the possible codes further than to `u8`.

## Related

- Detailed analysis of exit code support on various platforms: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
- https://github.com/rust-lang/rust/issues/48711
- https://github.com/rust-lang/rust/issues/43301
- https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization
2022-02-09 14:12:17 +09:00
bors 9a5a961be9 Auto merge of #93778 - matthiaskrgr:rollup-yfngdao, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91950 (Point at type when a `static` `#[global_allocator]` doesn't `impl` `GlobalAlloc`)
 - #92715 (Do not suggest char literal for zero-length strings)
 - #92917 (Don't constrain projection predicates with inference vars in GAT substs)
 - #93206 (Use `NtCreateFile` instead of `NtOpenFile` to open a file)
 - #93732 (add fut/back compat tests for implied trait bounds)
 - #93764 (⬆️ rust-analyzer)
 - #93767 (deduplicate `lcnr` in mailmap)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-09 01:18:06 +00:00
Matthias Krüger 9cb39a6083
Rollup merge of #93206 - ChrisDenton:ntopenfile, r=nagisa
Use `NtCreateFile` instead of `NtOpenFile` to open a file

Generally the internal `Nt*` functions should be avoided but when we do need to use one we should stick to the most commonly used for the job. To that end, this PR replaces `NtOpenFile` with `NtCreateFile`.

NOTE: The initial version of this comment hypothesised that this may help with some recent false positives from malware scanners. This hypothesis proved wrong. Sorry for the distraction.
2022-02-08 16:40:49 +01:00
Chris Denton 81cc3afe20
Fix absolute issues 2022-02-08 14:57:35 +00:00
Chris Denton d59d32c4f1
std::path::absolute 2022-02-08 14:57:34 +00:00
bors 0c292c9667 Auto merge of #93572 - scottmcm:generic-iter-process, r=yaahc
Change `ResultShunt` to be generic over `Try`

Just a refactor (and rename) for now, so it's not `Result`-specific.

This could be used for a future `Iterator::try_collect`, or similar, but anything like that is left for a future PR.
2022-02-08 13:41:40 +00:00
Matthias Krüger 1f841fc5fe
Rollup merge of #86497 - clarfonthey:nearest_char_boundary, r=scottmcm
Add {floor,ceil}_char_boundary methods to str

This is technically already used internally by the standard library in the form of `truncate_to_char_boundary`.

Essentially these are two building blocks to allow for approximate string truncation, where you want to cut off the string at "approximately" a given length in bytes but don't know exactly where the character boundaries lie. It's also a good candidate for the standard library as it can easily be done naively, but would be difficult to properly optimise. Although the existing code that's done in error messages is done naively, this code will explicitly only check a window of 4 bytes since we know that a boundary must lie in that range, and because it will make it possible to vectorise.

Although this method doesn't take into account graphemes or other properties, this would still be a required building block for splitting that takes those into account. For example, if you wanted to split at a grapheme boundary, you could take your approximate splitting point and then determine the graphemes immediately following and preceeding the split. If you then notice that these two graphemes could be merged, you can decide to either include the whole grapheme or exclude it depending on whether you decide splitting should shrink or expand the string.

This takes the most conservative approach and just offers the raw indices to the user, and they can decide how to use them. That way, the methods are as useful as possible despite having as few methods as possible.

(Note: I'll add some tests and a tracking issue if it's decided that this is worth including.)
2022-02-08 06:47:31 +01:00
Scott McMurray 413945ecc5 Change ResultShunt to be generic over Try
Just a refactor (and rename) for now, so it's not `Result`-specific.

This could be used for a future `Iterator::try_collect`, or similar, but anything like that is left for a future PR.
2022-02-07 12:57:25 -08:00
Jane Lusby 4c5a36e2d1 fix exclusive range error 2022-02-07 12:45:36 -08:00
bors 734368a200 Auto merge of #87869 - thomcc:skinny-io-error, r=yaahc
Make io::Error use 64 bits on targets with 64 bit pointers.

I've wanted this for a long time, but didn't see a good way to do it without having extra allocation. When looking at it yesterday, it was more clear what to do for some reason.

This approach avoids any additional allocations, and reduces the size by half (8 bytes, down from 16). AFAICT it doesn't come additional runtime cost, and the compiler seems to do a better job with code using it.

Additionally, this `io::Error` has a niche (still), so `io::Result<()>` is *also* 64 bits (8 bytes, down from 16), and `io::Result<usize>` (used for lots of io trait functions) is 2x64 bits (16 bytes, down from 24 — this means on x86_64 it can use the nice rax/rdx 2-reg struct return). More generally, it shaves a whole 64 bit integer register off of the size of basically any `io::Result<()>`.

(For clarity: Improving `io::Result` (rather than io::Error) was most of the motivation for this)

On 32 bit (or other non-64bit) targets we still use something equivalent the old repr — I don't think think there's improving it, since one of the fields it stores is a `i32`, so we can't get below that, and it's already about as close as we can get to it.

---

### Isn't Pointer Tagging Dodgy?

The details of the layout, and why its implemented the way it is, are explained in the header comment of library/std/src/io/error/repr_bitpacked.rs. There's probably more details than there need to be, but I didn't trim it down that much, since there's a lot of stuff I did deliberately, that might have not seemed that way.

There's actually only one variant holding a pointer which gets tagged. This one is the (holder for the) user-provided error.

I believe the scheme used to tag it is not UB, and that it preserves pointer provenance (even though often pointer tagging does not) because the tagging operation is just `core::ptr::add`, and untagging is `core::ptr::sub`. The result of both operations lands inside the original allocation, so it would follow the safety contract of `core::ptr::{add,sub}`.

The other pointer this had to encode is not tagged — or rather, the tagged repr is equivalent to untagged (it's tagged with 0b00, and has >=4b alignment, so we can reuse the bottom bits). And the other variants we encode are just integers, which (which can be untagged using bitwise operations without worry — they're integers).

CC `@RalfJung` for the stuff in repr_bitpacked.rs, as my comments are informed by a lot of the UCG work, but it's possible I missed something or got it wrong (even if the implementation is okay, there are parts of the header comment that says things like "We can't do $x" which could be false).

---

### Why So Many Changes?

The repr change was mostly internal, but changed one widely used API: I had to switch how `io::Error::new_const` works.

This required switching `io::Error::new_const` to take the full message data (including the kind) as a `&'static`, rather than just the string. This would have been really tedious, but I made a macro that made it much simpler, but it was a wide change since `io::Error::new_const` is used everywhere.

This included changing files for a lot of targets I don't have easy access to (SGX? Haiku? Windows? Who has heard of these things), so I expect there to be spottiness in CI initially, unless luck is on my side.

Anyway this large only tangentially-related change is all in the first commit (although that commit also pulls the previous repr out into its own file), whereas the packing stuff is all in commit 2.

---

P.S. I haven't looked at all of this since writing it, and will do a pass over it again later, sorry for any obvious typos or w/e. I also definitely repeat myself in comments and such.

(It probably could use more tests too. I did some basic testing, and made it so we `debug_assert!` in cases the decode isn't what we encoded, but I don't know the degree which I can assume libstd's testing of IO would exercise this. That is: it wouldn't be surprising to me if libstds IO testing were minimal, especially around error cases, although I have no idea).
2022-02-07 20:32:56 +00:00
ltdk edd318c313 Add {floor,ceil}_char_boundary methods to str 2022-02-07 13:34:08 -05:00
bors f52c31840d Auto merge of #93738 - m-ou-se:rollup-zjyd2et, r=m-ou-se
Rollup of 13 pull requests

Successful merges:

 - #88313 (Make the pre-commit script pre-push instead)
 - #91530 (Suggest 1-tuple parentheses on exprs without existing parens)
 - #92724 (Cleanup c_str.rs)
 - #93208 (Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t> for rust 1.60.0)
 - #93394 (Don't allow {} to refer to implicit captures in format_args.)
 - #93416 (remove `allow_fail` test flag)
 - #93487 (Fix linking stage1 toolchain in `./x.py setup`)
 - #93673 (Linkify sidebar headings for sibling items)
 - #93680 (Drop json::from_reader)
 - #93682 (Update tracking issue for `const_fn_trait_bound`)
 - #93722 (Use shallow clones for submodules managed by rustbuild, not just bootstrap.py)
 - #93723 (Rerun bootstrap's build script when RUSTC changes)
 - #93737 (bootstrap: prefer using '--config' over 'RUST_BOOTSTRAP_CONFIG')

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-07 15:32:19 +00:00
Mara Bos 252ff5ead0
Rollup merge of #93416 - name1e5s:chore/remove_allow_fail, r=m-ou-se
remove `allow_fail` test flag

close #93345
2022-02-07 14:08:34 +00:00
Mara Bos e3c972e252
Rollup merge of #93208 - kellerkindt:wrapping_int_assign_impl, r=m-ou-se
Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t> for rust 1.60.0

Tracking issue #93204

This is about adding basic integer operations to the `Wrapping` type:

```rust
let mut value = Wrapping(2u8);
value += 3u8;
value -= 1u8;
value *= 2u8;
value /= 2u8;
value %= 2u8;
value ^= 255u8;
value |= 123u8;
value &= 2u8;
```

Because this adds stable impls on a stable type, it runs into the following issue if an `#[unstable(...)]` attribute is used:

```
an `#[unstable]` annotation here has no effect
note: see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
```

This means - if I understood this correctly - the new impls have to be stabilized instantly.
Which in turn means, this PR has to kick of an FCP on the tracking issue as well?

This impl is analog to 1c0dc1810d #92356 for the `Saturating` type ``@dtolnay``  ``@Mark-Simulacrum``
2022-02-07 14:08:32 +00:00
Mara Bos 8219ad4fac
Rollup merge of #92724 - inteon:cleanup, r=Mark-Simulacrum
Cleanup c_str.rs

Some code cleanups in `c_str.rs`.
No functional changes.

ref: https://github.com/bytecodealliance/rustix/pull/163
2022-02-07 14:08:32 +00:00
bors c5e414843e Auto merge of #93719 - scottmcm:core-as-2021-everywhere, r=Mark-Simulacrum
Build libcore as 2021 in a few more places

The `Cargo.toml` has `edition = "2021"` (as of #92068), so that's what these command lines should use too.
2022-02-07 12:38:21 +00:00
Mara Bos 687d20afb8 Mark int_abs_diff as const stable. 2022-02-07 12:16:44 +01:00
Mara Bos 7d91d42993 Stabilize int_abs_diff in 1.60.0. 2022-02-07 12:02:56 +01:00
Mara Bos 14ff58cd86 Stabilize wrapping_int_assign_impl in 1.60.0. 2022-02-07 11:45:12 +01:00
bors 25b21a1d16 Auto merge of #93179 - Urgau:unreachable-2021, r=m-ou-se,oli-obk
Fix invalid special casing of the unreachable! macro

This pull-request fix an invalid special casing of the `unreachable!` macro in the same way the `panic!` macro was solved, by adding two new internal only macros `unreachable_2015` and `unreachable_2021` edition dependent and turn `unreachable!` into a built-in macro that do dispatching. This logic is stolen from the `panic!` macro.

~~This pull-request also adds an internal feature `format_args_capture_non_literal` that allows capturing arguments from formatted string that expanded from macros. The original RFC #2795 mentioned this as a future possibility. This feature is [required](https://github.com/rust-lang/rust/issues/92137#issuecomment-1018630522) because of concatenation that needs to be done inside the macro:~~
```rust
$crate::concat!("internal error: entered unreachable code: ", $fmt)
```

**In summary** the new behavior for the `unreachable!` macro with this pr is:

Edition 2021:
```rust
let x = 5;
unreachable!("x is {x}");
```
```
internal error: entered unreachable code: x is 5
```

Edition <= 2018:
```rust
let x = 5;
unreachable!("x is {x}");
```
```
internal error: entered unreachable code: x is {x}
```

Also note that the change in this PR are **insta-stable** and **breaking changes** but this a considered as being a [bug](https://github.com/rust-lang/rust/issues/92137#issuecomment-998441613).
If someone could start a perf run and then a crater run this would be appreciated.

Fixes https://github.com/rust-lang/rust/issues/92137
2022-02-07 00:26:52 +00:00
Scott McMurray d91e7a3663 Build libcore as 2021 in a few more places
The `Cargo.toml` has `edition = "2021"`, so that's what these command lines should use too.
2022-02-06 15:41:01 -08:00
bors 7b43cfc9b2 Auto merge of #93695 - matthiaskrgr:rollup-zslgooo, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #90998 (Require const stability attribute on all stable functions that are `const`)
 - #93489 (Mark the panic_no_unwind lang item as nounwind)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-06 21:41:00 +00:00
Jane Lusby cf4ac6b1e1
Add From<u8> for ExitCode
This should cover a mostly cross-platform subset of supported exit codes.
2022-02-06 12:43:12 -08:00
Inteon afb7a502f6
rewrite from_bytes_with_nul to match code style in from_vec_with_nul
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
2022-02-06 20:07:03 +01:00
The 8472 45082b077b Fix hashing for windows paths containing a CurDir component
* the logic only checked for / but not for \
* verbatim paths shouldn't skip items at all since they don't get normalized
* the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false
* tests lacked windows coverage for these cases

That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-06 11:43:50 +01:00
Matthias Krüger 4695c2157c
Rollup merge of #93489 - Amanieu:panic_no_unwind, r=nagisa
Mark the panic_no_unwind lang item as nounwind

This has 2 effects:
- It helps LLVM when inlining since it doesn't need to generate landing pads for `panic_no_unwind`.
- It makes it sound for a panic handler to unwind even if `PanicInfo::can_unwind` returns true. This will simply cause another panic once the unwind tries to go past the `panic_no_unwind` lang item. Eventually this will cause a stack overflow, which is safe.
2022-02-06 10:43:51 +01:00
Matthias Krüger 9f4559c345
Rollup merge of #90998 - jhpratt:require-const-stability, r=oli-obk
Require const stability attribute on all stable functions that are `const`

This PR requires all stable functions (of all kinds) that are `const fn` to have a `#[rustc_const_stable]` or `#[rustc_const_unstable]` attribute. Stability was previously implied if omitted; a follow-up PR is planned to change the fallback to be unstable.
2022-02-06 10:43:50 +01:00
bors f624427f87 Auto merge of #90414 - thomcc:count-chars-faster, r=nagisa
Optimize `core::str::Chars::count`

I wrote this a while ago after seeing this function as a bottleneck in a profile, but never got around to contributing it. I saw it again, and so here it is. The implementation is fairly complex, but I tried to explain what's happening at both a high level (in the header comment for the file), and in line comments in the impl. Hopefully it's clear enough.

This implementation (`case00_cur_libcore` in the benchmarks below) is somewhat consistently around 4x to 5x faster than the old implementation (`case01_old_libcore` in the benchmarks below), for a wide variety of workloads, without regressing performance on any of the workload sizes I've tried.

I also improved the benchmarks for this code, so that they explicitly check text in different languages and of different sizes (err, the cross product of language x size). The results of the benchmarks are here:

<details>
<summary>Benchmark results</summary>
<pre>
test str::char_count::emoji_huge::case00_cur_libcore       ... bench:      20,216 ns/iter (+/- 3,673) = 17931 MB/s
test str::char_count::emoji_huge::case01_old_libcore       ... bench:     108,851 ns/iter (+/- 12,777) = 3330 MB/s
test str::char_count::emoji_huge::case02_iter_increment    ... bench:     329,502 ns/iter (+/- 4,163) = 1100 MB/s
test str::char_count::emoji_huge::case03_manual_char_len   ... bench:     223,333 ns/iter (+/- 14,167) = 1623 MB/s
test str::char_count::emoji_large::case00_cur_libcore      ... bench:         293 ns/iter (+/- 6) = 19331 MB/s
test str::char_count::emoji_large::case01_old_libcore      ... bench:       1,681 ns/iter (+/- 28) = 3369 MB/s
test str::char_count::emoji_large::case02_iter_increment   ... bench:       5,166 ns/iter (+/- 85) = 1096 MB/s
test str::char_count::emoji_large::case03_manual_char_len  ... bench:       3,476 ns/iter (+/- 62) = 1629 MB/s
test str::char_count::emoji_medium::case00_cur_libcore     ... bench:          48 ns/iter (+/- 0) = 14750 MB/s
test str::char_count::emoji_medium::case01_old_libcore     ... bench:         217 ns/iter (+/- 4) = 3262 MB/s
test str::char_count::emoji_medium::case02_iter_increment  ... bench:         642 ns/iter (+/- 7) = 1102 MB/s
test str::char_count::emoji_medium::case03_manual_char_len ... bench:         445 ns/iter (+/- 3) = 1591 MB/s
test str::char_count::emoji_small::case00_cur_libcore      ... bench:          18 ns/iter (+/- 0) = 3777 MB/s
test str::char_count::emoji_small::case01_old_libcore      ... bench:          23 ns/iter (+/- 0) = 2956 MB/s
test str::char_count::emoji_small::case02_iter_increment   ... bench:          66 ns/iter (+/- 2) = 1030 MB/s
test str::char_count::emoji_small::case03_manual_char_len  ... bench:          29 ns/iter (+/- 1) = 2344 MB/s
test str::char_count::en_huge::case00_cur_libcore          ... bench:      25,909 ns/iter (+/- 39,260) = 13299 MB/s
test str::char_count::en_huge::case01_old_libcore          ... bench:     102,887 ns/iter (+/- 3,257) = 3349 MB/s
test str::char_count::en_huge::case02_iter_increment       ... bench:     166,370 ns/iter (+/- 12,439) = 2071 MB/s
test str::char_count::en_huge::case03_manual_char_len      ... bench:     166,332 ns/iter (+/- 4,262) = 2071 MB/s
test str::char_count::en_large::case00_cur_libcore         ... bench:         281 ns/iter (+/- 6) = 19160 MB/s
test str::char_count::en_large::case01_old_libcore         ... bench:       1,598 ns/iter (+/- 19) = 3369 MB/s
test str::char_count::en_large::case02_iter_increment      ... bench:       2,598 ns/iter (+/- 167) = 2072 MB/s
test str::char_count::en_large::case03_manual_char_len     ... bench:       2,578 ns/iter (+/- 55) = 2088 MB/s
test str::char_count::en_medium::case00_cur_libcore        ... bench:          44 ns/iter (+/- 1) = 15295 MB/s
test str::char_count::en_medium::case01_old_libcore        ... bench:         201 ns/iter (+/- 51) = 3348 MB/s
test str::char_count::en_medium::case02_iter_increment     ... bench:         322 ns/iter (+/- 40) = 2090 MB/s
test str::char_count::en_medium::case03_manual_char_len    ... bench:         319 ns/iter (+/- 5) = 2109 MB/s
test str::char_count::en_small::case00_cur_libcore         ... bench:          15 ns/iter (+/- 0) = 2333 MB/s
test str::char_count::en_small::case01_old_libcore         ... bench:          14 ns/iter (+/- 0) = 2500 MB/s
test str::char_count::en_small::case02_iter_increment      ... bench:          30 ns/iter (+/- 1) = 1166 MB/s
test str::char_count::en_small::case03_manual_char_len     ... bench:          30 ns/iter (+/- 1) = 1166 MB/s
test str::char_count::ru_huge::case00_cur_libcore          ... bench:      16,439 ns/iter (+/- 3,105) = 19777 MB/s
test str::char_count::ru_huge::case01_old_libcore          ... bench:      89,480 ns/iter (+/- 2,555) = 3633 MB/s
test str::char_count::ru_huge::case02_iter_increment       ... bench:     217,703 ns/iter (+/- 22,185) = 1493 MB/s
test str::char_count::ru_huge::case03_manual_char_len      ... bench:     157,330 ns/iter (+/- 19,188) = 2066 MB/s
test str::char_count::ru_large::case00_cur_libcore         ... bench:         243 ns/iter (+/- 6) = 20905 MB/s
test str::char_count::ru_large::case01_old_libcore         ... bench:       1,384 ns/iter (+/- 51) = 3670 MB/s
test str::char_count::ru_large::case02_iter_increment      ... bench:       3,381 ns/iter (+/- 543) = 1502 MB/s
test str::char_count::ru_large::case03_manual_char_len     ... bench:       2,423 ns/iter (+/- 429) = 2096 MB/s
test str::char_count::ru_medium::case00_cur_libcore        ... bench:          42 ns/iter (+/- 1) = 15119 MB/s
test str::char_count::ru_medium::case01_old_libcore        ... bench:         180 ns/iter (+/- 4) = 3527 MB/s
test str::char_count::ru_medium::case02_iter_increment     ... bench:         402 ns/iter (+/- 45) = 1579 MB/s
test str::char_count::ru_medium::case03_manual_char_len    ... bench:         280 ns/iter (+/- 29) = 2267 MB/s
test str::char_count::ru_small::case00_cur_libcore         ... bench:          12 ns/iter (+/- 0) = 2666 MB/s
test str::char_count::ru_small::case01_old_libcore         ... bench:          12 ns/iter (+/- 0) = 2666 MB/s
test str::char_count::ru_small::case02_iter_increment      ... bench:          19 ns/iter (+/- 0) = 1684 MB/s
test str::char_count::ru_small::case03_manual_char_len     ... bench:          14 ns/iter (+/- 1) = 2285 MB/s
test str::char_count::zh_huge::case00_cur_libcore          ... bench:      15,053 ns/iter (+/- 2,640) = 20067 MB/s
test str::char_count::zh_huge::case01_old_libcore          ... bench:      82,622 ns/iter (+/- 3,602) = 3656 MB/s
test str::char_count::zh_huge::case02_iter_increment       ... bench:     230,456 ns/iter (+/- 7,246) = 1310 MB/s
test str::char_count::zh_huge::case03_manual_char_len      ... bench:     220,595 ns/iter (+/- 11,624) = 1369 MB/s
test str::char_count::zh_large::case00_cur_libcore         ... bench:         227 ns/iter (+/- 65) = 20792 MB/s
test str::char_count::zh_large::case01_old_libcore         ... bench:       1,136 ns/iter (+/- 144) = 4154 MB/s
test str::char_count::zh_large::case02_iter_increment      ... bench:       3,147 ns/iter (+/- 253) = 1499 MB/s
test str::char_count::zh_large::case03_manual_char_len     ... bench:       2,993 ns/iter (+/- 400) = 1577 MB/s
test str::char_count::zh_medium::case00_cur_libcore        ... bench:          36 ns/iter (+/- 5) = 16388 MB/s
test str::char_count::zh_medium::case01_old_libcore        ... bench:         142 ns/iter (+/- 18) = 4154 MB/s
test str::char_count::zh_medium::case02_iter_increment     ... bench:         379 ns/iter (+/- 37) = 1556 MB/s
test str::char_count::zh_medium::case03_manual_char_len    ... bench:         364 ns/iter (+/- 51) = 1620 MB/s
test str::char_count::zh_small::case00_cur_libcore         ... bench:          11 ns/iter (+/- 1) = 3000 MB/s
test str::char_count::zh_small::case01_old_libcore         ... bench:          11 ns/iter (+/- 1) = 3000 MB/s
test str::char_count::zh_small::case02_iter_increment      ... bench:          20 ns/iter (+/- 3) = 1650 MB/s
</pre>
</details>

I also added fairly thorough tests for different sizes and alignments. This completes on my machine in 0.02s, which is surprising given how thorough they are, but it seems to detect bugs in the implementation. (I haven't run the tests on a 32 bit machine yet since before I reworked the code a little though, so... hopefully I'm not about to embarrass myself).

This uses similar SWAR-style techniques to the `is_ascii` impl I contributed in https://github.com/rust-lang/rust/pull/74066, so I'm going to request review from the same person who reviewed that one. That said am not particularly picky, and might not have the correct syntax for requesting a review from someone (so it goes).

r? `@nagisa`
2022-02-06 08:34:48 +00:00
Amanieu d'Antras 915a16035d Mark __rgl_oom and __rd_oom as "C-unwind" 2022-02-05 20:58:04 +00:00
Amanieu d'Antras b1b8810952 Allow handle_alloc_error to unwind 2022-02-05 20:58:04 +00:00
Thom Chiovoloni 41f821461f
Fix comment grammar for do_count_chars 2022-02-05 11:17:10 -08:00
Thom Chiovoloni ebbccaf6bf
Respond to review feedback, and improve implementation somewhat 2022-02-05 11:15:18 -08:00
Thom Chiovoloni 002aaf2c65
Ensure non-power-of-two sizes are tested in the Chars::count test 2022-02-05 11:15:18 -08:00
Thom Chiovoloni ed01324835
Fix zh::SMALL string in core::str benchmarks 2022-02-05 11:15:17 -08:00
Thom Chiovoloni 628b217326
Optimize core::str::Chars::count 2022-02-05 11:15:17 -08:00
Thom Chiovoloni 9cbe99488b
Add more tests for io::Error packing, and fix some comments that weren't quite accurate anymore 2022-02-04 23:15:02 -08:00
Thom Chiovoloni a17a896d09
Update documentation somewhat 2022-02-04 18:47:31 -08:00
Thom Chiovoloni e98c7f7209
Use wrapping pointer arithmetic in the bitpacked io::Error 2022-02-04 18:47:31 -08:00
Thom Chiovoloni f950edbef7
Elaborate some in the documentation and respond to some review comments 2022-02-04 18:47:31 -08:00
Thom Chiovoloni 06edf082c3
Update library/std/src/io/error/repr_bitpacked.rs
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2022-02-04 18:47:30 -08:00
Thom Chiovoloni 9f7eb7d473
Fix comment typos noticed by code review.
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-02-04 18:47:30 -08:00
Thom Chiovoloni 6b068437cb
Address address comments, improve comments slightly 2022-02-04 18:47:30 -08:00
Thom Chiovoloni ea211695bf
Optimize io::error::Repr layout on 64 bit targets. 2022-02-04 18:47:30 -08:00
Thom Chiovoloni 554918e311
Hide Repr details from io::Error, and rework io::Error::new_const. 2022-02-04 18:47:29 -08:00
Dan Gohman 7d603dc1b2 x.py fmt 2022-02-04 13:53:58 -08:00
Dan Gohman 4c4e43035f 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`.
2022-02-04 13:41:00 -08:00
Matthias Krüger 9ba09f976c
Rollup merge of #93612 - tspiteri:master, r=m-ou-se
doc: use U+2212 for minus sign in integer MIN/MAX text

Closes #90793.
2022-02-04 18:42:17 +01:00
Matthias Krüger af2886eef9
Rollup merge of #93495 - solid-rs:fix-kmc-solid-rtc-month, r=yaahc
kmc-solid: Fix off-by-one error in `SystemTime::now`

Fixes a miscalculation of `SystemTime`  on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Unlike the identically-named libc counterpart `tm::tm_mon`, `SOLID_RTC_TIME::tm_mon` contains a 1-based month number.
2022-02-04 18:42:14 +01:00
Matthias Krüger 6f03bd09ff
Rollup merge of #91589 - derekdreery:arc_unwrap_or_clone, r=m-ou-se
impl `Arc::unwrap_or_clone`

The function gets the inner value, cloning only if necessary. The conversation started on [`irlo`](https://internals.rust-lang.org/t/arc-into-inner/15707). If the reviewer think the PR has potential to be merged, and does not need an RFC, then I will create the corresponding tracking issues and update the PR.

## Alternative names

 - `into_inner`
 - `make_owned`
 - `make_unique`
 - `take_*` (`take_inner`?)
2022-02-04 18:42:13 +01:00
Trevor Spiteri d6e1df8d59 doc: use U+2212 for minus sign in integer MIN/MAX text 2022-02-04 17:59:53 +01:00
Matthias Krüger ca2ef71e96
Rollup merge of #93585 - tamaroning:add_tests_for_92630, r=m-ou-se
Missing tests for #92630

fixes #93143
2022-02-04 14:59:03 +01: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
Mara Bos c05276ae7b Stabilize pin_static_ref. 2022-02-04 12:27:33 +01:00
Jacob Pratt 1911eb8b61
Add missing const stability attributes 2022-02-03 19:15:57 -05:00
Yuki Okushi 95efb2b578
Rollup merge of #93600 - last-partizan:fix-junit-formatter, r=yaahc
fix: Remove extra newlines from junit output

This PR fixes extra newline in junit output https://github.com/rust-lang/rust/issues/93454
2022-02-03 22:20:28 +09:00
Charles Lew 18130a21dc Move {core,std}::stream::Stream to {core,std}::async_iter::AsyncIterator. 2022-02-03 21:03:06 +08:00
Richard Dodd f5e6d16d00 Add tracking issue and impl for Rc. 2022-02-03 10:40:31 +00:00
Richard Dodd 0602fb0c6e impl Arc::unwrap_or_clone
The function gets the inner value, cloning only if necessary.
2022-02-03 09:16:04 +00: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
Dan Gohman ba6050f742 Remove the documentation comment for OwnedSocket::from_raw_socket.
This function is documented in more detail in the `FromRawSocket` trait.
2022-02-02 16:23:23 -08: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
Serg Tereshchenko 088474a408 fix: Remove extra newlines from junit output 2022-02-02 22:14:03 +02:00
Mark Rousskov 85930c8f44 Configure panic hook backtrace behavior 2022-02-02 13:46:42 -05:00
tamaron 83242897fb add tests 2022-02-02 23:07:02 +09: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
Dan Gohman f88fb2a9a5 x.py fmt 2022-02-01 15:10:59 -08:00
Dan Gohman 656d2a3a12 Use From/Into rather than the traits they replaced. 2022-02-01 14:58:11 -08:00
Dan Gohman 89544e9001 Fix errors. 2022-02-01 14:38:23 -08:00
Dan Gohman 6ef7ee36c2 Fix unresolved doc links. 2022-02-01 14:37:15 -08:00
Dan Gohman 8516895170 Fix two copy+pastos. 2022-02-01 14:27:54 -08:00
Dan Gohman 713bb19ca3 Add missing pub keywords. 2022-02-01 14:23:03 -08:00
Dan Gohman ca42a1bece 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 needed 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-02-01 14:05:43 -08: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
Matthias Krüger a643e59800
Rollup merge of #91828 - oxalica:feat/waker-getters, r=dtolnay
Implement `RawWaker` and `Waker` getters for underlying pointers

implement #87021

New APIs:
- `RawWaker::data(&self) -> *const ()`
- `RawWaker::vtable(&self) -> &'static RawWakerVTable`
- ~`Waker::as_raw_waker(&self) -> &RawWaker`~ `Waker::as_raw(&self) -> &RawWaker`

This third one is an auxiliary function to make the two APIs above more useful. Since we can only get `&Waker` in `Future::poll`, without this, we need to `transmute` it into `&RawWaker` (relying on `repr(transparent)`) in order to access its data/vtable pointers.

~Not sure if it should be named `as_raw` or `as_raw_waker`. Seems we always use `as_<something-raw>` instead of just `as_raw`. But `as_raw_waker` seems not quite consistent with `Waker::from_raw`.~ As suggested in https://github.com/rust-lang/rust/pull/91828#discussion_r770729837, use `as_raw`.
2022-02-01 16:08:02 +01:00
bors 547f2ba06b Auto merge of #86988 - thomcc:chunky-splitz-says-no-checking, r=the8472
Carefully remove bounds checks from some chunk iterator functions

So, I was writing code that requires the equivalent of `rchunks(N).rev()` (which isn't the same as forward `chunks(N)` — in particular, if the buffer length is not a multiple of `N`, I must handle the "remainder" first).

I happened to look at the codegen output of the function (I was actually interested in whether or not a nested loop was being unrolled — it was), and noticed that in the outer `rchunks(n).rev()` loop, LLVM seemed to be unable to remove the bounds checks from the iteration: https://rust.godbolt.org/z/Tnz4MYY8f (this panic was from the split_at in `RChunks::next_back`).

After doing some experimentation, it seems all of the `next_back` in the non-exact chunk iterators have the issue: (`Chunks::next_back`, `RChunks::next_back`, `ChunksMut::next_back`, and `RChunksMut::next_back`)...

Even worse, the forward `rchunks` iterators sometimes have the issue as well (... but only sometimes). For example https://rust.godbolt.org/z/oGhbqv53r has bounds checks, but if I uncomment the loop body, it manages to remove the check (which is bizarre, since I'd expect the opposite...). I suspect it's highly dependent on the surrounding code, so I decided to remove the bounds checks from them anyway. Overall, this change includes:
- All `next_back` functions on the non-`Exact` iterators (e.g. `R?Chunks(Mut)?`).
- All `next` functions on the non-exact rchunks iterators (e.g. `RChunks(Mut)?`).

I wasn't able to catch any of the other chunk iterators failing to remove the bounds checks (I checked iterations over `r?chunks(_exact)?(_mut)?` with constant chunk sizes under `-O3`, `-Os`, and `-Oz`), which makes sense, since these were the cases where it was harder to prove the bounds check correct to remove...

In fact, it took quite a bit of thinking to convince myself that using unchecked_ here was valid — so I'm not really surprised that LLVM had trouble (although compilers are slightly better at this sort of reasoning than humans). A consequence of that is the fact that the `// SAFETY` comment for these are... kinda long...

---

I didn't do this for, or even think about it for, any of the other iteration methods; just `next` and `next_back` (where it mattered). If this PR is accepted, I'll file a follow up for someone (possibly me) to look at the others later (in particular, `nth`/`nth_back` looked like they had similar logic), but I wanted to do this now, as IMO `next`/`next_back` are the most important here, since they're what gets used by the iteration protocol.

---

Note: While I don't expect this to impact performance directly, the panic is a side effect, which would otherwise not exist in these loops. That is, this could prevent the compiler from being able to move/remove/otherwise rework a loop over these iterators (as an example, it could not delete the code for a loop whose body computes a value which doesn't get used).

Also, some like to be able to have confidence this code has no panicking branches in the optimized code, and "no bounds checks" is kinda part of the selling point of Rust's iterators anyway.
2022-02-01 10:11:59 +00: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
Thom Chiovoloni 9c62455e2f
Improve test coverage of {Chunks,RChunks,RChunksMut}::{next,next_back} 2022-01-31 17:35:19 -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
Loïc BRANSTETT a4b93eb188 Take in account the unreachable! macro in the non_fmt_panic lint 2022-01-31 17:09:31 +01:00
Loïc BRANSTETT 565710b33c Fix invalid special casing of the unreachable! macro 2022-01-31 17:09:31 +01:00
bors 86f5e177bc Auto merge of #93498 - matthiaskrgr:rollup-k5shwrc, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #90277 (Improve terminology around "after typeck")
 - #92918 (Allow eliding GATs in expression position)
 - #93039 (Don't suggest inaccessible fields)
 - #93155 (Switch pretty printer to block-based indentation)
 - #93214 (Respect doc(hidden) when suggesting available fields)
 - #93347 (Make `char::DecodeUtf16::size_hist` more precise)
 - #93392 (Clarify documentation on char::MAX)
 - #93444 (Fix some CSS warnings and errors from VS Code)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-31 11:24:03 +00: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 24737bd1ab
Rollup merge of #93485 - est31:remove_curly, r=joshtriplett
core: Remove some redundant {}s from the sorting code
2022-01-31 07:00:46 +01:00
Matthias Krüger b0cdf7e995
Rollup merge of #93480 - est31:remove_unstable_deprecated, r=Mark-Simulacrum
Remove deprecated and unstable slice_partition_at_index functions

They have been deprecated since commit 01ac5a97c9
which was part of the 1.49.0 release, so from the point of nightly,
11 releases ago.
2022-01-31 07:00:45 +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
Matthias Krüger 8fd2ff57fa
Rollup merge of #93403 - nagisa:total-cmp-review, r=joshtriplett
review the total_cmp documentation

The documentation has been restructured to split out a brief summary
paragraph out from the following elaborating paragraphs.

I also attempted my hand at wording improvements and adding articles
where I felt them missing, but being non-native english speaker these
may need more thorough review.

cc https://github.com/rust-lang/rust/issues/72599
2022-01-31 07:00:41 +01:00
Matthias Krüger c03bf54dd1
Rollup merge of #93392 - GKFX:char-docs, r=scottmcm
Clarify documentation on char::MAX

As mentioned in https://github.com/rust-lang/rust/issues/91836#issuecomment-994106874, the documentation on `char::MAX` is not quite correct – USVs are not "only ones within a certain range", they are code points _outside_ a certain range. I have corrected this and given the actual numbers as there is no reason to hide them.
2022-01-31 06:58:32 +01:00
Matthias Krüger 76857fb3fb
Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_hint, r=dtolnay
Make `char::DecodeUtf16::size_hist` more precise

New implementation takes into account contents of `self.buf` and rounds lower bound up instead of down.

Fixes #88762
Revival of #88763
2022-01-31 06:58:31 +01:00
Tomoaki Kawada 175219ad0c kmc-solid: SOLID_RTC_TIME::tm_mon is 1-based 2022-01-31 11:59:13 +09: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
bors e58e7b10e1 Auto merge of #90891 - nbdd0121:format, r=Mark-Simulacrum
Create `core::fmt::ArgumentV1` with generics instead of fn pointer

Split from (and prerequisite of) #90488, as this seems to have perf implication.

`@rustbot` label: +T-libs
2022-01-31 00:04:46 +00:00
George Bateman 9aaf52b66a
(#93392) Update char::MAX docs and core::char::MAX 2022-01-30 23:10:24 +00:00
George Bateman 4d4ec97e0a
Document char validity 2022-01-30 22:16:41 +00:00
Simonas Kazlauskas 78efb075d9 review the total_cmp documentation
The documentation has been restructured to split out a brief summary
paragraph out from the following elaborating paragraphs.

I also attempted my hand at wording improvements and adding articles
where I felt them missing, but being non-native english speaker these
may need more thorough review.
2022-01-30 23:20:54 +02:00
Amanieu d'Antras f738669b63 Clarify safety of PanicInfo::can_unwind 2022-01-30 21:33:51 +01:00
est31 cde240c1e8 core: Remove some redundant {}s from the sorting code 2022-01-30 18:32:24 +01: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
Samuel E. Moelius III 96d96a7ac4 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-01-30 10:25:40 -05:00
est31 105a7461b9 Remove deprecated and unstable slice_partition_at_index functions
They have been deprecated since commit 01ac5a97c9
which was part of the 1.49.0 release, so from the point of nightly,
11 releases ago.
2022-01-30 16:19:03 +01:00
Maybe Waffle 17cd2cd592 Fix an edge case in chat::DecodeUtf16::size_hint
There are cases, when data in the buf might or might not be an error.
2022-01-30 15:32:21 +03: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
ltdk 19645ac05a Add Result::{ok, err, and, or, unwrap_or} as const 2022-01-29 18:37:55 -05: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
Matthias Krüger 6e2593d343
Rollup merge of #93256 - EFanZh:patch-1, r=joshtriplett
Make `join!` description more accurate
2022-01-30 00:04:10 +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
Gary Guo a832f5f7bc Create core::fmt::ArgumentV1 with generics instead of fn pointer 2022-01-29 13:52:19 +00: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
Matthias Krüger 37e9cb34e5
Rollup merge of #93236 - woppopo:const_nonnull_new, r=oli-obk
Make `NonNull::new` `const`

Tracking issue: #93235
2022-01-29 14:46:31 +01:00
Matthias Krüger 9e86a434a7
Rollup merge of #92274 - woppopo:const_deallocate, r=oli-obk
Add `intrinsics::const_deallocate`

Tracking issue: #79597
Related: #91884

This allows deallocation of a memory allocated by `intrinsics::const_allocate`. At the moment, this can be only used to reduce memory usage, but in the future this may be useful to detect memory leaks (If an allocated memory remains after evaluation, raise an error...?).
2022-01-29 14:46:30 +01:00
woppopo 9728cc4e26 Document about some behaviors of const_(de)allocate and add some tests. 2022-01-29 19:13:23 +09: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 27f68212ab
Rollup merge of #93404 - rust-lang:scottmcm-patch-1, r=wesleywiser
Fix a typo from #92899

Just happened to notice this in passing
2022-01-28 15:20:30 +01:00
Matthias Krüger cfe03006b7
Rollup merge of #93356 - pierwill:partialord-headline, r=dtolnay
Edit docs introduction for `std::cmp::PartialOrd`

This makes `PartialOrd` consistent with the other three traits in this module, which all include links to their corresponding mathematical concepts on Wikipedia.

<img width="500" alt="Screen Shot 2022-01-26 at 10 24 23 PM" src="https://user-images.githubusercontent.com/19642016/151291720-decd85ed-cd6e-4be0-84a9-619b98ceb386.png">
2022-01-28 15:20:27 +01:00
Matthias Krüger 25cd639a4b
Rollup merge of #93353 - kellerkindt:saturating_int_assign_impl, r=joshtriplett
Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>

Tracking issue #92354

Analog to 9648b313cc #93208 reduce `saturating_int_assign_impl` (#93208) to:

```rust
let mut value = Saturating(2u8);
value += 3u8;
value -= 1u8;
value *= 2u8;
value /= 2u8;
value %= 2u8;
value ^= 255u8;
value |= 123u8;
value &= 2u8;
```

See https://github.com/rust-lang/rust/pull/93208#issuecomment-1022564429
2022-01-28 15:20:26 +01: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
Matthias Krüger 9f15c4d08b
Rollup merge of #93158 - haraldh:wasi_sock_accept, r=dtolnay
wasi: implement `sock_accept` and enable networking

With the addition of `sock_accept()` to snapshot1, simple networking via a passed `TcpListener` is possible. This PR implements the basics to make a simple server work.

See also:
* [wasmtime tracking issue](https://github.com/bytecodealliance/wasmtime/issues/3730)
* [wasmtime PR](https://github.com/bytecodealliance/wasmtime/pull/3711)

TODO:
* [ ] Discussion of `SocketAddr` return value for `::accept()`

```rust
        Ok((
            TcpStream::from_inner(unsafe { Socket::from_raw_fd(fd as _) }),
            // WASI has no concept of SocketAddr yet
            // return an unspecified IPv4Addr
            SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 0),
        ))
```
2022-01-28 15:20:22 +01:00
Matthias Krüger db6ca25325
Rollup merge of #92611 - Amanieu:asm-reference, r=m-ou-se
Add links to the reference and rust by example for asm! docs and lints

These were previously removed in #91728 due to broken links.

cc ``@ehuss`` since this updates the rust-by-example submodule
2022-01-28 15:20:21 +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
Amanieu d'Antras 9a814b8ba6 Update stdarch submodule 2022-01-28 12:46:22 +00: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
yuhaixin.hx 0b8c9fbf0b add allow_fail field in TestDesc to pass check 2022-01-28 19:40:49 +08:00
yuhaixin.hx 6562069ebe remove allow_fail test flag 2022-01-28 18:31:49 +08:00
Amanieu d'Antras 2188c551cd Move unstable is_{arch}_feature_detected! macros to std::arch 2022-01-28 09:51:46 +00:00
woppopo cdd0873db6 Add a test case for using NonNull::new in const context 2022-01-28 18:41:35 +09:00
Maybe Waffle 2c97d1012e Fix wrong assumption in DecodeUtf16::size_hint
`self.buf` can contain a surrogate, but only a leading one.
2022-01-28 12:40:59 +03:00
woppopo 7a7144f413 test_const_allocate_at_runtime 2022-01-28 17:27:33 +09:00
pierwill 7c7509bc3b Edit docs introduction for std::cmp::PartialOrd
This makes `PartialOrd` consistent with the other three traits in this
module, which all include links to their respective mathematical concepts
on Wikipedia.
2022-01-28 00:46:04 -06:00
Tomoaki Kawada da0d506ace kmc-solid: Implement FileDesc::duplicate 2022-01-28 15:02:44 +09:00
scottmcm 81b4e51c41
Fix a typo from #92899
Just happened to notice this in passing
2022-01-28 01:35:33 +00:00
George Bateman 2fb617ca0f
Clarify documentation on char::MAX 2022-01-27 22:13:01 +00:00
Matthias Krüger 54f357836e
Rollup merge of #92899 - cameron1024:zip-docs, r=dtolnay
Mention std::iter::zip in Iterator::zip docs

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

I'm not sure about the wording. I think it's alright, but happy to change.
2022-01-27 22:32:23 +01: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
David Tolnay 857ea1e7eb
Touch up PR 92899 Iterator::zip docs 2022-01-27 12:41:03 -08: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
Jubilee Young cde7bdc678 Sync rust-lang/portable-simd@03f6fbb21e 2022-01-27 11:23:40 -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
cameron f27758e8d7 mention std::iter::zip in Iterator::zip docs 2022-01-27 06:47:52 +00:00
Dan Gohman 47aaf79554 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`.
2022-01-26 16:27:46 -08:00
Michael Watzko a6c0a3d9c2 Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>
Analog to 9648b313cc #93208
2022-01-26 23:49:54 +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
Matthias Krüger e2b2bfe10c
Rollup merge of #92256 - fee1-dead:improve-selection-err, r=oli-obk
Improve selection errors for `~const` trait bounds
2022-01-26 23:45:22 +01:00
Matthias Krüger 1dd0ac1f6a
Rollup merge of #91861 - juniorbassani:use-from-array-in-collections-examples, r=yaahc
Replace iterator-based construction of collections by `Into<T>`

Just a few quality of life improvements in the doc examples. I also removed some `Vec`s in favor of arrays.
2022-01-26 23:45:19 +01:00
George Burgess IV 4d25c51f69 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
2022-01-26 14:19:29 -08:00
Maybe Waffle 9c8cd1ff37 Add a test for char::DecodeUtf16::size_hint 2022-01-27 00:50:34 +03:00
Maybe Waffle cd4245d318 Make char::DecodeUtf16::size_hist more precise
New implementation takes into account contents of `self.buf` and rounds
lower bound up instead of down.
2022-01-27 00:30:33 +03: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
woppopo 29932db09b const_deallocate: Don't deallocate memory allocated in an another const. Does nothing at runtime.
`const_allocate`:  Returns a null pointer at runtime.
2022-01-26 13:06:09 +09:00
Ralf Jung 53d2401f3f make Windows abort_internal Miri-compatible 2022-01-25 12:44:40 -05:00
Deadbeef 8b76cad0a7
Add a minimal working append_const_msg argument 2022-01-26 00:48:08 +11:00
Chris Denton 84c0c9d20d
Avoid double panics when using TempDir in tests 2022-01-25 10:36:10 +00:00
Nikolai Vazquez fe71c7431a Implement MIN/MAX constants for non-zero integers 2022-01-25 04:29:40 -05:00
Michael Watzko 9648b313cc Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t>
Analog to 1c0dc1810d #92356
2022-01-25 08:43:30 +01:00
Matthias Krüger 687bb583c8
Rollup merge of #88794 - sunfishcode:sunfishcode/try-clone, r=joshtriplett
Add a `try_clone()` function to `OwnedFd`.

As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by
refactoring the code out of the existing `File`/`Socket` code.

r? ``@joshtriplett``
2022-01-25 05:51:09 +01:00
Thomas de Zeeuw c1cd200922 Rename SocketAddr::unix to from_path
And change it to disallow NULL bytes.
2022-01-24 18:02:37 +01:00
Matthias Krüger 144aeedcf3
Rollup merge of #93152 - ivmarkov:master, r=m-ou-se
Fix STD compilation for the ESP-IDF target (regression from CVE-2022-21658)

Commit 54e22eb7db broke the compilation of STD for the ESP-IDF embedded "unix-like" Tier 3 target, because the fix for [CVE-2022-21658](https://blog.rust-lang.org/2022/01/20/Rust-1.58.1.html) uses [libc flags](https://github.com/esp-rs/esp-idf-svc/runs/4892221554?check_suite_focus=true) which are not supported on the ESP-IDF platform.

This PR simply redirects the ESP-IDF compilation to the "classic" implementation, similar to REDOX. This should be safe because:
* Neither of the two filesystems supported by ESP-IDF (spiffs and fatfs) support [symlinks](https://github.com/natevw/fatfs/blob/master/README.md) in the first place
* There is no notion of fs permissions at all, as the ESP-IDF is an embedded platform that does not have the notion of users, groups, etc.
* Similarly, ESP-IDF has just one "process" - the firmware itself - which contains the user code and the "OS" fused together and running with all permissions
2022-01-24 12:29:51 +01:00
Matthias Krüger b92a1e9c20
Rollup merge of #92513 - Xuanwo:path-buf, r=dtolnay
std: Implement try_reserve and try_reserve_exact on PathBuf

Part of https://github.com/rust-lang/rust/issues/91789

Signed-off-by: Xuanwo <github@xuanwo.io>
2022-01-24 12:29:50 +01:00
Chris Denton ac02fcc4d8
Use NtCreateFile instead of NtOpenFile to open a file 2022-01-24 10:00:31 +00:00
EFanZh 571356c24a
Make join! description more accurate 2022-01-24 16:17:40 +08:00
Matthias Krüger bb260e8950
Rollup merge of #92555 - m-ou-se:scoped-threads, r=Amanieu
Implement RFC 3151: Scoped threads.

This implements https://github.com/rust-lang/rfcs/pull/3151

r? `@Amanieu`
2022-01-23 20:13:02 +01:00
Thomas de Zeeuw f2cdb57b94 Add os::unix::net::SocketAddr::unix
Creates a new SocketAddr from a path, supports both regular paths and
abstract namespaces.
2022-01-23 17:11:06 +01:00
woppopo 5e97fc9aa2 Make NonNull::new const 2022-01-23 23:04:39 +09:00
bors 16c1a9dd7c Auto merge of #93220 - matthiaskrgr:rollup-9bkrlk0, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #90666 (Stabilize arc_new_cyclic)
 - #91122 (impl Not for !)
 - #93068 (Fix spacing for `·` between stability and source)
 - #93103 (Tweak `expr.await` desugaring `Span`)
 - #93113 (Unify search input and buttons size)
 - #93168 (update uclibc instructions for new toolchain, add link from platforms doc)
 - #93185 (rustdoc: Make some `pub` items crate-private)
 - #93196 (Remove dead code from build_helper)

Failed merges:

 - #93188 (rustdoc: fix bump down typing search on Safari)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-23 09:16:32 +00:00
woppopo aa6795e2d4 Add intrinsics::const_deallocate 2022-01-23 15:13:44 +09:00
Matthias Krüger 55a1f8b955
Rollup merge of #91122 - dtolnay:not, r=m-ou-se
impl Not for !

The lack of this impl caused trouble for me in some degenerate cases of macro-generated code of the form `if !$cond {...}`, even without `feature(never_type)` on a stable compiler. Namely if `$cond` contains a `return` or `break` or similar diverging expression, which would otherwise be perfectly legal in boolean position, the code previously failed to compile with:

```console
error[E0600]: cannot apply unary operator `!` to type `!`
   --> library/core/tests/ops.rs:239:8
    |
239 |     if !return () {}
    |        ^^^^^^^^^^ cannot apply unary operator `!`
```
2022-01-23 01:09:41 +01:00
Matthias Krüger 59d9ad98b6
Rollup merge of #90666 - bdbai:arc_new_cyclic, r=m-ou-se
Stabilize arc_new_cyclic

This stabilizes feature `arc_new_cyclic` as the implementation has been merged for one year and there is no unresolved questions. The FCP is not started yet.

Closes #75861 .

``@rustbot`` label +T-libs-api
2022-01-23 01:09:40 +01:00
bors 10c4c4afec Auto merge of #92998 - Amanieu:hashbrown12, r=Mark-Simulacrum
Update hashbrown to 0.12.0

[Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md#v0120---2022-01-17)
2022-01-22 23:39:21 +00:00
Mara Bos 465c405418 Add test for thread::Scope invariance. 2022-01-22 17:15:08 +01:00
Mara Bos 00e191c72d
Update stabilization version of arc_new_cyclic 2022-01-22 15:48:42 +00:00
Mara Bos 12cc7d9e15 Add tracking issue number for scoped_threads. 2022-01-22 16:03:23 +01:00
Mara Bos e572c5a3d5 Simplify Send/Sync of std:🧵:Packet. 2022-01-22 16:02:18 +01:00
Matthias Krüger 9d7c8edd6c
Rollup merge of #92828 - Amanieu:unwind-abort, r=dtolnay
Print a helpful message if unwinding aborts when it reaches a nounwind function

This is implemented by routing `TerminatorKind::Abort` back through the panic handler, but with a special flag in the `PanicInfo` which indicates that the panic handler should *not* attempt to unwind the stack and should instead abort immediately.

This is useful for the planned change in https://github.com/rust-lang/lang-team/issues/97 which would make `Drop` impls `nounwind` by default.

### Code

```rust
#![feature(c_unwind)]

fn panic() {
    panic!()
}

extern "C" fn nounwind() {
    panic();
}

fn main() {
    nounwind();
}
```

### Before

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Illegal instruction (core dumped)
```

### After

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'panic in a function that cannot unwind', test.rs:7:1
stack backtrace:
   0:     0x556f8f86ec9b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdccefe11a6ac4396
   1:     0x556f8f88ac6c - core::fmt::write::he152b28c41466ebb
   2:     0x556f8f85d6e2 - std::io::Write::write_fmt::h0c261480ab86f3d3
   3:     0x556f8f8654fa - std::panicking::default_hook::{{closure}}::h5d7346f3ff7f6c1b
   4:     0x556f8f86512b - std::panicking::default_hook::hd85803a1376cac7f
   5:     0x556f8f865a91 - std::panicking::rust_panic_with_hook::h4dc1c5a3036257ac
   6:     0x556f8f86f079 - std::panicking::begin_panic_handler::{{closure}}::hdda1d83c7a9d34d2
   7:     0x556f8f86edc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b70ed0cce71e95f
   8:     0x556f8f865592 - rust_begin_unwind
   9:     0x556f8f85a764 - core::panicking::panic_no_unwind::h2606ab3d78c87899
  10:     0x556f8f85b910 - test::nounwind::hade6c7ee65050347
  11:     0x556f8f85b936 - test::main::hdc6e02cb36343525
  12:     0x556f8f85b7e3 - core::ops::function::FnOnce::call_once::h4d02663acfc7597f
  13:     0x556f8f85b739 - std::sys_common::backtrace::__rust_begin_short_backtrace::h071d40135adb0101
  14:     0x556f8f85c149 - std::rt::lang_start::{{closure}}::h70dbfbf38b685e93
  15:     0x556f8f85c791 - std::rt::lang_start_internal::h798f1c0268d525aa
  16:     0x556f8f85c131 - std::rt::lang_start::h476a7ee0a0bb663f
  17:     0x556f8f85b963 - main
  18:     0x7f64c0822b25 - __libc_start_main
  19:     0x556f8f85ae8e - _start
  20:                0x0 - <unknown>
thread panicked while panicking. aborting.
Aborted (core dumped)
```
2022-01-22 15:32:49 +01:00
Matthias Krüger ffd199d768
Rollup merge of #85967 - atopia:update-l4re-target, r=petrochenkov
add support for the l4-bender linker on the x86_64-unknown-l4re-uclibc tier 3 target

This PR contains the work by ```@humenda``` to update support for the `x86_64-unknown-l4re-uclibc` tier 3 target (published at [humenda/rust](https://github.com/humenda/rust)), rebased and adapted to current rust in follow up commits by myself. The publishing of the rebased changes is authorized and preferred by the original author. As the goal was to distort the original work as little as possible, individual commits introduce changes that are incompatible to the newer code base that the changes were rebased on. These incompatibilities have been remedied in follow up commits, so that the PR as a whole should result in a clean update of the target.
If you prefer another strategy to mainline these changes while preserving attribution, please let me know.
2022-01-22 15:32:48 +01:00
Amanieu d'Antras 537439c177 Disable test_try_reserve on Android 2022-01-22 13:51:57 +00:00
Matthias Krüger 081d65fa4a
Rollup merge of #93134 - tlyu:delete-stdin-split, r=Amanieu
delete `Stdin::split` forwarder

Part of #87096. Delete the `Stdin::split` forwarder because it's seen as too niche to expose at this level.

`@rustbot` label T-libs-api A-io
2022-01-21 22:03:19 +01:00
Matthias Krüger 9474c74fb6
Rollup merge of #93109 - JakobDegen:arc-docs, r=m-ou-se
Improve `Arc` and `Rc` documentation

This makes two changes (I can split the PR if necessary, but the changes are pretty small):
 1. A bunch of trait implementations claimed to be zero cost; however, they use the `Arc<T>: From<Box<T>>` impl which is definitely not free, especially for large dynamically sized `T`.
 2.  The code in deferred initialization examples unnecessarily used excessive amounts of `unsafe`. This has been reduced.
2022-01-21 22:03:18 +01:00
Matthias Krüger 701a8330e8
Rollup merge of #92586 - esp-rs:bugfix/allocation-alignment-espidf, r=yaahc
Set the allocation MIN_ALIGN for espidf to 4.

Closes https://github.com/esp-rs/rust/issues/99.

cc: `@ivmarkov`
2022-01-21 22:03:13 +01:00
Amanieu d'Antras 361a2f9a83 Update HashMap::try_reserve test to version from hashbrown 2022-01-21 17:20:38 +00:00
Amanieu d'Antras 88149d13e3 Update hashbrown to 0.12.0 2022-01-21 17:20:38 +00:00
Benjamin Lamowski 660d993c64 adapt L4Bender implementation
- Fix style errors.

- L4-bender does not yet support dynamic linking.

- Stack unwinding is not yet supported for x86_64-unknown-l4re-uclibc.
  For now, just abort on panics.

- Use GNU-style linker options where possible. As suggested by review:
    - Use standard GNU-style ld syntax for relro flags.
    - Use standard GNU-style optimization flags and logic.
    - Use standard GNU-style ld syntax for --subsystem.

- Don't read environment variables in L4Bender linker. Thanks to
  CARGO_ENCODED_RUSTFLAGS introduced in #9601, l4-bender's arguments can
  now be passed from the L4Re build system without resorting to custom
  parsing of environment variables.
2022-01-21 16:50:33 +01:00
Amanieu d'Antras 24588e6b3a Old versions of Android generate SIGSEGV from libc::abort 2022-01-21 15:44:57 +00:00
Tavian Barnes 3eeb3ca407 fs: Use readdir() instead of readdir_r() on Android
Bionic also guarantees that readdir() is thread-safe enough.
2022-01-21 07:59:14 -05:00
Tavian Barnes bc04a4eac4 fs: Use readdir() instead of readdir_r() on Linux
readdir() is preferred over readdir_r() on Linux and many other
platforms because it more gracefully supports long file names.  Both
glibc and musl (and presumably all other Linux libc implementations)
guarantee that readdir() is thread-safe as long as a single DIR* is not
accessed concurrently, which is enough to make a readdir()-based
implementation of ReadDir safe.  This implementation is already used for
some other OSes including Fuchsia, Redox, and Solaris.

See #40021 for more details.  Fixes #86649.  Fixes #34668.
2022-01-21 07:59:14 -05:00
Tavian Barnes c3e92fec94 fs: Implement more ReadDir methods in terms of name_cstr() 2022-01-21 07:59:14 -05:00
ivmarkov 495c7b31aa Fix STD compilation for the ESP-IDF target 2022-01-21 09:41:13 +02:00
Taylor Yu fdf930ce01 delete Stdin::split forwarder 2022-01-20 15:37:44 -06:00
Matthias Krüger dbc97490bb
Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbini
Fix CVE-2022-21658

See https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html. Patches reviewed by `@m-ou-se.`

r? `@ghost`
2022-01-20 17:10:43 +01:00
Matthias Krüger 1cb57e2d2b
Rollup merge of #92992 - kornelski:backtraceopt, r=Mark-Simulacrum
Help optimize out backtraces when disabled

The comment in `rust_backtrace_env` says:

>    // If the `backtrace` feature of this crate isn't enabled quickly return
>   // `None` so this can be constant propagated all over the place to turn
>  // optimize away callers.

but this optimization has regressed, because the only caller of this function had an alternative path that unconditionally (and pointlessly) asked for a full backtrace, so the disabled state couldn't propagate.

I've added a getter for the full format that respects the feature flag, so that the caller will now be able to really optimize out the disabled backtrace path. I've also made `rust_backtrace_env` trivially inlineable when backtraces are disabled.
2022-01-20 17:10:40 +01:00
Matthias Krüger 98cb33894c
Rollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se
Add MaybeUninit::(slice_)as_bytes(_mut)

This adds methods to convert between `MaybeUninit<T>` and a slice of `MaybeUninit<u8>`. This is safe since `MaybeUninit<u8>` can correctly handle padding bytes in any `T`.

These methods are added:
```rust
impl<T> MaybeUninit<T> {
	pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
	pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
	pub fn slice_as_bytes(this: &[MaybeUninit<T>]) -> &[MaybeUninit<u8>];
	pub fn slice_as_bytes_mut(this: &mut [MaybeUninit<T>]) -> &mut [MaybeUninit<u8>];
}
```
2022-01-20 17:10:30 +01:00
Hans Kratz 0a6c9adc4a
Fix compilation for a few tier 2 targets 2022-01-20 16:35:16 +01:00
Jakob Degen 4de76184aa Remove unnecessary unsafe code in Arc deferred initialization examples. 2022-01-20 06:21:51 -05:00
Jakob Degen 7bc47cfd92 Correct docs in Arc and Rc.
A number of trait implementations incorrectly claimed to be zero cost.
2022-01-20 04:54:03 -05:00
David Tolnay 3136c5f752
Update stabilization version of impl Not for ! 2022-01-19 23:30:55 -08:00
bors 74fbbefea8 Auto merge of #92138 - AngelicosPhosphoros:try_smarter_vec_from_iter_48994_2, r=Mark-Simulacrum
Improve capacity estimation in Vec::from_iter

Iterates on the attempt made in #53086.

Closes #48994
2022-01-20 06:50:14 +00:00