Commit Graph

26283 Commits

Author SHA1 Message Date
Stuart Cook c539f3ffe1 Rollup merge of #149241 - thejpster:fix-armv4t-armv5te-bare-metal, r=davidtwco
Fix armv4t- and armv5te- bare metal targets

These two targets currently force on the LLVM feature `+atomics-32`. LLVM doesn't appear to actually be able to emit 32-bit load/store atomics for these targets despite this feature, and emits calls to a shim function called `__sync_lock_test_and_set_4`, which nothing in the Rust standard library supplies.

See [#t-compiler/arm > __sync_lock_test_and_set_4 on Armv5TE](https://rust-lang.zulipchat.com/#narrow/channel/242906-t-compiler.2Farm/topic/__sync_lock_test_and_set_4.20on.20Armv5TE/with/553724827) for more details.

Experimenting with clang and gcc (as logged in that zulip thread) shows that C code cannot do atomic load/stores on that architecture either (at least, not without a library call inserted).

So, the safest thing to do is probably turn off `+atomics-32` for these two Tier 3 targets.

I asked `@Lokathor` and he said he didn't even use atomics on the `armv4t-none-eabi`/`thumbv4t-none-eabi` target he maintains.

I was unable to reach `@QuinnPainter` for comment for `armv5te-none-eabi`/`thumbv5te-none-eabi`.

The second commit renames the base target spec `spec::base::thumb` to `spec::base::arm_none` and changes `armv4t-none-eabi`/`thumbv4t-none-eabi` and `armv5te-none-eabi`/`thumbv5te-none-eabi` to use it. This harmonises the frame-pointer and linker options across the bare-metal Arm EABI and EABIHF targets.

You could make an argument for harmonising `armv7a-none-*`, `armv7r-none*` and `armv8r-none-*` as well, but that can be another PR.
2025-12-02 13:56:30 +11:00
Stuart Cook dbb92adfc1 Rollup merge of #145628 - tinnamchoi:fix-btree-append, r=Amanieu
[std][BTree] Fix behavior of `::append` to match documentation, `::insert`, and `::extend`

Resolves rust-lang/rust#145614
2025-12-02 13:56:29 +11:00
Matthias Krüger 5f3dc5d89a Rollup merge of #149102 - bend-n:maybe_uninit_slice, r=joboet
stabilize maybe_uninit_slice

Tracking issue: rust-lang/rust#63569
Closes: rust-lang/rust#63569
FCP completed: https://github.com/rust-lang/rust/issues/63569#issuecomment-3477510504

Removes:
```rs
pub const fn slice_as_ptr(this: &[MaybeUninit<T>]) -> *const T;
pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit<T>]) -> *mut T;
```
2025-12-01 17:55:06 +01:00
Matthias Krüger 9a967de929 Rollup merge of #148690 - IntegralPilot:clamp-mag, r=joboet
Implement `clamp_magnitude` method for primitive floats & signed integers

Tracking issue rust-lang/rust#148519
ACP https://github.com/rust-lang/libs-team/issues/686
2025-12-01 17:55:05 +01:00
bors 9b82a4fffe Auto merge of #149481 - RalfJung:threadid-fallback, r=joboet
ThreadId generation fallback path: avoid spurious yields

Fixes https://github.com/rust-lang/miri/issues/4737
Alternative to https://github.com/rust-lang/rust/pull/149476
Cc `@orlp` `@joboet`
2025-12-01 10:47:13 +00:00
MolecularPilot ae7fa32e5b Implement clamp_magnitude for floats & signed integers
Added feature gate, documentation and tests also.
2025-12-01 17:04:25 +11:00
Ralf Jung 14830bfd0c ThreadId generation fallback path: avoid spurious yields 2025-11-30 22:52:28 +01:00
Matthias Krüger 1a9f5279f4 Rollup merge of #149475 - RalfJung:min-max-nan, r=tgross35
float::min/max: reference NaN bit pattern rules

Also, the "in particular" transition to the signed zero handling was odd, so I rearranged things a bit: first a self-contained description of the semantics, then an explanation of which operations in other standards/libraries this most closely corresponds to.

r? `@tgross35`
2025-11-30 12:03:24 +01:00
Matthias Krüger bc83bf21dd Rollup merge of #149236 - tisonkun:patch-1, r=tgross35
Clarify edge cases for Barrier::new

... since n-1 is undefined when the usize n is 0.
2025-11-30 12:03:23 +01:00
Ralf Jung 3287178d1f float::min/max: reference NaN bit pattern rules 2025-11-30 11:03:24 +01:00
tison 5d8f2b8ebe Clarify edge cases for Barrier::new 2025-11-30 17:14:46 +08:00
Matthias Krüger c93801cb20 Rollup merge of #148765 - joboet:split-up-thread, r=ChrisDenton
std: split up the `thread` module

Almost all functionality in `std::thread` is currently implemented in `thread/mod.rs`, resulting in a *huge* file with more than 2000 lines and multiple, interoperating `unsafe` sections. This PR splits the file up into multiple different private modules, each implementing mostly independent parts of the functionality. The only remaining `unsafe` interplay is that of the `lifecycle` and `scope` modules, the `spawn_scoped` implementation relies on the live thread count being updated correctly by the `lifecycle` module.

This PR contains no functional changes and only moves code around for the most part, with a few notable exceptions:
* `with_current_name` is moved to the already existing `current` module and now uses the `name` method instead of calculating the name from private fields. The old code was just a reimplementation of that method anyway.
* The private `JoinInner` type used to implement both join handles now has some more methods (`is_finished`, `thread` and the `AsInner`/`IntoInner` implementations) to avoid having to expose private fields and their invariants.
* The private `spawn_unchecked_` (note the underscore) method of `Builder` is now a freestanding function in `lifecycle`.

The rest of the changes are just visibility annotations.

I realise this PR ended up quite large – let me know if there is anyway I can aid the review process.

Edit: I've simplified the diff by adding an intermediate commit that creates all the new files by duplicating `mod.rs`. The actual changes in the second commit thus appear to delete the non-relevant parts from the respective file.
2025-11-29 20:54:06 +01:00
joboet 9c6e0f6f57 std: update broken links in thread module 2025-11-29 15:59:11 +01:00
joboet 8b08da218e std: split up the thread module 2025-11-29 15:59:11 +01:00
joboet e57df9220a std: split up the thread module (preparation) 2025-11-29 15:12:28 +01:00
Ayush Singh 5b0fded2b3 std: sys: fs: uefi: Implement rmdir and unlink
- Implement remove_dir and remove_file.
- Tested on qemu ovmf.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-11-29 14:14:02 +05:30
bors 3c5c55864f Auto merge of #149441 - jhpratt:rollup-4hmqc0z, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#147362 (Avoid suggesting constrain the associated type with unknown type)
 - rust-lang/rust#149395 (float::minimum/maximum: say which exact IEEE operation this corresponds to)
 - rust-lang/rust#149396 (Remove outdated comment)
 - rust-lang/rust#149421 (Add a regression test for issue 129865)
 - rust-lang/rust#149424 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-29 05:20:07 +00:00
Jacob Pratt a3173c1e62 Rollup merge of #149396 - yotamofek:pr/library/outdated-comment, r=chenyukang
Remove outdated comment

The comment was added in rust-lang/rust#136897 , but wasn't removed when the feature gate was stabilized (again).

Also, `it's` -> `its` :)
2025-11-28 21:22:24 -05:00
Jacob Pratt 010da38d00 Rollup merge of #149395 - RalfJung:float-minimum, r=scottmcm
float::minimum/maximum: say which exact IEEE operation this corresponds to

There's both `minimum` and `minimumNumber`, so this seems worth clarifying.

Also use code font for these names to make it more clear that they are technical terms.
2025-11-28 21:22:24 -05:00
bors 467250ddb2 Auto merge of #144465 - orlp:system-alloc-tls, r=Mark-Simulacrum
Allow the global allocator to use thread-local storage and std::thread::current()

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

Currently the thread-local storage implementation uses the `Global` allocator if it needs to allocate memory in some places. This effectively means the global allocator can not use thread-local variables. This is a shame as an allocator is precisely one of the locations where you'd *really* want to use thread-locals. We also see that this lead to hacks such as https://github.com/rust-lang/rust/pull/116402, where we detect re-entrance and abort.

So I've made the places where I could find allocation happening in the TLS implementation use the `System` allocator instead. I also applied this change to the storage allocated for a `Thread` handle so that it may be used care-free in the global allocator as well, for e.g. registering it to a central place or parking primitives.

r? `@joboet`
2025-11-29 02:08:53 +00:00
bors 9050733395 Auto merge of #148020 - bjorn3:oom_backtrace, r=Mark-Simulacrum
Show backtrace on allocation failures when possible

And if an allocation while printing the backtrace fails, don't try to print another backtrace as that will never succeed.

Split out of https://github.com/rust-lang/rust/pull/147725 to allow landing this independently of a decision whether or not to remove `-Zoom=panic`.
2025-11-28 12:27:33 +00:00
Stuart Cook 549c577c2a Rollup merge of #149087 - nxsaken:unchecked_neg_shifts_stabilize, r=Amanieu
Stabilize `unchecked_neg` and `unchecked_shifts`

Features: `unchecked_neg`, `unchecked_shifts`
Tracking issue: rust-lang/rust#85122

r? `@Amanieu`
2025-11-28 15:30:43 +11:00
Orson Peters 48fc0fd597 Add missing feature flag 2025-11-28 02:12:54 +01:00
Orson Peters 4ecf505eb7 Silence dead code warning for ThreadInit::init 2025-11-28 00:47:36 +01:00
Orson Peters 9b5bb75875 Add inline(never) to prevent reordering after TLS has been destroyed 2025-11-28 00:16:30 +01:00
Orson Peters b717684f87 Fix SGX implementation 2025-11-28 00:16:30 +01:00
Orson Peters 85a49073c3 Use checked_add instead of manual overflow check 2025-11-28 00:16:30 +01:00
Orson Peters 0b7cdf2435 Address review comments 2025-11-28 00:16:30 +01:00
Orson Peters 58830def36 Ensure set_current is called early during thread init 2025-11-28 00:16:23 +01:00
Orson Peters f9b0811d01 Add documentation guaranteeing global allocator use of TLS
Remove outdated part of comment claiming thread_local re-enters global allocator

Fix typo in doc comment

Add comments for guarantees given and footnote that System may still be called

Revise mention of using the global allocator

Allow for the possibility that the global allocator is the system allocator.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2025-11-28 00:09:12 +01:00
Orson Peters 8481b827fb Use spinlock for ThreadId if 64-bit atomic unavailable 2025-11-28 00:09:12 +01:00
Orson Peters 750609c0a7 Use System allocator for thread-local storage 2025-11-28 00:09:12 +01:00
bors c86564c412 Auto merge of #149397 - matthiaskrgr:rollup-go79y6a, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#147071 (constify from_fn, try_from_fn, try_map, map)
 - rust-lang/rust#148930 (tweak editor configs)
 - rust-lang/rust#149320 (-Znext-solver: normalize expected function input types when fudging)
 - rust-lang/rust#149363 (Port the `#![windows_subsystem]` attribute to the new attribute system)
 - rust-lang/rust#149378 (make run-make tests use 2024 edition by default)
 - rust-lang/rust#149381 (Add `impl TrustedLen` on `BTree{Map,Set}` iterators)
 - rust-lang/rust#149388 (remove session+blob decoder construction)
 - rust-lang/rust#149390 (`rust-analyzer` subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-27 19:24:40 +00:00
Matthias Krüger 66c0e1c06a Rollup merge of #149381 - yotamofek:pr/library/btree-iter-trustedlen, r=Amanieu
Add `impl TrustedLen` on `BTree{Map,Set}` iterators

https://github.com/rust-lang/rust/pull/149125#issuecomment-3556865052

r? `@Amanieu` , or re-assign
2025-11-27 20:07:15 +01:00
Yotam Ofek f15e99b2f0 Remove outdated comment 2025-11-27 20:05:58 +02:00
Ralf Jung be22161390 float::minimum/maximum: say which exact IEEE operation this corresponds to 2025-11-27 18:58:56 +01:00
Matthias Krüger cdb678c165 Rollup merge of #148589 - yoshuawuyts:DropGuard-dismiss, r=joshtriplett
Rename `DropGuard::into_inner` to `DropGuard::dismiss`

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

One of the open questions blocking the stabilization of `DropGuard` is what to name the associated method that prevents the destructor from running, and returns the captured value. This method is currently called `into_inner`, but most people (including myself) feel like this would benefit from a method that calls more attention to itself.

This PR proposes naming this method `dismiss`, after the Linux kernel's [`ScopeGuard::dismiss`](https://rust.docs.kernel.org/kernel/types/struct.ScopeGuard.html#method.dismiss). Which crucially does not evoke images of violence or weaponry the way alternatives such as "disarm" or "defuse" do. And personally I enjoy the visual metaphor of "dismissing a guard" (e.g. a person keeping watch over something) - a job well done, they're free to go.

This PR also changes the signature from an static method to an instance method. This also matches the Linux kernel's API, and seems alright since `dismiss` is not nearly as ubiquitous as `into_inner`. This makes it more convenient to use, with a much lower risk of conflicting. Though in the rare case there might be ambiguity, the explicit notation is available as a fallback.

```rust
let x = DropGuard::into_inner(guard);  // ← current
let x = guard.dismiss();               // ← proposed
2025-11-27 15:59:11 +01:00
bendn e3a2c23e37 redo the drain 2025-11-27 20:18:13 +07:00
bendn 1d718e20ac constify from_fn, try_from_fn, try_map, map 2025-11-27 20:16:46 +07:00
bendn eddf2f8c68 tests 2025-11-27 20:16:43 +07:00
Yotam Ofek 6d05636645 Add impl TrustedLen on BTree{Map,Set} iterators 2025-11-27 14:48:18 +02:00
bendn d67f99af2e fix 2025-11-27 17:55:34 +07:00
bendn daccd994e5 stabilize maybe_uninit_slice 2025-11-27 17:54:28 +07:00
bors 7b9905edb4 Auto merge of #149370 - Zalathar:rollup-6fkk5x4, r=Zalathar
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#149238 (float:🗜️ make treatment of signed zeros unspecified)
 - rust-lang/rust#149270 (implement `Iterator::{exactly_one, collect_array}`)
 - rust-lang/rust#149295 (Suggest _bytes versions of endian-converting methods)
 - rust-lang/rust#149332 (fix rustdoc search says “Consider searching for "null" instead.” rust-lang/rust#149324)
 - rust-lang/rust#149349 (Fix typo in comment.)
 - rust-lang/rust#149353 (Tidying up UI tests [3/N])
 - rust-lang/rust#149355 (Document that `build.description` affects symbol mangling and crate IDs)
 - rust-lang/rust#149360 (Enable CI download for windows-gnullvm)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-27 07:30:25 +00:00
Stuart Cook 4fca7c587c Rollup merge of #149349 - m-ou-se:fmt-arg-comment-typo, r=Mark-Simulacrum
Fix typo in comment.
2025-11-27 15:47:10 +11:00
Stuart Cook 463eebaa6e Rollup merge of #149295 - kornelski:endian_bytes, r=Mark-Simulacrum
Suggest _bytes versions of endian-converting methods

As pointed out [in this article](https://purplesyringa.moe/blog/ntoh-hton-is-a-bad-api/), the `int.to_be()`/`int.to_le()` functions are technically returning a wrong type, because endian-specific representations of integers and Rust's always-native-endian integers are different things.

I wanted to make the docs state more directly that byte swapping will result in the type having a "wrong" value, but I wasn't sure whether to delve into the special case of palindrome-like values (`0x12343412`) not changing.

I've updated the docs to suggest `{to,from}_[lb]e_bytes()` instead. These methods use `[u8; _]` for endian-specific representations, which is a different type than the native-endian `u16`/`u32`/`u64`, and this is a type-safety improvement.
2025-11-27 15:47:09 +11:00
Stuart Cook 3a62a46006 Rollup merge of #149270 - jdonszelmann:exact-length-collection, r=Mark-Simulacrum
implement `Iterator::{exactly_one, collect_array}`

As per https://github.com/rust-lang/rust/issues/149266
2025-11-27 15:47:08 +11:00
Stuart Cook 13c2640ecc Rollup merge of #149238 - RalfJung:clamp-signed-zeros, r=Amanieu
float:🗜️ make treatment of signed zeros unspecified

Fixes https://github.com/rust-lang/rust/issues/83984 by explicitly documenting that we do not specify the treatment of signed zeros in `clamp`. `@rust-lang/libs-api` Is this what you'd like to see?

Cc `@tgross35` `@thomcc`
2025-11-27 15:47:08 +11:00
Stuart Cook 0dae3e0293 Rollup merge of #149301 - moturus:main, r=Mark-Simulacrum
Motor OS: make decode_error_kind more comprehensive

A minor refactoring of a Tier 3 target (Motor OS).
2025-11-27 12:36:53 +11:00
Stuart Cook df6f24cc51 Rollup merge of #149239 - RalfJung:float-intrinsics, r=tgross35
clarify float min/max behavios for NaNs and signed zeros

The first comment is internal, it only documents the intrinsics to more clearly say what they do.
This makes the currently implemented semantics more explicit, so one does not have to go look for the publicly exposed version of the operation to figure out what exactly should happen.

The second commit adds a NaN test to the doc comment for `min`/`max`, which matches what we already have for `minimum`/`maximum`.
2025-11-27 12:36:52 +11:00