Commit Graph

8375 Commits

Author SHA1 Message Date
Adam Harvey
852da23a2d Explicitly note &[SocketAddr] impl of ToSocketAddrs.
Although the examples below this list do imply that there's an impl of
`ToSocketAddrs` for `&[SocketAddr]`, it's not actually noted in the list
of default implementations.
2025-09-24 15:56:38 -07:00
Matthias Krüger
d10d6bfb02 Rollup merge of #146958 - el-ev:fix_path_string_eq_recurse, r=joboet
Fix infinite recursion in Path::eq with String

- Closes [after beta backport] rust-lang/rust#146940
2025-09-24 23:33:28 +02:00
Stepan Koltsov
92859e98ee Repro duration_since regression from issue 146228 2025-09-24 21:07:26 +01:00
Jeremy Smart
a00f24116e unstably constify float mul_add methods
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-09-24 15:21:31 -04:00
Matthias Krüger
24e19c9088 Rollup merge of #146964 - Ayush1325:close-protocol, r=joboet
library: std: sys: pal: uefi: Add some comments

I seemed to have forgotten that since I am using GET_PROTOCOL attribute for the std usecases, I did not need to close the protocols explicitly. So adding these comments as a note to future self not to waste time on the same thing again.
2025-09-24 20:34:31 +02:00
Tropical
b2634e31c4 std: add support for armv7a-vex-v5 target
Co-authored-by: Lewis McClelland <lewis@lewismcclelland.me>
2025-09-24 12:10:15 -05:00
Iris Shi
5a4e536036 Fix infinite recursion in Path::eq with String 2025-09-24 21:30:41 +08:00
sysrex
8e37f0f120 chore: remove discord references from the std library as well 2025-09-24 09:13:08 +01:00
Ayush Singh
03fd823dbf library: std: sys: pal: uefi: Add some comments
I seemed to have forgotten that since I am using GET_PROTOCOL attribute
for the std usecases, I did not need to close the protocols explicitly.
So adding these comments as a note to future self not to waste time on
the same thing again.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-09-24 13:26:03 +05:30
Matthias Krüger
bba509eb7e Rollup merge of #146904 - peter-lyons-kehl:140368_data_ptr_const_fn, r=Amanieu
#140368 Mutex/RwLock/ReentrantLock::data_ptr to be const fn
2025-09-23 23:40:29 +02:00
Matthias Krüger
076ada52d3 Rollup merge of #146632 - ctz:jbp-adaptor-spelling, r=petrochenkov
Fix uses of "adaptor"

These docs are in en_US, so "adapter" is the correct spelling (and indeed used in the next line.)

A second commit comes along for the ride to fix other instances in non-rustdoc comments.
2025-09-23 18:13:51 +02:00
joboet
af1b14bb9b std: move WinSock abstractions to sys::pal 2025-09-23 17:13:35 +02:00
bors
4056082360 Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercote
Add panic=immediate-abort

MCP: https://github.com/rust-lang/compiler-team/issues/909

This adds a new panic strategy, `-Cpanic=immediate-abort`. This panic strategy essentially just codifies use of `-Zbuild-std-features=panic_immediate_abort`. This PR is intended to just set up infrastructure, and while it will change how the compiler is invoked for users of the feature, there should be no other impacts.

In many parts of the compiler, `PanicStrategy::ImmediateAbort` behaves just like `PanicStrategy::Abort`, because actually most parts of the compiler just mean to ask "can this unwind?" so I've added a helper function so we can say `sess.panic_strategy().unwinds()`.

The panic and unwind strategies have some level of compatibility, which mostly means that we can pre-compile the sysroot with unwinding panics then the sysroot can be linked with aborting panics later. The immediate-abort strategy is all-or-nothing, enforced by `compiler/rustc_metadata/src/dependency_format.rs` and this is tested for in `tests/ui/panic-runtime/`. We could _technically_ be more compatible with the other panic strategies, but immediately-aborting panics primarily exist for users who want to eliminate all the code size responsible for the panic runtime. I'm open to other use cases if people want to present them, but not right now. This PR is already large.

`-Cpanic=immediate-abort` sets both `cfg(panic = "immediate-abort")` _and_ `cfg(panic = "abort")`. bjorn3 pointed out that people may be checking for the abort cfg to ask if panics will unwind, and also the sysroot feature this is replacing used to require `-Cpanic=abort` so this seems like a good back-compat step. At least for the moment. Unclear if this is a good idea indefinitely. I can imagine this being confusing.

The changes to the standard library attributes are purely mechanical. Apart from that, I removed an `unsafe` we haven't needed for a while since the `abort` intrinsic became safe, and I've added a helpful diagnostic for people trying to use the old feature.

To test that `-Cpanic=immediate-abort` conflicts with other panic strategies, I've beefed up the core-stubs infrastructure a bit. There is now a separate attribute to set flags on it.

I've added a test that this produces the desired codegen, called `tests/run-make-cargo/panic-immediate-abort-codegen/` and also a separate run-make-cargo test that checks that we can build a binary.
2025-09-23 06:37:03 +00:00
Peter Lyons Kehl
819f8b05b9 Mutex/RwLock/ReentrantLock::data_ptr to be const fn 2025-09-22 12:51:50 -07:00
bors
ce4beebecb Auto merge of #146683 - clarfonthey:safe-intrinsics, r=RalfJung,Amanieu
Mark float intrinsics with no preconditions as safe

Note: for ease of reviewing, the list of safe intrinsics is sorted in the first commit, and then safe intrinsics are added in the second commit.

All *recently added* float intrinsics have been correctly marked as safe to call due to the fact that they have no preconditions. This adds the remaining float intrinsics which are safe to call to the safe intrinsic list, and removes the unsafe blocks around their calls.

---

Side note: this may want a try run before being added to the queue, since I'm not sure if there's any tier-2 code that uses these intrinsics that might not be tested on the usual PR flow. We've already uncovered a few places in subtrees that do this, and it's worth double-checking before clogging up the queue.
2025-09-22 14:35:46 +00:00
ltdk
055e05a338 Mark float intrinsics with no preconditions as safe 2025-09-21 20:37:51 -04:00
joboet
87a00f67ba std: merge definitions of StdioPipes
All platforms define this structure the same way, so we can just put it in the `process` module directly.
2025-09-21 19:45:46 +02:00
Ben Kimock
df58fd8cf7 Change the cfg to a dash 2025-09-21 13:12:20 -04:00
Ben Kimock
888679013d Add panic=immediate-abort 2025-09-21 13:12:18 -04:00
Stuart Cook
5224279572 Rollup merge of #146822 - saethlin:bbbbbstd, r=Noratrieb
Fix old typo in lang_start_internal comment

Noticed this when reading the rt cleanup code; the typo was introduced during a mass port of libstd to std in comments.
2025-09-21 14:42:37 +10:00
Stuart Cook
7a5819d154 Rollup merge of #144091 - thaliaarchi:stabilize-new-zeroed, r=Mark-Simulacrum
Stabilize `new_zeroed_alloc`

The corresponding `new_uninit` and `new_uninit_slice` functions were stabilized in rust-lang/rust#129401, but the zeroed counterparts were left for later out of a [desire](https://github.com/rust-lang/rust/issues/63291#issuecomment-2161039756) to stabilize only the minimal set. These functions are straightforward mirrors of the uninit functions and well-established. Since no blockers or design questions have surfaced in the past year, I think it's time to stabilize them.

Tracking issue: rust-lang/rust#129396
2025-09-21 14:42:33 +10:00
Ben Kimock
5c0cb3af59 Fix old typo in lang_start_internal comment 2025-09-20 18:27:33 -04:00
Matthias Krüger
48c1249bff Rollup merge of #146800 - thaliaarchi:fix-move-pal-thread, r=joboet
Fix unsupported `std::sys::thread` after move

Fixes building std for any platform with an unsupported thread abstraction. This includes {aarch64,armv7,x86_64}-unknown-trusty and riscv32im-risc0-zkvm-elf, which explicitly include the unsupported module, and platforms with no PAL.

Bug fix for rust-lang/rust#145177 (std: move thread into sys).

Also fix the `std` build for xtensa, which I incidentally found while looking for an unsupported platform.

r? ``@joboet``
2025-09-20 17:55:05 +02:00
Matthias Krüger
8904ff135f Rollup merge of #146762 - madsmtm:test-apple-sim, r=jieyouxu
Fix and provide instructions for running test suite on Apple simulators

The following now works:

```sh
./x test --host='' --target aarch64-apple-ios-sim --skip tests/debuginfo
./x test --host='' --target aarch64-apple-tvos-sim --skip tests/debuginfo
./x test --host='' --target aarch64-apple-watchos-sim --skip tests/debuginfo
./x test --host='' --target aarch64-apple-visionos-sim --skip tests/debuginfo
```

I have documented the setup I used [in the `rustc-dev-guide`](https://rustc-dev-guide.rust-lang.org/tests/running.html#testing-on-emulators), it's fairly standard use of `remote-test-server` (with a small fix to library load paths which I've made in the first commit).

I first tried the somewhat simpler `target.aarch64-apple-ios-sim.runner = "xcrun simctl spawn $UDID"`, but that doesn't work as required libraries etc. also need to be copied to the device.

The debuginfo tests fail, I think because the debug info in `.dSYM` isn't available. I am yet unsure exactly how to fix this, either we need to copy that directory to the target as well, or we need to configure `lldb` somehow to read it from the host.

I decided to not add this to our CI, since I suspect we wouldn't gain much from it? Running on the simulator still uses the host Darwin kernel, it's basically just configured to run in another mode with more restricted permissions and different system libraries.

r? jieyouxu
CC ``@simlay,`` you're a lot more familiar with `xcrun simctl` than I.
2025-09-20 17:55:04 +02:00
Thalia Archibald
db4d4eff56 Update cfg_if! to cfg_select!
The macro is now builtin.
2025-09-19 19:18:10 -06:00
Thalia Archibald
6a5838105d Fix unsupported std::sys::thread
Fixes building std for any platform with an unsupported thread
abstraction. This includes {aarch64,armv7,x86_64}-unknown-trusty and
riscv32im-risc0-zkvm-elf, which explicitly include the unsupported
module, and platforms with no PAL.

Bug fix for PR 145177 (std: move thread into sys).
2025-09-19 19:18:10 -06:00
Stuart Cook
20b6f7596b Rollup merge of #146691 - alexcrichton:wasip1-remove-dir-all-buffer, r=juntyr
std: Fix WASI implementation of `remove_dir_all`

This commit is a change to the WASI-specific implementation of the `std::fs::remove_dir_all` function. Specifically it changes how directory entries are read of a directory-being-deleted to specifically buffer them all into a `Vec` before actually proceeding to delete anything. This is necessary to fix an interaction with how the WASIp1 `fd_readdir` API works to have everything work out in the face of mutations while reading a directory.

The basic problem is that `fd_readdir`, the WASIp1 API for reading directories, is not a stateful read of a directory but instead a "seekable" read of a directory. Its `cookie` argument enables seeking anywhere within the directory at any time to read further entries. Native host implementations do not have this ability, however, which means that this seeking property must be achieved by re-reading the directory. The problem with this is that WASIp1 has under-specified semantics around what should happen if a directory is mutated between two calls to `fd_readdir`. In essence there's not really any possible implementation in hosts except to read the entire directory and support seeking through the already-read list. This implementation is not possible in the WASIp1-to-WASIp2 adapter that is primarily used to create components for the `wasm32-wasip2` target where it has constrained memory requirements and can't buffer up arbitrarily sized directories. There's some more detailed discussion at https://github.com/bytecodealliance/wasmtime/issues/11701#issuecomment-3299957213 as well.

The WASIp1 API definitions are effectively "dead" now at the standards level meaning that `fd_readdir` won't be changing nor will a replacement be coming. For the `wasm32-wasip2` target this will get fixed once filesystem APIs are updated to use WASIp2 directly instead of WASIp1, making this buffering unnecessary. In essence while this is a hack it's sort of the least invasive thing that works everywhere for now. I don't think this is viable to fix in hosts so guests compiled to wasm are going to have to work around it by not relying on any guarantees about what happens to a directory if it's mutated between reads.
2025-09-19 22:31:53 +10:00
Stuart Cook
ff8d63ae43 Rollup merge of #146541 - joboet:simplify-lookup-host, r=tgross35
std: simplify host lookup

The logic for splitting up a string into a hostname and port is currently duplicated across (nearly) all of the networking implementations in `sys`. Since it does not actually rely on any system internals, this PR moves it to the `ToSocketAddr` implementation for `&str`, making it easier to discover and maintain.

On the other hand, the `ToSocketAddr` implementation (or rather the `resolve_socket_addr` function) contained logic to overwrite the port on the socket addresses returned by `LookupHost`, even though `LookupHost` is already aware of the port and sets the port already on Xous. This PR thus removes this logic by moving the responsibility of setting the port to the system-specific `LookupHost` implementation.

As a consequence of these changes, there remains only one way of creating `LookupHost`, hence I've removed the `TryFrom` implementations in favour of a `lookup_host` function, mirroring other, public iterator-based features.

And finally, I've simplified the parsing logic responsible for recognising IP addresses passed to `<(&str, u16)>::to_socket_addrs()` by using the `FromStr` impl of `IpAddr` rather than duplicating the parsing for both IP versions.
2025-09-19 22:31:51 +10:00
Mads Marquart
37be93497e Fix test suite in iOS/tvOS/watchOS/visionOS simulator 2025-09-19 13:55:03 +02:00
joboet
09d3120a99 std: simplify host lookup 2025-09-19 11:30:27 +02:00
Alex Crichton
f900758623 std: Fix WASI implementation of remove_dir_all
This commit is a change to the WASI-specific implementation of the
`std::fs::remove_dir_all` function. Specifically it changes how
directory entries are read of a directory-being-deleted to specifically
buffer them all into a `Vec` before actually proceeding to delete
anything. This is necessary to fix an interaction with how the WASIp1
`fd_readdir` API works to have everything work out in the face of
mutations while reading a directory.

The basic problem is that `fd_readdir`, the WASIp1 API for reading
directories, is not a stateful read of a directory but instead a
"seekable" read of a directory. Its `cookie` argument enables seeking
anywhere within the directory at any time to read further entries.
Native host implementations do not have this ability, however, which
means that this seeking property must be achieved by re-reading the
directory. The problem with this is that WASIp1 has under-specified
semantics around what should happen if a directory is mutated between
two calls to `fd_readdir`. In essence there's not really any possible
implementation in hosts except to read the entire directory and support
seeking through the already-read list. This implementation is not
possible in the WASIp1-to-WASIp2 adapter that is primarily used to
create components for the `wasm32-wasip2` target where it has
constrained memory requirements and can't buffer up arbitrarily sized
directories.

The WASIp1 API definitions are effectively "dead" now at the standards
level meaning that `fd_readdir` won't be changing nor will a replacement
be coming. For the `wasm32-wasip2` target this will get fixed once
filesystem APIs are updated to use WASIp2 directly instead of WASIp1,
making this buffering unnecessary. In essence while this is a hack it's
sort of the least invasive thing that works everywhere for now. I don't
think this is viable to fix in hosts so guests compiled to wasm are
going to have to work around it by not relying on any guarantees about
what happens to a directory if it's mutated between reads.
2025-09-17 14:55:51 -07:00
bors
4645a79881 Auto merge of #139849 - thaliaarchi:args/zkvm, r=ibraheemdev
Fix `env::ArgsOs` for zkVM

The zkVM implementation of `env::ArgsOs` incorrectly reports the full length even after having iterated. Instead, use a range approach which works out to be simpler. Also, implement more iterator methods like the other platforms in #139847.

cc `@flaub` `@jbruestle` `@SchmErik`
2025-09-17 18:19:36 +00:00
Stuart Cook
6ad98750e0 Rollup merge of #145660 - jbatez:darwin_objc, r=jdonszelmann,madsmtm,tmandry
initial implementation of the darwin_objc unstable feature

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

This feature makes it possible to reference Objective-C classes and selectors using the same ABI used by native Objective-C on Apple/Darwin platforms. Without it, Rust code interacting with Objective-C must resort to loading classes and selectors using costly string-based lookups at runtime. With it, these references can be loaded efficiently at dynamic load time.

r? ```@tmandry```

try-job: `*apple*`
try-job: `x86_64-gnu-nopt`
2025-09-17 14:56:44 +10:00
Joe Birr-Pixton
1ae720a52d Fix spelling of "adaptor"
These docs are in en_US, so "adapter" is the correct spelling
(and indeed used in the next line.)
2025-09-16 11:51:19 +01:00
Matthias Krüger
fbd63a93c3 Rollup merge of #146549 - asomers:freebsd-readdir, r=Mark-Simulacrum
On FreeBSD, use readdir instead of readdir_r

readdir_r has the same problems on FreeBSD as it does on other platforms: it assumes a fixed NAME_MAX.  And readdir has the same thread-safety guarantee as it does on other platforms: it's safe as long as only one thread tries to read from the directory stream at a given time.

Furthermore, readdir_r is likely to be removed for FreeBSD 16, so we should stop using it now.
2025-09-15 22:09:50 +02:00
Alan Somers
572b423464 On FreeBSD, use readdir instead of readdir_r
readdir_r has the same problems on FreeBSD as it does on other
platforms: it assumes a fixed NAME_MAX.  And readdir has the same
thread-safety guarantee as it does on other platforms: it's safe as long
as only one thread tries to read from the directory stream at a given
time.

Furthermore, readdir_r is likely to be removed for FreeBSD 16, so we
should stop using it now.
2025-09-14 11:44:55 -06:00
Jo Bates
1ebf69d1b1 initial implementation of the darwin_objc unstable feature 2025-09-13 16:06:22 -07:00
Jacob Pratt
08db93806b Rollup merge of #146517 - RalfJung:wait-timeout, r=joboet
fix Condvar::wait_timeout docs

[Context](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Condvar.20wait_timeout.20sleep.20duration.20decremented/with/539279839)
r? `@joboet`
2025-09-13 18:55:19 -04:00
Jacob Pratt
5d56e52409 Rollup merge of #146473 - RalfJung:system-time-deconst, r=workingjubilee
Revert "Constify SystemTime methods"

This reverts https://github.com/rust-lang/rust/pull/144519. The const-hacks introduces bugs, and they make the code harder to maintain. Let's wait until we can constify these functions without changing their implementation.

Fixes https://github.com/rust-lang/rust/issues/146228.
Closes https://github.com/rust-lang/rust/issues/144517 (since the feature is gone).
r? `@tgross35`
Cc `@clarfonthey`
2025-09-13 18:55:18 -04:00
Ralf Jung
f21d3fbce9 fix Condvar::wait_timeout docs 2025-09-13 20:13:37 +02:00
Waffle Lapkin
f13c8c2192 fixup become kw documentation wrt #[track_caller] 2025-09-13 19:48:10 +02:00
Maybe Waffle
cc9225406c Document become keyword 2025-09-13 19:48:07 +02:00
Ralf Jung
2baa39e89f also apply revert to wasip2 2025-09-13 10:41:59 +02:00
Ralf Jung
5d8e41b656 Revert "Constify SystemTime methods"
This reverts commit 7ce620dd7c.
The const-hacks introduces bugs, and they make the code harder to maintain.
Let's wait until we can constify these functions without changing their implementation.
2025-09-12 17:16:38 +02:00
bors
408eacfb95 Auto merge of #146468 - Zalathar:rollup-6u3s44d, r=Zalathar
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#144549 (match clang's `va_arg` assembly on arm targets)
 - rust-lang/rust#145895 (thread parking: fix docs and examples)
 - rust-lang/rust#146308 (support integer literals in `${concat()}`)
 - rust-lang/rust#146323 (check before test for hardware capabilites in bits 32~63 of usize)
 - rust-lang/rust#146332 (tidy: make behavior of extra-checks more uniform)
 - rust-lang/rust#146374 (Update `browser-ui-test` version to `0.22.2`)
 - rust-lang/rust#146413 (Improve suggestion in case a bare URL is surrounded by brackets)
 - rust-lang/rust#146426 (Bump miow to 0.60.1)
 - rust-lang/rust#146432 (Implement `Socket::take_error` for Hermit)
 - rust-lang/rust#146433 (rwlock tests: fix miri macos test regression)
 - rust-lang/rust#146435 (Change the default value of `gcc.download-ci-gcc` to `true`)
 - rust-lang/rust#146439 (fix cfg for poison test macro)
 - rust-lang/rust#146448 ([rustdoc] Correctly handle literal search on paths)
 - rust-lang/rust#146449 (Fix `libgccjit` symlink when we build GCC locally)
 - rust-lang/rust#146455 (test: remove an outdated normalization for rustc versions)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-09-12 11:27:07 +00:00
Stuart Cook
2e51a38999 Rollup merge of #146439 - connortsui20:fix-sync-macro-attr, r=RalfJung
fix cfg for poison test macro

Fixes test regression in https://github.com/rust-lang/rust/pull/144648
Continuation of https://github.com/rust-lang/rust/pull/146433

I think this is right? Not really sure how to test this myself to be honest.

r? ```@RalfJung```

I'll also leave the improvement to the test macro for a separate PR (described [here](https://github.com/rust-lang/rust/pull/146433#issuecomment-3280210451)) since I've never done something like that before. Though since this fixes all of the tests, it might not be necessary since anyone in the future will see the `cfg()` and not `cfg_attr()`?
2025-09-12 20:02:17 +10:00
Stuart Cook
312e15fb3e Rollup merge of #146433 - RalfJung:rwlock-miri, r=tgross35
rwlock tests: fix miri macos test regression

https://github.com/rust-lang/rust/pull/144648 broke the attributes that ignore the tests on Miri; this patch should fix that.
2025-09-12 20:02:16 +10:00
Stuart Cook
f40d78f57e Rollup merge of #146432 - hermit-os:hermit-take_error, r=joboet
Implement `Socket::take_error` for Hermit

This PR fixes an unused-imports compilation error introduced in 845311a065 and implements `Socket::take_error` for Hermit.

Hermit's `Socket::take_error` implementation works exactly like the one for Unix.

r? joboet
2025-09-12 20:02:15 +10:00
Stuart Cook
1037c082bc Rollup merge of #145895 - RalfJung:unpark, r=joboet
thread parking: fix docs and examples

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

r? ```@joboet```
Cc ```@m-ou-se``` ```@Amanieu```
2025-09-12 20:02:10 +10:00
bors
ac4495a10d Auto merge of #146019 - joboet:better-dlsym, r=tgross35
std: optimize `dlsym!` macro and add a test for it

The `dlsym!` macro always ensures that the name string is nul-terminated, so there is no need to perform the check at runtime. Also, acquire loads are generally faster than a load and a barrier, so use them. This is only false in the case where the symbol is missing, but that shouldn't matter too much.
2025-09-12 08:18:41 +00:00