Commit graph

24728 commits

Author SHA1 Message Date
Samuel Tardieu
1724af9f1e
Rollup merge of #144872 - connortsui20:once-poison-docs, r=Amanieu
Document Poisoning in `LazyCell` and `LazyLock`

Currently, there is no documentation of poisoning behavior in either `LazyCell` or `LazyLock`, even though both of them can be observed as poisoned by users.

`LazyCell` [plagyround example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=9cf38b8dc56db100848f54085c2c697d)

`LazyLock` [playground example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f1cd6f9fe16636e347ebb695a0ce30c0)

# Open Questions

- [x] Is it worth making the implementation of `LazyLock` more complicated to ensure that the the panic message is `"LazyLock instance has previously been poisoned"` instead of `"Once instance has previously been poisoned"`? See the `LazyLock` playground link above for more context.
- [x] Does it make sense to move `LazyLock` into the `poison` module? It is certainly a poison-able type, but at the same time it is slightly different from the 4 other types currently in the `poison` module in that it is unrecoverable. I think this is more of a libs-api question.

``@rustbot`` label +T-libs-api

Please let me know if these open questions deserve a separate issue / PR!
2025-08-05 03:51:38 +02:00
Samuel Tardieu
db7ac64997
Rollup merge of #144867 - scottmcm:more-as-array, r=chenyukang
Use `as_array` in PartialEq for arrays

Now that `as_array` exists we might as well use it here, since it's a bit more convenient than getting the correct type out of `try_into`.
2025-08-05 03:51:38 +02:00
Samuel Tardieu
d2fcd71be6
Rollup merge of #144852 - Kivooeo:rename-panic, r=m-ou-se
Rename `rust_panic_without_hook` to `resume_unwind`

part of https://github.com/rust-lang/rust/issues/116005

r? libs
2025-08-05 03:51:37 +02:00
Stuart Cook
7fbb303147
Rollup merge of #144853 - Kivooeo:rust_-cleanup, r=Mark-Simulacrum
Remove unnecessary `rust_` prefixes

part of https://github.com/rust-lang/rust/issues/116005

Honestly, not sure if this can affect linking somehow, also I didn't touched things like `__rust_panic_cleanup` and `__rust_start_panic` which very likely will break something, so just small cleanup here

also didn't changed `rust_panic_without_hook` because it was renamed here https://github.com/rust-lang/rust/pull/144852

r? libs
2025-08-04 11:24:42 +10:00
Stuart Cook
f6b4e45be7
Rollup merge of #144667 - scottmcm:alignment-is-usize, r=tgross35
`AlignmentEnum` should just be `repr(usize)` now

These used to use specific sizes because they were compiled on all widths.  But now that the types themselves are `#[cfg]`'d, we can save some conversions by having it always be `repr(usize)`.
2025-08-04 11:24:38 +10:00
Stuart Cook
e65201ccb8
Rollup merge of #144188 - joshtriplett:available-parallelism, r=Mark-Simulacrum
`available_parallelism`: Add documentation for why we don't look at `ulimit`
2025-08-04 11:24:36 +10:00
Stuart Cook
625b180035
Rollup merge of #142205 - paolobarbolini:const_swap_with_slice-impl, r=Mark-Simulacrum
Mark `slice::swap_with_slice` unstably const

Tracking issue rust-lang/rust#142204
2025-08-04 11:24:35 +10:00
Connor Tsui
96adb7df96
add poisoning documentation to LazyLock 2025-08-03 22:57:08 +02:00
Connor Tsui
37922fc24c
add poisoning documentation to LazyCell 2025-08-03 22:57:07 +02:00
Connor Tsui
cf3865f7a5
fix broken doc section link in poison.rs 2025-08-03 22:57:07 +02:00
Samuel Tardieu
d0d648d764
Rollup merge of #144843 - rust-lang:cargo_update, r=clubby789
Weekly `cargo update`

Automation to keep dependencies in `Cargo.lock` current.
r? dep-bumps

The following is the output from `cargo update`:

```txt

compiler & tools dependencies:
     Locking 14 packages to latest compatible versions
    Updating clap v4.5.41 -> v4.5.42
    Updating clap_builder v4.5.41 -> v4.5.42
    Updating jsonpath-rust v1.0.3 -> v1.0.4
    Updating libredox v0.1.6 -> v0.1.9
    Updating object v0.37.1 -> v0.37.2
    Updating redox_syscall v0.5.16 -> v0.5.17
    Updating redox_users v0.5.0 -> v0.5.2
    Updating rustc-demangle v0.1.25 -> v0.1.26
    Updating serde_json v1.0.141 -> v1.0.142
    Updating wasm-encoder v0.235.0 -> v0.236.0
    Updating wasmparser v0.235.0 -> v0.236.0
    Updating wast v235.0.0 -> v236.0.0
    Updating wat v1.235.0 -> v1.236.0
    Updating windows-targets v0.53.2 -> v0.53.3
note: pass `--verbose` to see 36 unchanged dependencies behind latest

library dependencies:
     Locking 3 packages to latest compatible versions
    Updating object v0.37.1 -> v0.37.2
    Updating rustc-demangle v0.1.25 -> v0.1.26
    Updating unwinding v0.2.7 -> v0.2.8
note: pass `--verbose` to see 2 unchanged dependencies behind latest

rustbook dependencies:
     Locking 6 packages to latest compatible versions
    Updating cc v1.2.30 -> v1.2.31
    Updating clap v4.5.41 -> v4.5.42
    Updating clap_builder v4.5.41 -> v4.5.42
    Updating redox_syscall v0.5.16 -> v0.5.17
    Updating serde_json v1.0.141 -> v1.0.142
    Updating windows-targets v0.53.2 -> v0.53.3
```
2025-08-03 21:57:01 +02:00
Samuel Tardieu
116619fb81
Rollup merge of #144070 - stifskere:feat/macros/hash_map, r=Noratrieb
Implement `hash_map` macro

Implementation of https://github.com/rust-lang/rust/issues/144032

Implements the `hash_map` macro under `std/src/macros.rs`.
2025-08-03 21:56:55 +02:00
Scott McMurray
eee28138b8 Use as_array in PartialEq for arrays 2025-08-03 12:47:11 -07:00
Kivooeo
3aeeae6d44 remove rust_ prefixes 2025-08-03 23:25:36 +05:00
Kivooeo
754654d5a9 rename rust_panic_without_hook 2025-08-03 17:59:37 +05:00
github-actions
97435739ff cargo update
compiler & tools dependencies:
     Locking 14 packages to latest compatible versions
    Updating clap v4.5.41 -> v4.5.42
    Updating clap_builder v4.5.41 -> v4.5.42
    Updating jsonpath-rust v1.0.3 -> v1.0.4
    Updating libredox v0.1.6 -> v0.1.9
    Updating object v0.37.1 -> v0.37.2
    Updating redox_syscall v0.5.16 -> v0.5.17
    Updating redox_users v0.5.0 -> v0.5.2
    Updating rustc-demangle v0.1.25 -> v0.1.26
    Updating serde_json v1.0.141 -> v1.0.142
    Updating wasm-encoder v0.235.0 -> v0.236.0
    Updating wasmparser v0.235.0 -> v0.236.0
    Updating wast v235.0.0 -> v236.0.0
    Updating wat v1.235.0 -> v1.236.0
    Updating windows-targets v0.53.2 -> v0.53.3
note: pass `--verbose` to see 36 unchanged dependencies behind latest

library dependencies:
     Locking 3 packages to latest compatible versions
    Updating object v0.37.1 -> v0.37.2
    Updating rustc-demangle v0.1.25 -> v0.1.26
    Updating unwinding v0.2.7 -> v0.2.8
note: pass `--verbose` to see 2 unchanged dependencies behind latest

rustbook dependencies:
     Locking 6 packages to latest compatible versions
    Updating cc v1.2.30 -> v1.2.31
    Updating clap v4.5.41 -> v4.5.42
    Updating clap_builder v4.5.41 -> v4.5.42
    Updating redox_syscall v0.5.16 -> v0.5.17
    Updating serde_json v1.0.141 -> v1.0.142
    Updating windows-targets v0.53.2 -> v0.53.3
2025-08-03 00:27:18 +00:00
Samuel Tardieu
5e1ea9cda4
Rollup merge of #144797 - nilehmann:safety-comment-niche, r=Noratrieb
Update safety comment for new_unchecked in niche_types

Change the safety comment on `new_unchecked` to mention the valid range instead of 0. I noticed this while working on https://github.com/model-checking/verify-rust-std
2025-08-02 11:24:29 +02:00
Samuel Tardieu
d082ff4c04
Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu
Improve formatting of doc code blocks

We don't currently apply automatic formatting to doc comment code blocks. As a
result, it has built up various idiosyncracies, which make such automatic
formatting difficult. Some of those idiosyncracies also make things harder for
human readers or other tools.

This PR makes a few improvements to doc code formatting, in the hopes of making
future automatic formatting easier, as well as in many cases providing net
readability improvements.

I would suggest reading each commit separately, as each commit contains one
class of changes.
2025-08-02 11:24:24 +02:00
Samuel Tardieu
ce1961bbfc
Rollup merge of #144185 - purplesyringa:poisoning-wording, r=Amanieu
Document guarantees of poisoning

This mostly documents the current behavior of `Mutex` and `RwLock` (rust-lang/rust#143471) as imperfect. It's unlikely that the situation improves significantly in the future, and even if it does, the rules will probably be more complicated than "poisoning is completely reliable", so this is a conservative guarantee.

We also explicitly specify that `OnceLock` never poisons, even though it has an API similar to mutexes.

Fixes rust-lang/rust#143471 by improving documentation.

r? ``@Amanieu``
2025-08-02 11:24:22 +02:00
Samuel Tardieu
96b3b83299
Rollup merge of #143771 - Randl:const-result, r=tgross35
Constify some more `Result` functions
2025-08-02 11:24:22 +02:00
stifskere
066023e47c
feat: implement hash_map! macro 2025-08-02 01:32:52 +02:00
Nico Lehmann
4c7c9de8ac Fix safety comment for new_unchecked in niche_types 2025-08-01 14:00:56 -07:00
Evgenii Zheltonozhskii
9377e0af52 Constify additional Result functions 2025-08-01 08:55:50 +03:00
Jacob Pratt
3f5f045fa7
Rollup merge of #144683 - tgross35:builtins-via-std-workspace, r=bjorn3,Noratrieb
Simplify library dependencies on `compiler-builtins`

The three panic-related library crates need to have access to `core`, and `compiler-builtins` needs to be in the crate graph. Rather than specifying both dependencies, switch these crates to use `rustc-std-workspace-core` which already does this.

This means there is now a single place that the `compiler-builtins` dependency needs to get configured, for everything other than `alloc` and `std`.

The second commit removes `compiler-builtins` from `std` (more details in the message).
2025-08-01 00:38:19 -04:00
Trevor Gross
42bf044ce8 Remove std's dependency on compiler-builtins
`compiler-builtins` is already in the crate graph via `alloc`, and all
features related to `compiler-builtins` goes through `alloc`. There
isn't any reason that `std` needs this direct dependency, so remove it.
2025-07-31 22:47:24 +00:00
Trevor Gross
daf353461b Use core via rustc-std-workspace-core in library/panic*
The three panic-related library crates need to have access to `core`,
and `compiler-builtins` needs to be in the crate graph. Rather than
specifying both dependencies, switch these crates to use
`rustc-std-workspace-core` which already does this.

This means there is now a single place that the `compiler-builtins`
dependency needs to get configured, for everything other than `alloc`
and `std`.
2025-07-31 22:47:24 +00:00
Trevor Gross
8d0b92acbf uefi: Use slice equality rather than memcmp
`compiler_builtins` shouldn't be called directly. Change the `PartialEq`
implementation for `DevicePathNode` to use slice equality instead, which
will call `memcmp`/`bcmp` via the intrinsic.
2025-07-31 22:47:24 +00:00
Samuel Tardieu
97e2806caa
Rollup merge of #144721 - a4lg:riscv-hwprobe-linux-6.16, r=Amanieu
`std_detect`: Linux 6.16 support for RISC-V

It adds feature detection of 1 extension (new in `std_detect`).

New RISC-V Extension:

1.  "Zabha"
2025-07-31 13:12:47 +02:00
Samuel Tardieu
febd8cdd44
Rollup merge of #144297 - GuillaumeGomez:ERROR_EXIT_CODE, r=Amanieu
Make `libtest::ERROR_EXIT_CODE` const public to not redefine it in rustdoc

I think it's better to make this constant public so it can be used by crates using `libtest` as dependency.

As a side-note, I will update https://github.com/rust-lang/rust/pull/143900 to make use of this constant once this is current PR is merged.
2025-07-31 13:12:46 +02:00
Guillaume Gomez
227abb70ab Make libtest::ERROR_EXIT_CODE const public to not redefine it in rustdoc 2025-07-31 10:44:50 +02:00
Tsukasa OI
c51e5ce452 std_detect: Linux 6.16 support for RISC-V
It adds feature detection of 1 extension (new in std_detect).

New RISC-V Extension:

1.  "Zabha"
2025-07-31 07:39:10 +00:00
Stuart Cook
dc8aec4cf2
Rollup merge of #135975 - balt-dev:master, r=tgross35
Implement `push_mut`

Implementation of rust-lang/rust#135974.
2025-07-31 15:41:58 +10:00
Balt
3ccfa14e48 Implement push_mut 2025-07-30 12:26:16 -05:00
Scott McMurray
4220587c22 AlignmentEnum should just be repr(usize) now
Since it's cfg'd instead of type-aliased
2025-07-30 00:09:01 -07:00
bors
c8bb4e8a12 Auto merge of #144658 - jhpratt:rollup-jdzhz27, r=jhpratt
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#144034 (tests: Test line number in debuginfo for diverging function calls)
 - rust-lang/rust#144510 (Fix Ord, Eq and Hash implementation of panic::Location)
 - rust-lang/rust#144583 (Enable T-compiler backport nomination)
 - rust-lang/rust#144586 (Update wasi-sdk to 27.0 in CI)
 - rust-lang/rust#144605 (Resolve: cachify `ExternPreludeEntry.binding` through a `Cell`)
 - rust-lang/rust#144632 (Update some tests for LLVM 21)
 - rust-lang/rust#144639 (Update rustc-perf submodule)
 - rust-lang/rust#144640 (Add support for the m68k architecture in 'object_architecture')

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-29 23:53:04 +00:00
Jacob Pratt
48dfddd39e
Rollup merge of #144510 - orlp:fix-location-ord, r=ibraheemdev
Fix Ord, Eq and Hash implementation of panic::Location

Fixes https://github.com/rust-lang/rust/issues/144486.

Now properly compares/hashes the filename rather than the pointer to the string.
2025-07-29 18:55:18 -04:00
bors
ba7e63b638 Auto merge of #144393 - heiher:str-contains-lsx, r=tgross35
LoongArch64 LSX fast-path for `str.contains(&str)`

Benchmark results with LLVM 21 on LA664:

```
OLD:
test bench_is_contained_in ... bench:          43.63 ns/iter (+/- 0.04)

NEW:
test bench_is_contained_in ... bench:          12.81 ns/iter (+/- 0.01)
```
2025-07-29 20:44:32 +00:00
Orson Peters
05da623016 Fix Ord, Eq and Hash implementation of panic::Location
Faster equality compare

Add tests

Add missing files for tests
2025-07-29 22:15:44 +02:00
Stuart Cook
7088bf5cc6
Rollup merge of #144634 - lucaswerkmeister:patch-1, r=lqd
Fix typo in `DropGuard` doc

Follows-up rust-lang/rust#144236 (I happened to see the typo yesterday but didn’t think it should delay the PR’s merge so I kept quiet, sorryyyyy).
2025-07-29 23:50:38 +10:00
WANG Rui
1ceacf55a0 LoongArch64 LSX fast-path for str.contains(&str)
Benchmark results with LLVM 21 on LA664:

```
OLD:
test bench_is_contained_in ... bench:          43.63 ns/iter (+/- 0.04)

NEW:
test bench_is_contained_in ... bench:          12.81 ns/iter (+/- 0.01)
```
2025-07-29 21:38:37 +08:00
Lucas Werkmeister
de02a32cf1
Fix typo in DropGuard doc 2025-07-29 13:24:41 +02:00
Stuart Cook
4bfbd80bab
Rollup merge of #144500 - joboet:thread-name-stack-overflow, r=ChrisDenton
thread name in stack overflow message

Fixes rust-lang/rust#144481, which is caused by the thread name not being initialised yet when setting up the stack overflow information. Unfortunately, the stack overflow UI test did not test for the correct thread name being present, and testing this separately didn't occur to me when writing https://github.com/rust-lang/rust/pull/140628.

This PR contains the smallest possible fix I could think of: passing the thread name explicitly to the platform thread creation function. In the future I'd very much like to explore some possibilities around merging the thread packet and thread handle into one structure and using that in the platform code instead – but that's best left for another PR.

This PR also amends the stack overflow test to check for thread names, so we don't run into this again.

``@rustbot`` label +beta-nominated
2025-07-29 20:19:51 +10:00
Stuart Cook
9cba49896c
Rollup merge of #144167 - zachs18:rangebounds-not-unsized-reason, r=tgross35
Document why `Range*<&T> as RangeBounds<T>` impls are not `T: ?Sized`, and give an alternative.

`Range*<&T> as RangeBounds<T>` impls have been tried to be relaxed to `T: ?Sized` at least twice:

* https://github.com/rust-lang/rust/pull/61584
* https://github.com/rust-lang/rust/pull/64327

I also was just about to make another PR to do it again until I `./x.py test library/alloc` and rediscovered the type inference regression, then searched around and found the previous PRs. Hence this PR instead so hopefully that doesn't keep happening 😛.

These impls cannot be relaxed for two reasons:

1. Type inference regressions: See ``@SimonSapin's`` explanation from a previous PR: https://github.com/rust-lang/rust/pull/61584#issuecomment-499601046
2. It's a breaking change: `impl RangeBounds<MyUnsizedType> for std::ops::Range<&MyUnsizedType>` is allowed after the coherence rebalance ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f704a6fe53bfc33e55b2fc246d895ec2)), and relaxing these impls would conflict with that downstream impl.

This PR adds doc-comments explaining that not having `T: ?Sized` is intentional[^1], and gives an explicit alternative: `(Bound<&T>, Bound<&T>)`.

Technically, the impls for the unstable new `std::range` types could be relaxed, as they are still unstable so the change would not be breaking, but having them be different in this regard seems worse (and the non-iterable `RangeTo/RangeToInclusive` range types are shared between the "new" and "old" so cannot be changed anyway), and then the type inference regression would pop up in whatever edition the new range types stabilize in.

The "see \<link\> for discussion of those issues" is intentionally left as a non-doc comment just for whoever may try to relax these impls again in the future, but if it is preferred to have the link in the docs I can add that.

Closes https://github.com/rust-lang/rust/issues/107196 (as wontfix)
CC https://github.com/rust-lang/rust/issues/64027

[^1]: "intentional" is maybe a bit of strong wording, should it instead say something like "was stabilized without it and it would be breaking to change it now"?
2025-07-29 20:19:48 +10:00
Stuart Cook
4bc1b98e15
Rollup merge of #144022 - connortsui20:sync_nonpoison, r=tgross35
Implementation: `#[feature(sync_nonpoison)]`, `#[feature(nonpoison_mutex)]`

Continuation of https://github.com/rust-lang/rust/pull/134663

Tracking Issue: https://github.com/rust-lang/rust/issues/134645

This PR implements a new `sync/nonpoison` module, as well as the `nonpoison` variant of the `Mutex` lock.

There are 2 main changes here, the first is the new `nonpoison::mutex` module, and the second is the `mutex` integration tests.

For the `nonpoison::mutex` module, I did my best to align it with the current state of the `poison::mutex` module. This means that several unstable features (`mapped_lock_guards`, `lock_value_accessors`, and `mutex_data_ptr`) are also in the new `nonpoison::mutex` module, under their respective feature gates. Everything else in that file is under the correct feature gate (`#[unstable(feature = "nonpoison_mutex", issue = "134645")]`).

Everything in the `nonpoison::mutex` file is essentially identical in spirit, as we are simply removing the error case from the original `poison::mutex`.

The second big change is in the integration tests. I created a macro called that allows us to duplicate tests that are "generic" over the different mutex types, in that the poison mutex is always `unwrap`ped.

~~I think that there is an argument against doing this, as it can make the tests a bit harder to understand (and language server capabilities are weaker within macros), but I think the benefit of code deduplication here is worth it. Note that it is definitely possible to generalize this (with a few tweaks) to testing the other `nonpoison` locks when they eventually get implemented, but I'll leave that for a later discussion.~~
2025-07-29 20:19:48 +10:00
Connor Tsui
d073d297b6
add extra drop, panic, and unwind tests 2025-07-29 10:44:36 +02:00
Connor Tsui
3eb722e655
add nonpoison and poison mutex tests
Adds tests for the `nonpoison::Mutex` variant by using a macro to
duplicate the existing `poison` tests.

Note that all of the tests here are adapted from the existing `poison`
tests.
2025-07-29 10:36:26 +02:00
Connor Tsui
f34fb05923
reorder mutex tests
This commit simply helps discern the actual changes needed to test both
poison and nonpoison locks.
2025-07-29 10:33:05 +02:00
Connor Tsui
3bdc228c10
add nonpoison::mutex implementation
Adds the equivalent `nonpoison` types to the `poison::mutex` module.
These types and implementations are gated under the `nonpoison_mutex`
feature gate.

Also blesses the ui tests that now have a name conflicts (because these
types no longer have unique names). The full path distinguishes the
different types.

Co-authored-by: Aandreba <aandreba@gmail.com>
Co-authored-by: Trevor Gross <tmgross@umich.edu>
2025-07-29 10:32:15 +02:00
Connor Tsui
ec4dc1c5f8
clean up existing poison files 2025-07-29 10:32:14 +02:00
Stuart Cook
95781464e0
Rollup merge of #144582 - usamoi:docs, r=RalfJung
fix `Atomic*::as_ptr` wording

r? `````@RalfJung`````

cc rust-lang/rust#144072
2025-07-29 16:16:45 +10:00