Commit Graph

10197 Commits

Author SHA1 Message Date
Kai Luo
34534152f5 [LSDA] Take ttype_index into account when taking action
If cs_action != 0, we should check the ttype_index field in
action record. If ttype_index == 0, a clean up action is taken.
2023-01-04 18:00:09 +08:00
bors
b435960c4c Auto merge of #95644 - WaffleLapkin:str_split_as_str_refactor_take2, r=Amanieu
`Split*::as_str` refactor

I've made this patch almost a year ago, so the rename and the behavior change are in one commit, sorry 😅

This fixes #84974, as it's required to make other changes work.

This PR
- Renames `as_str` method of string `Split*` iterators to `remainder` (it seems like the `as_str` name was confusing to users)
- Makes `remainder` return `Option<&str>`, to distinguish between "the iterator is exhausted" and "the tail is empty", this was [required on the tracking issue](https://github.com/rust-lang/rust/issues/77998#issuecomment-832696619)

r? `@m-ou-se`
2023-01-03 11:06:08 +00:00
Michael Goulet
da1ca5df6e
Rollup merge of #104298 - tbu-:pr_set_extension_caveats, r=m-ou-se
Add notes and examples about non-intuitive `PathBuf::set_extension` behavior

Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension.
2023-01-02 15:39:16 -08:00
David Tolnay
257e766c0c
Remove test of static Context
Context is no longer Sync so this doesn't work.

    error[E0277]: `*mut ()` cannot be shared between threads safely
      --> library/core/tests/task.rs:24:21
       |
    24 |     static CONTEXT: Context<'static> = Context::from_waker(&WAKER);
       |                     ^^^^^^^^^^^^^^^^ `*mut ()` cannot be shared between threads safely
       |
       = help: within `Context<'static>`, the trait `Sync` is not implemented for `*mut ()`
       = note: required because it appears within the type `PhantomData<*mut ()>`
       = note: required because it appears within the type `Context<'static>`
       = note: shared static variables must have a type that implements `Sync`
2023-01-02 10:33:23 -08:00
James Higgins
fd59b628ea
Add PhantomData marker to Context to make Context !Send and !Sync 2023-01-02 10:20:59 -08:00
Kornel
3a6ceeb18f Document a way to limit read_line length 2023-01-01 18:04:26 +00:00
Kornel
1a983536f3 Document read_line gotcha 2023-01-01 17:49:05 +00:00
Matthias Krüger
4bf9cae080
Rollup merge of #106280 - Ezrashaw:path-join-docs-better, r=thomcc
docs: add link to `Path::join` in `PathBuf::push`

Fixes #106219

Hopefully my wording is alright.
2022-12-31 23:51:34 +01:00
bors
dd01a163c1 Auto merge of #106275 - Nilstrieb:const-eval-select-me-some-compile-time, r=thomcc
Use some more `const_eval_select` in pointer methods for compile times

Builds on top of #105435

`is_aligned_to` is _huge_ with calling `align_offset`, so this should cut it down a lot.

This shows up in https://github.com/rust-lang/rust/issues/65031#issuecomment-1367574340
2022-12-31 17:19:10 +00:00
Michael Goulet
5b74a33b8d
Rollup merge of #106248 - dtolnay:revertupcastlint, r=jackh726
Revert "Implement allow-by-default `multiple_supertrait_upcastable` lint"

This is a clean revert of #105484.

I confirmed that reverting that PR fixes the regression reported in #106247. ~~I can't say I understand what this code is doing, but maybe it can be re-landed with a different implementation.~~ **Edit:** https://github.com/rust-lang/rust/issues/106247#issuecomment-1367174384 has an explanation of why #105484 ends up surfacing spurious `where_clause_object_safety` errors. The implementation of `where_clause_object_safety` assumes we only check whether a trait is object safe when somebody actually uses that trait with `dyn`. However the implementation of `multiple_supertrait_upcastable` added in the problematic PR involves checking *every* trait for whether it is object-safe.

FYI `@nbdd0121` `@compiler-errors`
2022-12-30 21:26:34 -08:00
Michael Goulet
ff3326d925
Rollup merge of #105903 - joboet:unify_parking, r=m-ou-se
Unify id-based thread parking implementations

Multiple platforms currently use thread-id-based parking implementations (NetBSD and SGX[^1]). Even though the strategy does not differ, these are duplicated for each platform, as the id is encoded into an atomic thread variable in different ways for each platform.

Since `park` is only called by one thread, it is possible to move the thread id into a separate field. By ensuring that the field is only written to once, before any other threads access it, these accesses can be unsynchronized, removing any restrictions on the size and niches of the thread id.

This PR also renames the internal `thread_parker` modules to `thread_parking`, as that name now better reflects their contents. I hope this does not add too much reviewing noise.

r? `@m-ou-se`

`@rustbot` label +T-libs

[^1]: SOLID supports this as well, I will switch it over in a follow-up PR.
2022-12-30 21:26:33 -08:00
Tobias Bucher
40916ef88f Add notes and examples about non-intuitive PathBuf::set_extension behavior
Basically, passing the empty string will actually remove the extension
instead of setting it to the empty string. This might change what is
considered to be an extension. Additionally, passing an extension that
contains dots will make the path only consider the last part of it to be
the new extension.
2022-12-31 00:56:43 +01:00
bors
ce85c98575 Auto merge of #105651 - tgross35:once-cell-inline, r=m-ou-se
Add #[inline] markers to once_cell methods

Added inline markers to all simple methods under the `once_cell` feature. Relates to #74465 and  #105587

This should not block #105587
2022-12-30 19:22:33 +00:00
bors
bbdca4c28f Auto merge of #106296 - matthiaskrgr:rollup-ukdbqwx, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #99244 (doc: clearer and more correct Iterator::scan)
 - #103707 (Replace libstd, libcore, liballoc terminology in docs)
 - #104182 (`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation.)
 - #106273 (rustdoc: remove redundant CSS `.source .content { overflow: visible }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-30 16:10:00 +00:00
Matthias Krüger
bd20fc1fd6
Rollup merge of #104182 - gabhijit:ipv6-in6addr-any-doc-fix, r=m-ou-se
`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation.

Added documentation for IPv6 Addresses `IN6ADDR_ANY_INIT` also known as `in6addr_any` and `IN6ADDR_LOOPBACK_INIT` also known as `in6addr_loopback` similar to `INADDR_ANY` for IPv4 Addresses.
2022-12-30 17:01:39 +01:00
Matthias Krüger
25b1f1c26d
Rollup merge of #103707 - jonathanCogan:master, r=m-ou-se
Replace libstd, libcore, liballoc terminology in docs

Fixes #103551.  I changed line comments containing the outdated terms as well.

It would be great if someone with more experience could weigh in on whether these changes introduce ambiguity as suggested in https://github.com/rust-lang/rust/issues/103551#issuecomment-1291225315.
2022-12-30 17:01:39 +01:00
Matthias Krüger
80e309f798
Rollup merge of #99244 - gthb:doc-improve-iterator-scan, r=m-ou-se
doc: clearer and more correct Iterator::scan

The `Iterator::scan` documentation seemed a little misleading to my newcomer
eyes, and this tries to address that.

* I found “similar to `fold`” unhelpful because (a) the similarity is only that
  they maintain state between iterations, and (b) the _dissimilarity_ is no less
  important: one returns a final value and the other an iterator. So this
  replaces that with “which, like `fold`, holds internal state, but unlike
  `fold`, produces a new iterator.

* I found “the return value from the closure, an `Option`, is yielded by the
  iterator” to be downright incorrect, because “yielded by the iterator” means
  “returned by the `next` method wrapped in `Some`”, so this implied that `scan`
  would convert an input iterator of `T` to an output iterator of `Option<T>`.
  So this replaces “yielded by the iterator” with “returned by the `next`
  method” and elaborates: “Thus the closure can return `Some(value)` to yield
  `value`, or `None` to end the iteration.”

* This also changes the example to illustrate the latter point by returning
  `None` to terminate the iteration early based on `state`.
2022-12-30 17:01:38 +01:00
Nilstrieb
a8f50453d0 Use some more const_eval_select in pointer methods for compile times 2022-12-30 16:39:58 +01:00
joboet
898302e685
std: remove unnecessary #[cfg] on NetBSD 2022-12-30 15:50:31 +01:00
joboet
9abda03da6
std: rename Parker::new to Parker::new_in_place, add safe Parker::new constructor for SGX 2022-12-30 15:49:47 +01:00
jonathanCogan
78691e3589 Update paths in comments. 2022-12-30 14:00:42 +01:00
jonathanCogan
db47071df2 Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
jonathanCogan
72067c77bd Replace libstd, libcore, liballoc in docs. 2022-12-30 14:00:40 +01:00
bors
7c991868c6 Auto merge of #105426 - flba-eb:fix_tls_destructor_unwinding, r=m-ou-se
Catch panics/unwinding in destruction of TLS values

`destroy_value` is/can be called from C code (libc). Unwinding from Rust to C code is undefined behavior, which is why unwinding is caught here.

This problem caused an infinite loop inside the unwinding code when running `src/test/ui/threads-sendsync/issue-24313.rs` on a tier 3 target (QNX/Neutrino) on aarch64.

See also https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Infinite.20unwinding.20bug.
2022-12-30 12:58:50 +00:00
Ezra Shaw
2c4ecffb77
docs: add link to Path::join in PathBuf::push 2022-12-30 14:24:12 +13:00
bors
973a4db8d5 Auto merge of #106210 - fee1-dead-contrib:const-closure-trait-method, r=compiler-errors
Allow trait method paths to satisfy const Fn bounds

r? `@oli-obk`
2022-12-30 01:09:31 +00:00
joboet
3076f4ec30
std: pass hint to id-based parking functions 2022-12-29 17:54:09 +01:00
joboet
a9e5c1a309
std: unify id-based thread parking implementations 2022-12-29 17:45:07 +01:00
David Tolnay
06ec0bf8b0
Revert "Implement allow-by-default multiple_supertrait_upcastable lint"
This reverts commit 5e44a65517.
2022-12-29 00:47:23 -08:00
bors
6ad8383451 Auto merge of #105590 - solid-rs:patch/kmc-solid/thread-lifecycle-ordering, r=m-ou-se
kmc-solid: Fix memory ordering in thread operations

Fixes two memory ordering issues in the thread state machine (`ThreadInner::lifecycle`) of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

1. When detaching a thread that is still running (i.e., the owner updates `lifecycle` first, and the child updates it next), the first update did not synchronize-with the second update, resulting in a data race between the first update and the deallocation of `ThreadInner` by the child thread.
2. When joining on a thread, the joiner has to pass its own task ID to the joinee in order to be woken up later, but in doing so, it did not synchronize-with the read operation, creating possible sequences of execution where the joinee wakes up an incorrect or non-existent task.

Both issue are theoretical and most likely have never manifested in practice because of the stronger guarantees provided by the Arm memory model (particularly due to its barrier-based definition). Compiler optimizations could have subverted this, but the inspection of compiled code did not reveal such optimizations taking place.
2022-12-29 04:22:25 +00:00
bors
b15ca6635f Auto merge of #105741 - pietroalbini:pa-1.68-nightly, r=Mark-Simulacrum
Bump master bootstrap compiler

This PR bumps the bootstrap compiler to the beta created earlier this week, cherry-picks the stabilization version number updates, and updates the `cfg(bootstrap)`s.

r? `@Mark-Simulacrum`
2022-12-29 01:24:26 +00:00
Matthias Krüger
89ccd704f0
Rollup merge of #106161 - meithecatte:iter-find-position, r=Mark-Simulacrum
Iterator::find: link to Iterator::position in docs for discoverability
2022-12-28 22:22:21 +01:00
Matthias Krüger
d28ef9dbf1
Rollup merge of #105998 - RalfJung:no-unwind-panic-msg, r=thomcc
adjust message on non-unwinding panic

"thread panicked while panicking" is just plain wrong in case this is a non-unwinding panic, such as
- a panic out of a `nounwind` function
- the sanity checks we have in `mem::uninitialized` and `mem::zeroed`
- the optional debug assertion in various unsafe std library functions
2022-12-28 22:22:21 +01:00
Matthias Krüger
0b7ed65c13
Rollup merge of #105497 - albertlarsan68:doc-panic-hook-and-catch-unwind, r=m-ou-se
Clarify `catch_unwind` docs about panic hooks

Makes it clear from `catch_unwind` docs that the panic hook will be called before the panic is caught.

Fixes #105432
2022-12-28 22:22:19 +01:00
Matthias Krüger
22060f20ae
Rollup merge of #105359 - flba-eb:thread_local_key_sentinel_value, r=m-ou-se
Make sentinel value configurable in `library/std/src/sys_common/thread_local_key.rs`

This is an excerpt of a changeset for the QNX/Neutrino OS. To make the patch for QNX smaller and easier to review, I've extracted this change (which is OS independent). I would be surprised if no other OS is also affected.

All this patch does is to define a `const` for a sentinel value instead of using it directly at several places.

There are OSs that always return the lowest free value. The algorithm in `lazy_init` always avoids keys with the sentinel value.
In affected OSs, this means that each call to `lazy_init` will always request two keys from the OS and returns/frees the first one (with sentinel value) immediately afterwards.

By making the sentinel value configurable, affected OSs can use a different value than zero to prevent this performance issue.

On QNX/Neutrino, it is planned to use a different sentinel value:
```rust
// Define a sentinel value that is unlikely to be returned
// as a TLS key (but it may be returned).
#[cfg(not(target_os = "nto"))]
const KEY_SENTVAL: usize = 0;
// On QNX/Neutrino, 0 is always returned when currently not in use.
// Using 0 would mean to always create two keys and remote the first
// one (with value of 0) immediately afterwards.
#[cfg(target_os = "nto")]
const KEY_SENTVAL: usize = libc::PTHREAD_KEYS_MAX + 1;
```

It seems like no other OS defines `PTHREAD_KEYS_MAX` in Rusts libc, but `limits.h` on unix systems does.
2022-12-28 22:22:18 +01:00
Matthias Krüger
2dd2fb728e
Rollup merge of #104493 - adamncasey:cgroupzeroperiod, r=m-ou-se
available_parallelism: Gracefully handle zero value cfs_period_us

There seem to be some scenarios where the cgroup cpu quota field `cpu.cfs_period_us` can contain `0`. This field is used to determine the "amount" of parallelism suggested by the function `std:🧵:available_parallelism`

A zero value of this field cause a panic when `available_parallelism()` is invoked. This issue was detected by the call from binaries built by `cargo test`. I really don't feel like `0` is a good value for `cpu.cfs_period_us`, but I also don't think applications should panic if this value is seen.

This panic started happening with rust 1.64.0.

This case is gracefully handled by other projects which read this information: [num_cpus](e437b9d908/src/linux.rs (L207-L210)), [ninja](https://github.com/ninja-build/ninja/pull/2174/files), [dotnet](c4341d45ac/src/coreclr/pal/src/misc/cgroup.cpp (L481-L483))

Before this change, running `cargo test` in environments configured as described above would trigger this panic:
```
$ RUST_BACKTRACE=1 cargo test
    Finished test [unoptimized + debuginfo] target(s) in 3.55s
     Running unittests src/main.rs (target/debug/deps/x-9a42e145aca2934d)
thread 'main' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:546:70
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: std::sys::unix:🧵:cgroups::quota
   4: std::sys::unix:🧵:available_parallelism
   5: std:🧵:available_parallelism
   6: test::helpers::concurrency::get_concurrency
   7: test::console::run_tests_console
   8: test::test_main
   9: test::test_main_static
  10: x::main
             at ./src/main.rs:1:1
  11: core::ops::function::FnOnce::call_once
             at /tmp/rust-1.64-1.64.0-1/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: test failed, to rerun pass '--bin x'
```

I've tested this change in an environment which has the bad (questionable?) setup and rebuilding the test executable against a fixed std library fixes the panic.
2022-12-28 22:22:18 +01:00
Matthias Krüger
d91432832e
Rollup merge of #104402 - joboet:sync_remutex, r=m-ou-se
Move `ReentrantMutex` to `std::sync`

If I understand #84187 correctly, `sys_common` should not contain platform-independent code, even if it is private.
2022-12-28 22:22:17 +01:00
Florian Bartels
04a6f22f79
Catch panics in destruction of TLS values
`destroy_value` is/can be called from C code (libc). Unwinding
from Rust to C code is undefined behavior, which is why unwinding
is caught here.
2022-12-28 18:32:41 +01:00
Albert Larsan
cb7c8993b9
Clarify catch_unwind docs about panic hooks
Makes it clear from catch_unwind docs that the panic hook will be called
before the panic is caught.
2022-12-28 16:54:42 +01:00
Lukas Markeffsky
9480314416 fix custom mir doc tests 2022-12-28 09:18:43 -05:00
Lukas Markeffsky
f4ff423d67 fix documenting private items of standard library 2022-12-28 09:18:43 -05:00
Lukas Markeffsky
fdf6cc34b2 delete more cfg(bootstrap) 2022-12-28 09:18:43 -05:00
Pietro Albini
11191279b7 Update bootstrap cfg 2022-12-28 09:18:43 -05:00
Pietro Albini
f6762c2035 update stabilization version numbers 2022-12-28 09:18:42 -05:00
Matthias Krüger
31f5e753fb
Rollup merge of #106172 - estebank:suggest-impl-trait, r=compiler-errors
Suggest `impl Iterator` when possible for `_` return type

Address #106096.
2022-12-28 14:40:00 +01:00
bors
6a20f7df57 Auto merge of #106209 - fee1-dead-contrib:rollup-47ysdcu, r=fee1-dead
Rollup of 9 pull requests

Successful merges:

 - #94145 (Test leaking of BinaryHeap Drain iterators)
 - #103945 (Remove `iter::Empty` hack)
 - #104024 (Fix `unused_must_use` warning for `Box::from_raw`)
 - #104708 (Fix backoff doc to match implementation)
 - #105347 (Account for `match` expr in single line)
 - #105484 (Implement allow-by-default `multiple_supertrait_upcastable` lint)
 - #106184 (Fix `core::any` docs)
 - #106201 (Emit fewer errors on invalid `#[repr(transparent)]` on `enum`)
 - #106205 (Remove some totally duplicated files in `rustc_infer`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-28 10:10:09 +00:00
Ralf Jung
b804c0d5a5 adjust message on non-unwinding panic 2022-12-28 10:38:04 +01:00
Deadbeef
983606d367 Allow trait method paths to satisfy const Fn bounds 2022-12-28 09:06:31 +00:00
fee1-dead
45d6f02ea5
Rollup merge of #106184 - albertlarsan68:docs-106154, r=Nilstrieb
Fix `core::any` docs

Thanks to ``@pbevin`` in #106154

Closes #106154

``@rustbot`` labels +A-docs
2022-12-28 15:51:42 +08:00
fee1-dead
8b3d0c4cf9
Rollup merge of #105484 - nbdd0121:upcast, r=compiler-errors
Implement allow-by-default `multiple_supertrait_upcastable` lint

The lint detects when an object-safe trait has multiple supertraits.

Enabled in libcore and liballoc as they are low-level enough that many embedded programs will use them.

r? `@nikomatsakis`
2022-12-28 15:51:41 +08:00