Commit Graph

9669 Commits

Author SHA1 Message Date
Pointerbender
5673536153
fix typos
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-24 04:27:37 +02:00
Michael Howell
ae2b1f096f
Rollup merge of #103447 - ajtribick:maybe_uninit_doc_update, r=scottmcm
`MaybeUninit`: use `assume_init_drop()` in the partially initialized array example

The `assume_init_drop()` method does the same thing as the pointer conversion, and makes the example more straightforward.
2022-10-23 14:48:19 -07:00
Michael Howell
23d1b05726
Rollup merge of #103005 - solid-rs:patch/kmc-solid/readdir-terminator, r=m-ou-se
kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`

Fixes the issue where the `std::fs::ReadDir` implementaton of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets silently suppressed errors returned by the underlying `SOLID_FS_ReadDir` system function. The new implementation correctly handles all cases:

- `SOLID_ERR_NOTFOUND` indicates the end of directory stream.
- `SOLID_ERR_OK` + non-empty `d_name` indicates success.
- Some old filesystem drivers may return `SOLID_ERR_OK` + empty `d_name` to indicate the end of directory stream.
- Any other negative values (per ITRON convention) represent an error.
2022-10-23 14:48:15 -07:00
Michael Howell
214fa9fb9c
Rollup merge of #101644 - Timmmm:file_permissions_docs, r=thomcc
Document surprising and dangerous fs::Permissions behaviour on Unix

This documents the very surprising behaviour that `set_readonly(false)` will make a file *world writable* on Unix. I would go so far as to say that this function should be deprecated on Unix, or maybe even entirely. But documenting the bad behaviour is a good first step.

Fixes #74895
2022-10-23 14:48:14 -07:00
Michael Howell
acc269d65b
Rollup merge of #100462 - zohnannor:master, r=thomcc
Clarify `array::from_fn` documentation

I've seen quite a few of people on social media confused of where the length of array is coming from in the newly stabilized `array::from_fn` example.

This PR tries to clarify the documentation on this.
2022-10-23 14:48:13 -07:00
Gary Guo
4e6d60c837 Fix alloc size 2022-10-23 20:30:16 +01:00
Gary Guo
979d1a2c78 Apply suggestion
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2022-10-23 20:30:16 +01:00
Gary Guo
86c65d2c1c Implement Rust foreign exception protection for EMCC and SEH 2022-10-23 20:30:16 +01:00
Gary Guo
e521a8d46b Prevent foreign Rust exceptions from being caught 2022-10-23 20:30:16 +01:00
bors
7fcf850d79 Auto merge of #103137 - dtolnay:readdir, r=Mark-Simulacrum
Eliminate 280-byte memset from ReadDir iterator

This guy:

1536ab1b38/library/std/src/sys/unix/fs.rs (L589)

It turns out `libc::dirent64` is quite big&mdash;https://docs.rs/libc/0.2.135/libc/struct.dirent64.html. In #103135 this memset accounted for 0.9% of the runtime of iterating a big directory.

Almost none of the big zeroed value is ever used. We memcpy a tiny prefix (19 bytes) into it, and then read just 9 bytes (`d_ino` and `d_type`) back out. We can read exactly those 9 bytes we need directly from the original entry_ptr instead.

## History

This code got added in #93459 and tweaked in #94272 and #94750.

Prior to #93459, there was no memset but a full 280 bytes were being copied from the entry_ptr.

<table><tr><td>copy 280 bytes</td></tr></table>

This was not legal because not all of those bytes might be initialized, or even allocated, depending on the length of the directory entry's name, leading to a segfault. That PR fixed the segfault by creating a new zeroed dirent64 and copying just the guaranteed initialized prefix into it.

<table><tr><td>memset 280 bytes</td><td>copy 19 bytes</td></tr></table>

However this was still buggy because it used `addr_of!((*entry_ptr).d_name)`, which is considered UB by Miri in the case that the full extent of entry_ptr is not in bounds of the same allocation. (Arguably this shouldn't be a requirement, but here we are.)

The UB got fixed by #94272 by replacing `addr_of` with some pointer manipulation based on `offset_from`, but still fundamentally the same operation.

<table><tr><td>memset 280 bytes</td><td>copy 19 bytes</td></tr></table>

Then #94750 noticed that only 9 of those 19 bytes were even being used, so we could pick out only those 9 to put in the ReadDir value.

<table><tr><td>memset 280 bytes</td><td>copy 19 bytes</td><td>copy 9 bytes</td></tr></table>

After my PR we just grab the 9 needed bytes directly from entry_ptr.

<table><tr><td>copy 9 bytes</td></tr></table>

The resulting code is more complex but I believe still worthwhile to land for the following reason. This is an extremely straightforward thing to accomplish in C and clearly libc assumes that; literally just `entry_ptr->d_name`. The extra work in comparison to accomplish it in Rust is not an example of any actual safety being provided by Rust. I believe it's useful to have uncovered that and think about what could be done in the standard library or language to support this obvious operation better.

## References

- https://man7.org/linux/man-pages/man3/readdir.3.html
2022-10-23 18:55:40 +00:00
Josh Stone
15cfeb33b0 Only test pthread_getname_np on linux-gnu 2022-10-23 11:53:39 -07:00
Andrew Tribick
560433ac86 MaybeUninit: use assume_init_drop() in the partially initialized array example 2022-10-23 19:09:18 +02:00
Finn Bear
9f0503e4a6 Fix typo in docs of String::leak. 2022-10-22 12:26:47 -07:00
Dylan DPC
b4536943e3
Rollup merge of #103360 - ChrisDenton:isterm-filetype, r=thomcc
Reduce false positives in msys2 detection

Currently msys2 will be detected by getting the file path and looking to see if it contains the substrings "msys-" and "-ptr" (or "cygwin-" and "-pty"). This risks false positives, especially with filesystem files and if `GetFileInformationByHandleEx` returns a [full path](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntqueryinformationfile#remarks).

This PR adds a check to see if the handle is a pipe before doing the substring search. Additionally, for "msys2-" or "cygwin-" it only checks if the file name starts with the substring rather than looking at the whole path.
2022-10-22 16:28:09 +05:30
Dylan DPC
b22559f547
Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, r=dtolnay
Adjust argument type for mutable with_metadata_of (#75091)

The method takes two pointer arguments: one `self` supplying the pointer value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements. The provenance of the metadata parameter is disregarded completely. Using a mutable pointer in the call site can be coerced to a const pointer while the reverse is not true.

In some cases, the current parameter type can thus lead to a very slightly confusing additional cast. [Example](cad93775eb).

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```

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

``@dtolnay`` you're reviewed #95249, would you mind chiming in?
2022-10-22 16:28:09 +05:30
Dylan DPC
3f49f9506f
Rollup merge of #103329 - saethlin:nonnull-precondition, r=thomcc
Add a forgotten check for NonNull::new_unchecked's precondition

Looks like I forgot this function a while ago in https://github.com/rust-lang/rust/pull/92686

r? ```@thomcc```
2022-10-22 16:28:08 +05:30
Dylan DPC
141478b40f
Rollup merge of #103280 - finnbear:impl_string_leak_2, r=joshtriplett
(#102929) Implement `String::leak` (attempt 2)

Implementation of `String::leak` (#102929)

ACP: https://github.com/rust-lang/libs-team/issues/109

Supersedes #102941 (see previous reviews there)

```@rustbot``` label +T-libs-api -T-libs
2022-10-22 16:28:08 +05:30
Josh Stone
12e45846eb Move truncation next to other thread tests for tidy 2022-10-21 18:13:22 -07:00
Josh Stone
7280f3d28a Truncate thread names on Linux and Apple targets
These targets have system limits on the thread names, 16 and 64 bytes
respectively, and `pthread_setname_np` returns an error if the name is
longer. However, we're not in a context that can propagate errors when
we call this, and we used to implicitly truncate on Linux with `prctl`,
so now we manually truncate these names ahead of time.
2022-10-21 17:44:35 -07:00
bors
8f2c56aec7 Auto merge of #103375 - matthiaskrgr:rollup-4xrs7f2, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #102635 (make `order_dependent_trait_objects` show up in future-breakage reports)
 - #103335 (Replaced wrong test with the correct mcve)
 - #103339 (Fix some typos)
 - #103340 (WinConsole::new is not actually fallible)
 - #103341 (Add test for issue 97607)
 - #103351 (Require Drop impls to have the same constness on its bounds as the bounds on the struct have)
 - #103359 (Remove incorrect comment in `Vec::drain`)
 - #103364 (rustdoc: clean up rustdoc-toggle CSS)
 - #103370 (rustdoc: remove unused CSS `.out-of-band { font-weight: normal }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-21 23:42:01 +00:00
Matthias Krüger
1b2f594f48
Rollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcm
Remove incorrect comment in `Vec::drain`

r? ``@scottmcm``

Turns out this comment wasn't correct for 6 years, since #34951, which switched from using `slice::IterMut` into using `slice::Iter`.
2022-10-22 00:14:03 +02:00
Matthias Krüger
b21eb5e5ba
Rollup merge of #103340 - RalfJung:winconsole, r=thomcc
WinConsole::new is not actually fallible

I just noticed this while reading the code for other reasons.
r? ``@thomcc``
2022-10-22 00:14:01 +02:00
bors
5c8bff74bc Auto merge of #101263 - lopopolo:lopopolo/c-unwind-fn-ptr-impls, r=thomcc
Add default trait implementations for "c-unwind" ABI function pointers

Following up on #92964, only add default trait implementations for the `c-unwind` family of function pointers. The previous attempt in #92964 added trait implementations for many more ABIs and ran into concerns regarding the increase in size of the libcore rlib.

An attempt to abstract away function pointer types behind a unified trait to reduce the duplication of trait impls is being discussed in #99531 but this change looks to be blocked on a lang MCP.

Following `@RalfJung's` suggestion in https://github.com/rust-lang/rust/pull/99531#issuecomment-1233440142, this commit is another cut at #92964 but it _only_ adds the impls for `extern "C-unwind" fn` and `unsafe extern "C-unwind" fn`.

I am interested in landing this patch to unblock the stabilization of the `c_unwind` feature.

RFC: https://github.com/rust-lang/rfcs/pull/2945
Tracking Issue: https://github.com/rust-lang/rust/issues/74990
2022-10-21 20:59:03 +00:00
bors
57e2c06a8d Auto merge of #101077 - sunshowers:signal-mask-inherit, r=sunshowers
Change process spawning to inherit the parent's signal mask by default

Previously, the signal mask was always reset when a child process is
started. This breaks tools like `nohup` which expect `SIGHUP` to be
blocked for all transitive processes.

With this change, the default behavior changes to inherit the signal mask.

This also changes the signal disposition for `SIGPIPE` to only be changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-21 18:09:03 +00:00
Chris Denton
d7b0bcb20f
Reduce false positives in msys2 detection
This checks that:

* the handle is a pipe
* the pipe's file name starts with "msys-" or "cygwin-" rather than looking in the full path.
2022-10-21 18:06:12 +01:00
Maybe Waffle
e97d295d00 Remove incorrect comment in Vec::drain 2022-10-21 15:29:02 +00:00
Andreas Molzer
e3606b2b02 Reduce mutability in std-use of with_metadata_of 2022-10-21 14:49:29 +02:00
Andreas Molzer
71c39dea4d Argument type for mutable with_metadata_of (#75091)
The method takes two pointer arguments: one `self` supplying the pointer
value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements.
The provenance of the metadata parameter is disregarded completely.
Using a mutable pointer in the call site can be coerced to a const
pointer while the reverse is not true.

An example of the current use:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```
2022-10-21 14:46:14 +02:00
Ralf Jung
3ff0a33a83 WinConsole::new is not actually fallible 2022-10-21 12:18:33 +02:00
bors
b1ab3b738a Auto merge of #103308 - sunfishcode:sunfishcode/wasi-io-safety, r=joshtriplett
Mark `std::os::wasi::io::AsFd` etc. as stable.

io_safety was stabilized in Rust 1.63, so mark the io_safety exports in `std::os::wasi::io` as stable.

Fixes #103306.
2022-10-21 04:05:02 +00:00
Ben Kimock
9b6791078a Add a missing precondition check 2022-10-20 20:40:35 -04:00
Rain
a52c79e859 Change process spawning to inherit the parent's signal mask by default
Previously, the signal mask is always reset when a child process is
started. This breaks tools like `nohup` which expect `SIGHUP` to be
blocked.

With this change, the default behavior changes to inherit the signal mask.

This also changes the signal disposition for `SIGPIPE` to only be
changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-20 14:53:38 -07:00
Dan Gohman
7ac645a565 Make the whole std::os::wasi::io module stable. 2022-10-20 14:31:11 -07:00
Matthias Krüger
c6a680ebc5
Rollup merge of #103288 - johnmatthiggins:master, r=thomcc
Fixed docs typo in `library/std/src/time.rs`

* Changed comment from `Previous rust versions panicked when self was earlier than the current time.` to `Previous rust versions panicked when the current time was earlier than self.`
* Resolves #103282.
2022-10-20 22:42:39 +02:00
Matthias Krüger
cfb424a044
Rollup merge of #103281 - thomcc:long-overdue, r=jyn514
Adjust `transmute{,_copy}` to be clearer about which of `T` and `U` is input vs output

This is essentially a documentation-only change (although it does touch code in an irrelevant way).
2022-10-20 22:42:39 +02:00
Dan Gohman
e56b84e844 Mark std::os::wasi::io::AsFd etc. as stable.
io_safety was stabilized in Rust 1.63, so mark the io_safety exports in
`std::os::wasi::io` as stable.

Fixes #103306.
2022-10-20 08:04:19 -07:00
Ryan Lopopolo
efe61dab21
Skip C-unwind fn pointer impls with the bootstrap compiler
These need to wait until #103239 makes it into the bootstrap compiler.
2022-10-20 07:37:17 -07:00
Pointerbender
16104474ad clarify documentation about the memory layout of UnsafeCell 2022-10-20 08:37:47 +02:00
Matthias Krüger
1f210238a0
Rollup merge of #103272 - clubby789:extra-spaces, r=thomcc
Remove extra spaces in docs

Removing some random extra spaces in the examples for `core::sync::atomic`.

r? `@thomcc`
2022-10-20 07:58:57 +02:00
Matthias Krüger
62bb0c6fdd
Rollup merge of #103197 - est31:stabilize_proc_macro_source_text, r=petrochenkov
Stabilize proc_macro::Span::source_text

Splits `proc_macro::Span::source_text` into a new feature gate and stabilizes it. The [FCP is complete](https://github.com/rust-lang/rust/issues/101991#issuecomment-1279393265).

```Rust
impl Span {
    pub fn source_text(&self) -> Option<String>;
}
```

Closes #101991
2022-10-20 07:58:55 +02:00
Thom Chiovoloni
afd08175de
Adjust transmute{,_copy} to be clearer about which of T and U is input vs output 2022-10-19 22:36:14 -07:00
John Higgins
a3ccb193be
Fixed docs typo in library/std/src/time.rs 2022-10-19 21:49:29 -07:00
Ben Kimock
cfcb0a2135 Use a faster allocation size check in slice::from_raw_parts 2022-10-20 00:30:00 -04:00
Ryan Lopopolo
531679684c
Update stability annotations on fnptr impls for C-unwind ABI 2022-10-19 19:17:32 -07:00
Ryan Lopopolo
16dd5737b0
Add default trait implementations for "c-unwind" ABI function pointers
Following up on #92964, only add default trait implementations for the
`c-unwind` family of function pointers. The previous attempt in #92964
added trait implementations for many more ABIs and ran into concerns
regarding the increase in size of the libcore rlib.

An attempt to abstract away function pointer types behind a unified
trait to reduce the duplication of trait impls is being discussed in #99531
but this change looks to be blocked on a lang MCP.

Following @RalfJung's suggestion in
https://github.com/rust-lang/rust/pull/99531#issuecomment-1233440142,
this commit is another cut at #92964 but it _only_ adds the impls for
`extern "C-unwind" fn` and `unsafe extern "C-unwind" fn`.

I am interested in landing this patch to unblock the stabilization of
the `c_unwind` feature.

RFC: https://github.com/rust-lang/rfcs/pull/2945
Tracking Issue: https://github.com/rust-lang/rust/issues/74990
2022-10-19 19:17:32 -07:00
Finn Bear
4f44d6253d Put fn in the right place. 2022-10-19 19:15:58 -07:00
Finn Bear
f81cd87eea Copy of #102941. 2022-10-19 19:07:45 -07:00
Thom Chiovoloni
4b66432268
Update libstd's libc to 0.2.135 2022-10-19 17:54:55 -07:00
clubby789
19bc8fb05a Remove extra spaces 2022-10-19 23:54:00 +01:00
inquisitivecrystal
4a92cf6156 Derive Eq and Hash for ControlFlow 2022-10-19 13:25:34 -07:00
Dylan DPC
d056ea8828
Rollup merge of #103153 - ChrisDenton:leak-oom, r=m-ou-se
Allow `Vec::leak` when using `no_global_oom_handling`

As [the documentation notes](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.leak), `Vec::leak` hasn't allocated since 1.57.

cc `@Ericson2314` in case I'm missing something.
2022-10-19 14:05:53 +05:30
Dylan DPC
f4afb9d9ec
Rollup merge of #103127 - SUPERCILEX:inline-const-uninit, r=scottmcm
Make transpose const and inline

r? `@scottmcm`

- These should have been const from the beginning since we're never going to do more than a transmute.
- Inline these always because that's what every other method in MaybeUninit which simply casts does. :) Ok, but a stronger justification is that because we're taking in arrays by `self`, not inlining would defeat the whole purpose of using `MaybeUninit` due to the copying.
2022-10-19 14:05:52 +05:30
bors
84365fff0a Auto merge of #103225 - matthiaskrgr:rollup-1zkv87y, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #103166 (Optimize `slice_iter.copied().next_chunk()`)
 - #103176 (Fix `TyKind::is_simple_path`)
 - #103178 (Partially fix `src/test/run-make/coverage-reports` when cross-compiling)
 - #103198 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-19 05:41:14 +00:00
Matthias Krüger
d6eb7bca09
Rollup merge of #103166 - the8472:copied-next-chunk, r=m-ou-se
Optimize `slice_iter.copied().next_chunk()`

```
OLD:
test iter::bench_copied_array_chunks                               ... bench:         371 ns/iter (+/- 7)
NEW:
test iter::bench_copied_array_chunks                               ... bench:          31 ns/iter (+/- 0)
```

The default `next_chunk` implementation suffers from having to assemble the array byte by byte via `next()`, checking the `Option<&T>` and then dereferencing `&T`. The specialization copies the chunk directly from the slice.
2022-10-19 07:15:30 +02:00
The 8472
873a18e221 specialize slice_iter.copied().next_chunk() 2022-10-19 00:02:00 +02:00
Matthias Krüger
18431b66ce
Rollup merge of #102507 - scottmcm:more-binary-search-docs, r=m-ou-se
More slice::partition_point examples

After seeing the discussion of `binary_search` vs `partition_point` in #101999, I thought some more example code could be helpful.
2022-10-18 21:18:46 +02:00
Matthias Krüger
d2644e538c
Rollup merge of #101889 - tspiteri:redoc-uint-adc-sbb, r=m-ou-se
doc: rewrite doc for uint::{carrying_add,borrowing_sub}

Reword the documentation for bigint helper methods `uint::{carrying_add,borrowing_sub}` (#85532).

The examples were also rewritten to demonstrate how the methods can be used in bignum arithmetic. No loops are used in the examples, but the variable names were chosen to include indices so that it is clear how this can be used in a loop if required.

Also, previously `carrying_add` had an example to say that if the input carry is false, the method is equivalent to `overflowing_add`. While the note was kept, the example was removed and an extra note was added to make sure this equivalence is not assumed for signed integers as well.
2022-10-18 21:18:46 +02:00
est31
d89fb1dee5 Stabilize proc_macro::Span::source_text
Splits proc_macro::Span::source_text into a new feature gate and stabilizes it.
2022-10-18 17:13:41 +02:00
bors
e94827e5b0 Auto merge of #103188 - JohnTitor:rollup-pwilam1, r=JohnTitor
Rollup of 6 pull requests

Successful merges:

 - #103023 (Adding `fuchsia-ignore` and `needs-unwind` to compiler test cases)
 - #103142 (Make diagnostic for unsatisfied `Termination` bounds more precise)
 - #103154 (Fix typo in `ReverseSearcher` docs)
 - #103159 (Remove the redundant `Some(try_opt!(..))` in `checked_pow`)
 - #103163 (Remove all uses of array_assume_init)
 - #103168 (Stabilize asm_sym)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-18 13:35:43 +00:00
Yuki Okushi
b411b8861c
Rollup merge of #103163 - SUPERCILEX:uninit-array-assume2, r=scottmcm
Remove all uses of array_assume_init

See https://github.com/rust-lang/rust/pull/103134#discussion_r997462733

r? `@scottmcm`
2022-10-18 21:21:32 +09:00
Yuki Okushi
e04bbcb9b1
Rollup merge of #103159 - cuviper:check_pow-final-try_opt, r=Mark-Simulacrum
Remove the redundant `Some(try_opt!(..))` in `checked_pow`

The final return value doesn't need to be tried at all -- we can just
return the checked option directly. The optimizer can probably figure
this out anyway, but there's no need to make it work here.
2022-10-18 21:21:31 +09:00
Yuki Okushi
ba643786b8
Rollup merge of #103154 - H4x5:reverse-searcher-typo, r=Mark-Simulacrum
Fix typo in `ReverseSearcher` docs
2022-10-18 21:21:31 +09:00
Yuki Okushi
472a8742a6
Rollup merge of #103142 - fmease:fix-103052, r=oli-obk
Make diagnostic for unsatisfied `Termination` bounds more precise

Don't blindly emit a diagnostic claiming that “*`main` has an invalid return type*” if we encounter a type that should but doesn't implement `std::process::Termination` and isn't actually the return type of the program entry `main`.

Fixes #103052.

``@rustbot`` label A-diagnostics T-compiler T-libs
r? diagnostics
2022-10-18 21:21:30 +09:00
bors
21b246587c Auto merge of #103075 - SUPERCILEX:miri-metadata, r=thomcc
Support DirEntry metadata calls in miri

This should work as it uses lstat64 which is supported here: ~d9ad25ee4b/src/shims/unix/macos/foreign_items.rs (L42~) just noticed that's macos, linux would be using statx: 86f0e63b21/src/shims/unix/linux/foreign_items.rs (L112)

The failing syscall is `dirfd`, so maybe that should actually be added to the shims?
2022-10-18 10:54:53 +00:00
The 8472
963d6f757c add a benchmark for slice_iter.copied().array_chunks() 2022-10-17 23:40:21 +02:00
Alex Saveau
55d71c61b8
Remove all uses of array_assume_init
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-17 13:03:54 -07:00
bors
06f049a355 Auto merge of #101837 - scottmcm:box-array-from-vec, r=m-ou-se
Add `Box<[T; N]>: TryFrom<Vec<T>>`

We have `[T; N]: TryFrom<Vec<T>>` (#76310) and `Box<[T; N]>: TryFrom<Box<[T]>>`, but not this combination.

`vec.into_boxed_slice().try_into()` isn't quite a replacement for this, as that'll reallocate unnecessarily in the error case.

**Insta-stable, so needs an FCP**

(I tried to make this work with `, A`, but that's disallowed because of `#[fundamental]` https://github.com/rust-lang/rust/issues/29635#issuecomment-1247598385)
2022-10-17 19:46:04 +00:00
Josh Stone
d7fd1d57ec Remove the redundant Some(try_opt!(..)) in checked_pow
The final return value doesn't need to be tried at all -- we can just
return the checked option directly. The optimizer can probably figure
this out anyway, but there's no need to make it work here.
2022-10-17 11:21:50 -07:00
Sky
9a7e527e28
Fix typo in ReverseSearcher docs 2022-10-17 13:14:15 -04:00
Chris Denton
913393a0f7
Allow Vec::leak with no_global_oom_handling 2022-10-17 17:12:32 +01:00
León Orell Valerian Liehr
684df4d24e
Make diagnostic for unsatisfied Termination bounds more precise 2022-10-17 12:08:46 +02:00
David Tolnay
0bb6eb1526
Eliminate 280-byte memset from ReadDir iterator 2022-10-16 23:43:35 -07:00
Thayne McCombs
63a7fdf61b Fix types in documentation for Alignment::as_usize and Alignmnet::as_nonzero 2022-10-16 23:44:06 -06:00
Alex Saveau
1a1ebb080f
Make transpose const and inline
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-16 17:51:38 -07:00
Matthias Krüger
0602d6484b
Rollup merge of #103109 - RalfJung:phantom-data-impl, r=thomcc
PhantomData: inline a macro that is used only once

I suspect this macro used to have more uses, but right now it just obfuscates the code.
2022-10-16 22:36:06 +02:00
Matthias Krüger
bdfc262742
Rollup merge of #103102 - H4x5:len_utf16_docs, r=scottmcm
Clarify the possible return values of `len_utf16`

`char::len_utf16` always return 1 or 2. Clarify this in the docs, in the same way as `char::len_utf8`.
2022-10-16 22:36:06 +02:00
Matthias Krüger
e31ae4f9c0
Rollup merge of #103087 - phimuemue:btreemap_append_doc, r=Mark-Simulacrum
Documentation BTreeMap::append's behavior for already existing keys

`BTreeMap::append` overwrites existing values with new ones. This commit adds explicit documentation for that.
2022-10-16 22:36:05 +02:00
Alex Saveau
727335878d
Support DirEntry metadata calls in miri
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-16 12:14:27 -07:00
Sky
a6372525ce
Clarify the possible return values of len_utf16 2022-10-16 11:06:19 -04:00
Ralf Jung
73d655e9c2 remove redundant Send impls for references
also move them next to the trait they are implementing
2022-10-16 11:34:24 +02:00
Ralf Jung
ddd5e983d1 PhantomData: inline a macro that is used only once 2022-10-16 10:37:51 +02:00
Yuki Okushi
166f664037
Rollup merge of #102023 - SUPERCILEX:maybeuninit-transpose, r=scottmcm
Add MaybeUninit array transpose From impls

See discussion in https://github.com/rust-lang/rust/pull/101179 and https://github.com/rust-lang/rust/issues/96097. I believe this solution offers the simplest implementation with minimal future API regret.

`@RalfJung` mind doing a correctness review?
2022-10-16 11:41:12 +09:00
Yuki Okushi
cbc0a73c95
Rollup merge of #101717 - Pointerbender:unsafecell-memory-layout, r=Amanieu
Add documentation about the memory layout of `UnsafeCell<T>`

The documentation for `UnsafeCell<T>` currently does not make any promises about its memory layout. This PR adds this documentation, namely that the memory layout of `UnsafeCell<T>` is the same as the memory layout of its inner `T`.

# Use case
Without this layout promise, the following cast would not be legally possible:

```rust
fn example<T>(ptr: *mut T) -> *const UnsafeCell<T> {
  ptr as *const UnsafeCell<T>
}
```

A use case where this can come up involves FFI. If Rust receives a pointer over a FFI boundary which provides shared read-write access (with some form of custom synchronization), and this pointer is managed by some Rust struct with lifetime `'a`, then it would greatly simplify its (internal) API and safety contract if a `&'a UnsafeCell<T>` can be created from a raw FFI pointer `*mut T`. A lot of safety checks can be done when receiving the pointer for the first time through FFI (non-nullness, alignment, initialize uninit bytes, etc.) and these properties can then be encoded into the `&UnsafeCell<T>` type. Without this documentation guarantee, this is not legal today outside of the standard library.

# Caveats
Casting in the opposite direction is still not valid, even with this documentation change:

```rust
fn example2<T>(ptr: &UnsafeCell<T>) -> &mut T {
  let t = ptr as *const UnsafeCell<T> as *mut T;
  unsafe { &mut *t }
}
```

This is because the only legal way to obtain a mutable pointer to the contents of the shared reference is through [`UnsafeCell::get`](https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html#method.get) and [`UnsafeCell::raw_get`](https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html#method.raw_get). Although there might be a desire to also make this legal at some point in the future, that part is outside the scope of this PR. Also see this relevant [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/transmuting.20.26.20-.3E.20.26mut).

# Alternatives
Instead of adding a new documentation promise, it's also possible to add a new method to `UnsafeCell<T>` with signature `pub fn from_ptr_bikeshed(ptr: *mut T) -> *const UnsafeCell<T>` which indirectly only allows one-way casting to `*const UnsafeCell<T>`.
2022-10-16 11:41:12 +09:00
Alex Saveau
393434c29e
Add MaybeUninit array transpose impls
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-15 15:57:19 -07:00
bors
ddc7fd9837 Auto merge of #100579 - joboet:sync_mutex_everywhere, r=thomcc
std: use `sync::Mutex` for internal statics

Since `sync::Mutex` is now `const`-constructible, it can be used for internal statics, removing the need for `sys_common::StaticMutex`. This adds some extra allocations on platforms which need to box their mutexes (currently SGX and some UNIX), but these will become unnecessary with the lock improvements tracked in #93740.

I changed the program argument implementation on Hermit, it does not need `Mutex` but can use atomics like some UNIX systems (ping `@mkroening` `@stlankes).`
2022-10-15 22:49:30 +00:00
Scott McMurray
5b9a02a87d More slice::partition_point examples 2022-10-15 14:03:56 -07:00
Ryan Lopopolo
95040a70d7
Stabilize duration_checked_float
Tracking issue:

- https://github.com/rust-lang/rust/issues/83400
2022-10-15 12:02:13 -07:00
philipp
4854e37dbc Documentation BTreeMap::append's behavior for already existing keys 2022-10-15 17:47:07 +02:00
Dylan DPC
cbe5e7bc62
Rollup merge of #102773 - joboet:apple_parker, r=thomcc
Use semaphores for thread parking on Apple platforms

Currently we use a mutex-condvar pair for thread parking on Apple systems. Unfortunately, `pthread_cond_timedwait` uses the real-time clock for measuring time, which causes problems when the system time changes. The parking implementation in this PR uses a semaphore instead, which measures monotonic time by default, avoiding these issues. As a further benefit, this has the potential to improve performance a bit, since `unpark` does not need to wait for a lock to be released.

Since the Mach semaphores are poorly documented (I could not find availability or stability guarantees for instance), this uses a [dispatch semaphore](https://developer.apple.com/documentation/dispatch/dispatch_semaphore?language=objc) instead. While it adds a layer of indirection (it uses Mach semaphores internally), the overhead is probably negligible.

Tested on macOS 12.5.

r? ``````@thomcc``````
2022-10-15 15:45:30 +05:30
bors
8154955321 Auto merge of #98033 - joshtriplett:is-terminal-fd-handle, r=thomcc
Add `IsTerminal` trait to determine if a descriptor or handle is a terminal

The UNIX implementation uses `isatty`. The Windows implementation uses
the same logic the `atty` crate uses, including the hack needed to
detect msys terminals.

Implement this trait for `Stdin`/`Stdout`/`Stderr`/`File` on all
platforms. On Unix, implement it for `BorrowedFd`/`OwnedFd`. On Windows,
implement it for `BorrowedHandle`/`OwnedHandle`.

Based on https://github.com/rust-lang/rust/pull/91121

Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-15 01:42:28 +00:00
Josh Triplett
97d438cd31 Use Align8 to avoid misalignment if the allocator or Vec doesn't align allocations 2022-10-15 00:35:39 +01:00
Josh Triplett
6a79da9ab7 Rewrite FILE_NAME_INFO handling to avoid enlarging slice reference
Rather than referencing a slice's pointer and then creating a new slice
with a longer length, offset from the base structure pointer instead.
This makes some choices of Rust semantics happier.
2022-10-15 00:35:39 +01:00
Josh Triplett
e25fe564d1 Make is_terminal fail fast if a process has no console at all
If a process has no console, it'll have NULL in place of a console
handle, so return early with `false` in that case without making any OS
calls.
2022-10-15 00:35:38 +01:00
Josh Triplett
326ef470a8 Add IsTerminal trait to determine if a descriptor or handle is a terminal
The UNIX and WASI implementations use `isatty`. The Windows
implementation uses the same logic the `atty` crate uses, including the
hack needed to detect msys terminals.

Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and
their locked counterparts on all platforms. On UNIX and WASI, implement
it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for
`BorrowedHandle`/`OwnedHandle`.

Based on https://github.com/rust-lang/rust/pull/91121

Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-15 00:35:38 +01:00
bors
8147e6e427 Auto merge of #103069 - matthiaskrgr:rollup-xxsx6sk, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #102092 (refactor: use grep -E/-F instead of fgrep/egrep)
 - #102781 (Improved documentation for `std::io::Error`)
 - #103017 (Avoid dropping TLS Key on sgx)
 - #103039 (checktools: fix comments)
 - #103045 (Remove leading newlines from integer primitive doc examples)
 - #103047 (Update browser-ui-test version to fix some flaky tests)
 - #103054 (Clean up rust-logo rustdoc GUI test)
 - #103059 (Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`)
 - #103067 (More alphabetical sorting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-14 22:56:53 +00:00
Matthias Krüger
a96f1a8a1e
Rollup merge of #103067 - Nilstrieb:tidy-likes-the-alphabet, r=jackh726
More alphabetical sorting

Sort and enforce a few more things. The biggest change here is sorting all target features.
2022-10-14 23:43:46 +02:00
Matthias Krüger
03a521b4fe
Rollup merge of #103059 - beetrees:duration-from-negative-zero, r=thomcc
Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`

Make `Duration::{try_,}from_secs_f{32,64}(-0.0)` return `Duration::ZERO` (as they did before #90247) instead of erroring/panicking.

I'll update this PR to remove the `#![feature(duration_checked_float)]` if #102271 is merged before this PR.

Tracking issue for `try_from_secs_f{32,64}`: #83400
2022-10-14 23:43:46 +02:00
Matthias Krüger
1a5d8a5c59
Rollup merge of #103045 - lukas-code:blank-lines, r=GuillaumeGomez
Remove leading newlines from integer primitive doc examples

fixes https://github.com/rust-lang/rust/issues/103043

```@rustbot``` label +A-docs
2022-10-14 23:43:44 +02:00
Matthias Krüger
d47b755683
Rollup merge of #103017 - fortanix:raoul/sgx_tls_fix, r=ChrisDenton
Avoid dropping TLS Key on sgx

#102655 reenabled dropping thread local `Key` on every platform ([library/std/src/sys_common/thread_local_key.rs](fa0ca783f8 (diff-5cb9acf9e243f35c975fa9fbac4885519dc104626bc03610dfa7a20bc79641ceL237-R215))). That's causing problems at least for sgx.

cc: `@jethrogb` `@ChrisDenton`
2022-10-14 23:43:43 +02:00
Matthias Krüger
fbb0c31544
Rollup merge of #102781 - StackOverflowExcept1on:master, r=joshtriplett
Improved documentation for `std::io::Error`
2022-10-14 23:43:43 +02:00
bors
bf15a9e526 Auto merge of #101030 - woppopo:const_location, r=scottmcm
Constify `Location` methods

Tracking issue: #102911

Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4789884c2f16ec4fb0e0405d86b794f5
2022-10-14 20:15:51 +00:00
nils
b00cb04037
Sort target features alphabetically 2022-10-14 22:01:18 +02:00
nils
3c0062641d
Add some tidy-alphabetical 2022-10-14 21:18:03 +02:00
bors
5819f419a7 Auto merge of #102783 - RalfJung:tls, r=thomcc
sync thread_local key conditions exactly with what the macro uses

This makes the `cfg` in `mod.rs` syntactically the same as those in `local.rs`.

I don't think this should actually change anything, but seems better to be consistent?
I looked into this due to https://github.com/rust-lang/rust/issues/102549, but this PR would make it *less* likely that `__OsLocalKeyInner` is going to get provided, so this cannot help with that issue.

r? `@thomcc`
2022-10-14 16:43:46 +00:00
Raoul Strackx
c46185bea0 Bugfix: keep TLS data in sync 2022-10-14 17:07:18 +02:00
beetrees
c9948f5c5f
Fix Duration::{try_,}from_secs_f{32,64}(-0.0) 2022-10-14 16:07:09 +01:00
bors
ee1c3b385b Auto merge of #102529 - colinba:master, r=joshtriplett
Detect and reject out-of-range integers in format string literals

Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results.

When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc.

Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize.

Fixes #102528
2022-10-14 13:41:40 +00:00
Josh Triplett
f95e853222
Tweak grammar 2022-10-14 12:17:07 +01:00
Dylan DPC
77064b7f0a
Rollup merge of #103018 - Rageking8:more-dupe-word-typos, r=TaKO8Ki
More dupe word typos

I only picked those changes (from the regex search) that I am pretty certain doesn't change meaning and is just a typo fix. Do correct me if any fix is undesirable and I can revert those. Thanks.
2022-10-14 16:19:15 +05:30
Dylan DPC
b03bece6f3
Rollup merge of #102847 - joshtriplett:bugfix-impl-fd-traits-for-io-types, r=m-ou-se
impl AsFd and AsRawFd for io::{Stdin, Stdout, Stderr}, not the sys versions

https://github.com/rust-lang/rust/pull/100892 implemented AsFd for the
sys versions, rather than for the public types. Change the
implementations to apply to the public types.
2022-10-14 16:19:12 +05:30
Lukas Markeffsky
b8bb40664c remove leading newlines from integer primitive doc examples 2022-10-14 12:14:29 +02:00
Rageking8
7122abaddf more dupe word typos 2022-10-14 12:57:56 +08:00
bors
6b3ede3f7b Auto merge of #103009 - Dylan-DPC:rollup-9c2tng6, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #102765 (Suggest `==` to the first expr which has `ExprKind::Assign` kind)
 - #102854 (openbsd: don't reallocate a guard page on the stack.)
 - #102904 (Print return-position `impl Trait` in trait verbosely if `-Zverbose`)
 - #102947 (Sort elaborated existential predicates in `object_ty_for_trait`)
 - #102956 (Use `full_res` instead of `expect_full_res`)
 - #102999 (Delay `is_intrinsic` query until after we've determined the callee is a function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-13 14:59:39 +00:00
Dylan DPC
376c81c94a
Rollup merge of #102854 - semarie:openbsd-immutablestack, r=m-ou-se
openbsd: don't reallocate a guard page on the stack.

the kernel currently enforce that a stack is immutable. calling mmap(2) or  mprotect(2) to change it will result in EPERM, which generate a panic!().

so just do like for Linux, and trust the kernel to do the right thing.
2022-10-13 18:19:19 +05:30
Ralf Jung
594838d132 smarter way to avoid 'unused' warning when building for tests 2022-10-13 14:09:08 +02:00
Ralf Jung
600ac6959a sync thread_local key conditions exactly with what the macro uses 2022-10-13 14:09:08 +02:00
bors
4891d57f7a Auto merge of #102919 - luojia65:update-stdarch, r=Amanieu
library: update stdarch submodule

It has been one month since we update `stdarch`  submodule into main branch Rust, it includes various fixes in code and more neat documents. This pull request also adds missing features to ensure we can build latest stdarch submodule.

The documents after this pull request:
<details>

![图片](https://user-images.githubusercontent.com/40385009/195123337-a6c4cfaa-a7b9-4574-b524-c43683e6540c.png)
</details>

Comparing to current nightly:
<details>

![图片](https://user-images.githubusercontent.com/40385009/195123430-e047cff1-a925-4d2d-ae1c-da9769383a9c.png)
</details>

r? `@Amanieu`
2022-10-13 12:03:46 +00:00
joboet
2d2c9e4493
std: use sync::Mutex for internal statics 2022-10-13 12:55:14 +02:00
bors
fa0ca783f8 Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDenton
Optimize TLS on Windows

This implements the suggestion in the current TLS code to embed the linked list of destructors in the `StaticKey` structure to save allocations. Additionally, locking is avoided when no destructor needs to be run. By using one Windows-provided `Once` per key instead of a global lock, locking is more finely-grained (this unblocks #100579).
2022-10-13 06:49:29 +00:00
Tomoaki Kawada
76bec177bc kmc-solid: Handle errors returned by SOLID_FS_ReadDir 2022-10-13 15:10:23 +09:00
bors
3cf5fc58d5 Auto merge of #102995 - JohnTitor:rollup-yomkwge, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #102641 (Support casting boxes to dyn*)
 - #102836 (rustc_target: Fix json target specs using LLD linker flavors in link args)
 - #102949 (should-skip-this: add missing backslash)
 - #102967 (Add test for issue 102964)
 - #102971 (tidy: error if a lang feature is already present)
 - #102974 (Fix small word dupe typos)
 - #102980 (rustdoc: merge separate `.item-info` CSS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-13 03:33:40 +00:00
luojia65
59fea7ecf4 library: update stdarch submodule
add feature target_feature_11 and riscv_target_feature
2022-10-13 09:41:16 +08:00
Yuki Okushi
0ace46f98c
Rollup merge of #102974 - Rageking8:fix-small-word-dupe-typos, r=JohnTitor
Fix small word dupe typos
2022-10-13 09:41:27 +09:00
bors
2a9217601c Auto merge of #102372 - abrown:issue-102157, r=thomcc
Allow compiling the `wasm32-wasi` std library with atomics

The issue #102157 demonstrates how currently the `-Z build-std` option will fail when re-compiling the standard library with `RUSTFLAGS` like `RUSTFLAGS="-C target-feature=+atomics,+bulk-memory -C link-args=--shared-memory"`. This change attempts to resolve those build issues by depending on the the WebAssembly `futex` module and providing an implementation for `env_lock`. Fixes #102157.
2022-10-13 00:37:28 +00:00
Pointerbender
ddd119b2fe expand documentation on type conversion w.r.t. UnsafeCell 2022-10-12 23:34:13 +02:00
Rageking8
d1982bd0af fix small word dupe typos 2022-10-13 00:53:46 +08:00
bors
538f118da1 Auto merge of #102732 - RalfJung:assert_unsafe_precondition2, r=bjorn3
nicer errors from assert_unsafe_precondition

This makes the errors shown by cargo-careful nicer, and since `panic_no_unwind` is `nounwind noreturn` it hopefully doesn't have bad codegen impact. Thanks to `@bjorn3` for the hint!

Would be nice if we could somehow supply our own (static) message to print, currently it always prints `panic in a function that cannot unwind`. But still, this is better than before.
2022-10-12 14:39:43 +00:00
Markus Reiter
36dbb07daf
Update docs for CStr::from_ptr. 2022-10-12 13:46:20 +02:00
Markus Reiter
328f81713c
Make CStr::from_ptr const. 2022-10-12 13:01:30 +02:00
bors
50f6d337c6 Auto merge of #102460 - flba-eb:fix_85261_prevent_alloc_after_fork, r=thomcc
Prevent UB in child process after calling libc::fork

After calling libc::fork, the child process tried to access a TLS variable when processing a panic. This caused a memory allocation which is UB in the child.
To prevent this from happening, the panic handler will not access the TLS variable in case `panic::always_abort` was called before.

Fixes #85261 (not only on Android systems, but also on Linux/QNX with TLS disabled, see issue for more details)

Main drawbacks of this fix:
* Panic messages can incorrectly omit `core::panic::PanicInfo` struct in case several panics (of multiple threads) occur at the same time. The handler cannot distinguish between multiple panics in different threads or recursive ones in the same thread, but the message will contain a hint about the uncertainty.
* `panic_count::increase()` will be a bit slower as it has an additional `if`, but this should be irrelevant as it is only called in case of a panic.
2022-10-12 10:51:31 +00:00
bors
e6ce5627a9 Auto merge of #102948 - Dylan-DPC:rollup-j8h74rb, r=Dylan-DPC
Rollup of 8 pull requests

Successful merges:

 - #102110 (Migrate rustc_passes diagnostics)
 - #102187 (Use correct location for type tests in promoted constants)
 - #102239 (Move style guide to rust-lang/rust)
 - #102578 (Panic for invalid arguments of `{integer primitive}::ilog{,2,10}` in all modes)
 - #102811 (Use memset to initialize readbuf)
 - #102890 (Check representability in adt_sized_constraint)
 - #102913 (unify `IsPattern` and `IsImport` enum in `show_candidates`)
 - #102924 (rustdoc: remove unused classes from sidebar links)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-12 06:57:24 +00:00
Dylan DPC
658169b7db
Rollup merge of #102811 - the8472:bufread-memset, r=m-ou-se
Use memset to initialize readbuf

The write loop was found to be slow in #102727

The proper fix is in #102760 but this might still help debug builds and code running under miri by using the write_bytes intrinsic instead of writing one byte at a time.
2022-10-12 11:11:25 +05:30
Dylan DPC
d8091f8991
Rollup merge of #102578 - lukas-code:ilog-panic, r=m-ou-se
Panic for invalid arguments of `{integer primitive}::ilog{,2,10}` in all modes

Decision made in https://github.com/rust-lang/rust/issues/100422#issuecomment-1245864700

resolves https://github.com/rust-lang/rust/issues/100422

tracking issue: https://github.com/rust-lang/rust/issues/70887

r? `@m-ou-se`
2022-10-12 11:11:25 +05:30
bors
2b91cbe2d4 Auto merge of #102692 - nnethercote:TokenStreamBuilder, r=Aaron1011
Remove `TokenStreamBuilder`

`TokenStreamBuilder` is used to combine multiple token streams. It can be removed, leaving the code a little simpler and a little faster.

r? `@Aaron1011`
2022-10-12 03:46:16 +00:00
Ralf Jung
38c78a9ac1 reorder panicking.rs to put main entry points at the top 2022-10-11 22:47:31 +02:00
Ralf Jung
b61e742a39 use panic_fmt_nounwind for assert_unsafe_precondition 2022-10-11 22:47:31 +02:00
Ralf Jung
66282cb47d add panic_fmt_nounwind for panicing without unwinding, and use it for panic_no_unwind 2022-10-11 22:47:31 +02:00
Ralf Jung
2b50cd1877 rename rustc_allocator_nounwind to rustc_nounwind 2022-10-11 22:47:31 +02:00
Andrew Brown
95b0b2d349 fix: return type of single-threaded dummy lock must be droppable 2022-10-11 11:42:44 -07:00
Matthias Krüger
ccde95f489
Rollup merge of #102869 - azdavis:master, r=joshtriplett
Add basename and dirname aliases

Users might be used to the POSIX names of these functions. In fact, here's a [blog post][1] about this very thing.

[1]: https://boinkor.net/2019/07/basename-and-dirname-in-rust/
2022-10-11 18:59:49 +02:00
Matthias Krüger
1b1223df9f
Rollup merge of #102685 - nbdd0121:unwind, r=m-ou-se
Interpret EH actions properly

The EH actions stored in the LSDA follows the format of GCC except table (even for LLVM-generated code). An missing action in the table is the encoding for `Terminate`, see https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_personality.cc#L522-L526.

The currently code interprets it as `None`, as a workaround for #35011, an issue that seems to occur in LLVM 3.7 and not after 3.9. These are very old versions of LLVM and we don't support them anymore, so remove this workaround and interpret them properly.

Note that LLVM currently does not emit any `Terminate` actions, but GCC does. Although GCC backend currently doesn't do unwinding, removing it preemptively would prevent future developers from wasting time to figure out what's wrong.

``@rustbot`` label: +T-compiler
2022-10-11 18:59:49 +02:00
Matthias Krüger
d10b47ef69
Rollup merge of #102445 - jmillikin:cstr-is-empty, r=Mark-Simulacrum
Add `is_empty()` method to `core::ffi::CStr`.

ACP: https://github.com/rust-lang/libs-team/issues/106

Tracking issue: https://github.com/rust-lang/rust/issues/102444
2022-10-11 18:59:48 +02:00
Matthias Krüger
51320b3a16
Rollup merge of #102227 - devnexen:solarish_get_path, r=m-ou-se
fs::get_path solarish version.

similar to linux, albeit there is no /proc/self notion on solaris
 based system thus flattening the difference for simplification sake.
2022-10-11 18:59:47 +02:00
Matthias Krüger
d13f7aef70
Rollup merge of #101774 - Riolku:atomic-update-aba, r=m-ou-se
Warn about safety of `fetch_update`

Specifically as it relates to the ABA problem.

`fetch_update` is a useful function, and one that isn't provided by, say, C++. However, this does not mean the function is magic. It is implemented in terms of `compare_exchange_weak`, and in particular, suffers from the ABA problem. See the following code, which is a naive implementation of `pop` in a lock-free queue:

```rust
fn pop(&self) -> Option<i32> {
    self.front.fetch_update(Ordering::Relaxed, Ordering::Acquire, |front| {
        if front == ptr::null_mut() {
            None
        }
        else {
            Some(unsafe { (*front).next })
        }
    }.ok()
}
```

This code is unsound if called from multiple threads because of the ABA problem. Specifically, suppose nodes are allocated with `Box`. Suppose the following sequence happens:

```
Initial: Queue is X -> Y.

Thread A: Starts popping, is pre-empted.
Thread B: Pops successfully, twice, leaving the queue empty.
Thread C: Pushes, and `Box` returns X (very common for allocators)
Thread A: Wakes up, sees the head is still X, and stores Y as the new head.
```

But `Y` is deallocated. This is undefined behaviour.

Adding a note about this problem to `fetch_update` should hopefully prevent users from being misled, and also, a link to this common problem is, in my opinion, an improvement to our docs on atomics.
2022-10-11 18:59:46 +02:00
Matthias Krüger
cadb37a8c7
Rollup merge of #101727 - est31:stabilize_map_first_last, r=m-ou-se
Stabilize map_first_last

Stabilizes the following functions:

```Rust
impl<T> BTreeSet<T> {
    pub fn first(&self) -> Option<&T> where T: Ord;
    pub fn last(&self) -> Option<&T> where T: Ord;
    pub fn pop_first(&mut self) -> Option<T> where T: Ord;
    pub fn pop_last(&mut self) -> Option<T> where T: Ord;
}

impl<K, V> BTreeMap<K, V> {
    pub fn first_key_value(&self) -> Option<(&K, &V)> where K: Ord;
    pub fn last_key_value(&self) -> Option<(&K, &V)> where K: Ord;
    pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord;
    pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord;
    pub fn pop_first(&mut self) -> Option<(K, V)> where K: Ord;
    pub fn pop_last(&mut self) -> Option<(K, V)> where K: Ord;
}
```

Closes #62924

~~Blocked on the [FCP](https://github.com/rust-lang/rust/issues/62924#issuecomment-1179489929) finishing.~~ Edit: It finished!
2022-10-11 18:59:46 +02:00
Yuki Okushi
b380518691
Rollup merge of #102625 - Rageking8:fix-backtrace-small-typo, r=m-ou-se
fix backtrace small typo
2022-10-11 18:37:54 +09:00
Yuki Okushi
919d6bf446
Rollup merge of #102589 - RalfJung:scoped-threads-dangling, r=m-ou-se
scoped threads: pass closure through MaybeUninit to avoid invalid dangling references

The `main` function defined here looks roughly like this, if it were written as a more explicit stand-alone function:
```rust
// Not showing all the `'lifetime` tracking, the point is that
// this closure might live shorter than `thread`.
fn thread(control: ..., closure: impl FnOnce() + 'lifetime) {
    closure();
    control.signal_done();
    // A lot of time can pass here.
}
```
Note that `thread` continues to run even after `signal_done`! Now consider what happens if the `closure` captures a reference of lifetime `'lifetime`:
- The type of `closure` is a struct (the implicit unnameable closure type) with a `&'lifetime mut T` field. References passed to a function are marked with `dereferenceable`, which is LLVM speak for *this reference will remain live for the entire duration of this function*.
- The closure runs, `signal_done` runs. Then -- potentially -- this thread gets scheduled away and the main thread runs, seeing the signal and returning to the user. Now `'lifetime` ends and the memory the reference points to might be deallocated.
- Now we have UB! The reference that as passed to `thread` with the promise of remaining live for the entire duration of the function, actually got deallocated while the function still runs. Oops.

Long-term I think we should be able to use `ManuallyDrop` to fix this without `unsafe`, or maybe a new `MaybeDangling` type. I am working on an RFC for that. But in the mean time it'd be nice to fix this so that Miri with `-Zmiri-retag-fields` (which is needed for "full enforcement" of all the LLVM flags we generate) stops erroring on scoped threads.

Fixes https://github.com/rust-lang/rust/issues/101983
r? `@m-ou-se`
2022-10-11 18:37:54 +09:00
Yuki Okushi
e0954cadc8
Rollup merge of #102412 - joboet:dont_panic, r=m-ou-se
Never panic in `thread::park` and `thread::park_timeout`

fixes #102398

`@rustbot` label +T-libs +T-libs-api
2022-10-11 18:37:53 +09:00
Yuki Okushi
387df55f26
Rollup merge of #102277 - mgeisler:rwlock, r=m-ou-se
Consistently write `RwLock`

Before the documentation sometimes referred to an "rwlock" and sometimes to "`RwLock`".
2022-10-11 18:37:52 +09:00
Yuki Okushi
ff903bbb71
Rollup merge of #102258 - cjgillot:core-kappa, r=m-ou-se
Remove unused variable in float formatting.
2022-10-11 18:37:52 +09:00