about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2025-09-23Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercotebors-17/+15
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-22Mutex/RwLock/ReentrantLock::data_ptr to be const fnPeter Lyons Kehl-5/+5
2025-09-22Auto merge of #146683 - clarfonthey:safe-intrinsics, r=RalfJung,Amanieubors-32/+32
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-21Mark float intrinsics with no preconditions as safeltdk-32/+32
2025-09-21std: merge definitions of `StdioPipes`joboet-34/+21
All platforms define this structure the same way, so we can just put it in the `process` module directly.
2025-09-21Change the cfg to a dashBen Kimock-13/+13
2025-09-21Add panic=immediate-abortBen Kimock-17/+15
2025-09-21Rollup merge of #146822 - saethlin:bbbbbstd, r=NoratriebStuart Cook-1/+1
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-21Rollup merge of #144091 - thaliaarchi:stabilize-new-zeroed, r=Mark-SimulacrumStuart Cook-1/+0
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-20Fix old typo in lang_start_internal commentBen Kimock-1/+1
2025-09-20Rollup merge of #146800 - thaliaarchi:fix-move-pal-thread, r=joboetMatthias Krüger-8/+2
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-20Rollup merge of #146762 - madsmtm:test-apple-sim, r=jieyouxuMatthias Krüger-26/+95
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-19Update cfg_if! to cfg_select!Thalia Archibald-1/+1
The macro is now builtin.
2025-09-19Fix unsupported std::sys::threadThalia Archibald-7/+1
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-19Rollup merge of #146691 - alexcrichton:wasip1-remove-dir-all-buffer, r=juntyrStuart Cook-1/+8
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-19Rollup merge of #146541 - joboet:simplify-lookup-host, r=tgross35Stuart Cook-193/+50
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-19Fix test suite in iOS/tvOS/watchOS/visionOS simulatorMads Marquart-26/+95
2025-09-19std: simplify host lookupjoboet-193/+50
2025-09-17std: Fix WASI implementation of `remove_dir_all`Alex Crichton-1/+8
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-17Auto merge of #139849 - thaliaarchi:args/zkvm, r=ibraheemdevbors-45/+58
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-17Rollup merge of #145660 - jbatez:darwin_objc, r=jdonszelmann,madsmtm,tmandryStuart Cook-0/+15
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-16Fix spelling of "adaptor"Joe Birr-Pixton-1/+1
These docs are in en_US, so "adapter" is the correct spelling (and indeed used in the next line.)
2025-09-15Rollup merge of #146549 - asomers:freebsd-readdir, r=Mark-SimulacrumMatthias Krüger-57/+63
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-14On FreeBSD, use readdir instead of readdir_rAlan Somers-57/+63
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-13initial implementation of the darwin_objc unstable featureJo Bates-0/+15
2025-09-13Rollup merge of #146517 - RalfJung:wait-timeout, r=joboetJacob Pratt-10/+8
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-13Rollup merge of #146473 - RalfJung:system-time-deconst, r=workingjubileeJacob Pratt-183/+75
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-13fix Condvar::wait_timeout docsRalf Jung-10/+8
2025-09-13fixup `become` kw documentation wrt `#[track_caller]`Waffle Lapkin-1/+4
2025-09-13Document `become` keywordMaybe Waffle-0/+99
2025-09-13also apply revert to wasip2Ralf Jung-18/+7
2025-09-12Revert "Constify SystemTime methods"Ralf Jung-165/+68
This reverts commit 7ce620dd7c6fc3371290b40a1ea28146f0d37031. 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-12Auto merge of #146468 - Zalathar:rollup-6u3s44d, r=Zalatharbors-18/+62
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-12Rollup merge of #146432 - hermit-os:hermit-take_error, r=joboetStuart Cook-2/+3
Implement `Socket::take_error` for Hermit This PR fixes an unused-imports compilation error introduced in 845311a065a5638c516ed96c73b09862b176b329 and implements `Socket::take_error` for Hermit. Hermit's `Socket::take_error` implementation works exactly like the one for Unix. r? joboet
2025-09-12Rollup merge of #145895 - RalfJung:unpark, r=joboetStuart Cook-16/+59
thread parking: fix docs and examples Fixes https://github.com/rust-lang/rust/issues/145816 r? ```@joboet``` Cc ```@m-ou-se``` ```@Amanieu```
2025-09-12Auto merge of #146019 - joboet:better-dlsym, r=tgross35bors-51/+112
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-11Auto merge of #145177 - joboet:move-pal-thread, r=ibraheemdevbors-1097/+897
std: move `thread` into `sys` Part of https://github.com/rust-lang/rust/issues/117276.
2025-09-11Implement `Socket::take_error` for HermitMartin Kröning-1/+2
2025-09-11Remove unused import from sys/pal/hermit/os.rsMartin Kröning-1/+1
This fixes ``` error: unused import: `str` --> library/std/src/sys/pal/hermit/os.rs:6:22 | 6 | use crate::{fmt, io, str}; | ^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]` ``` This was caused by 845311a065a5638c516ed96c73b09862b176b329.
2025-09-11Rollup merge of #146379 - madsmtm:fix-platform_version-test, r=tgross35Stuart Cook-3/+3
Fix `compare_against_sw_vers` test The `saturating_sub` doesn't actually perform its intended since the version numbers are signed integers (which I changed in a later revision of https://github.com/rust-lang/rust/pull/138944). Fixes the issue described in https://github.com/rust-lang/rust/pull/138944#issuecomment-3270662876. r? tgross35
2025-09-10Rollup merge of #146322 - weiznich:fix/146087, r=joboetMatthias Krüger-0/+4
Make Barrier RefUnwindSafe again This commit manually implements `RefUnwindSafe` for `std::sync::Barrier` to fix rust-lang/rust#146087. This is a fix for a regression indroduced by https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
2025-09-10Rollup merge of #145327 - joboet:net-addr-sgx-hack, r=tgross35Matthias Krüger-216/+276
std: make address resolution weirdness local to SGX Currently, the implementations of `TcpStream::connect` and its cousins take an `io::Result<&SocketAddr>` as argument, which is very weird, as most of them then `?`-try the result immediately to access the actual address. This weirdness is however necessitated by a peculiarity of the SGX networking implementation: SGX doesn't support DNS resolution but rather accepts hostnames in the same place as socket addresses. So, to make e.g. ```rust TcpStream::connect("example.com:80")` ``` work, the DNS lookup returns a special error (`NonIpSockAddr`) instead, which contains the hostname being looked up. When `.to_socket_addrs()` fails, the `each_addr` function used to select an address will pass the error to the inner `TcpStream::connect` implementation, which in SGX's case will inspect the error and try recover the hostname from it. If that succeeds, it continues with the found hostname. This is pretty obviously a terrible hack and leads to buggy code (for instance, when users use the result of `.to_socket_addrs()` in their own `ToSocketAddrs` implementation to select from a list of possible URLs, the only URL used will be that of the last item tried). Still, without changes to the SGX usercall ABI, it cannot be avoided. Therefore, this PR aims to minimise the impact of that weirdness and remove it from all non-SGX platforms. The inner `TcpStream::connect`, et al. functions now receive the `ToSocketAddrs` type directly and call `each_addr` (which is moved to `sys::net::connection`) themselves. On SGX, the implementation uses a special `each_addr` which contains the whole pass-hostname-through-error hack. As well as making the code cleaner, this also opens up the possibility of reusing newly created sockets even if a connection request fails – but I've left that for another PR. CC `@raoulstrackx`
2025-09-10std: only test `dlsym!` on platforms where it is actually usedjoboet-0/+10
`dlsym` doesn't work for finding libc symbols on platforms like linux-musl, so the test will fail.
2025-09-10std: move `thread` into `sys`joboet-1042/+842
2025-09-10Add suggestionsGeorg Semmler-3/+2
2025-09-09Fix compare_against_sw_vers test when a version part is 0Mads Marquart-3/+3
2025-09-09Make Barrier RefUnwindSafe againGeorg Semmler-0/+5
This commit manually implements `RefUnwindSafe` for `std::sync::Barrier` to fix 146087. This is a fix for a regression indroduced by https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
2025-09-09Rollup merge of #146343 - madsmtm:fix-platform_version, r=tgross35Stuart Cook-3/+8
Weakly export `platform_version` symbols The symbols `__isPlatformVersionAtLeast` and `__isOSVersionAtLeast`. This should allow linking both `compiler-rt` and `std`, which fixes https://github.com/rust-lang/rust/pull/138944#issuecomment-3266574582. r? tgross35 CC ``@zmodem,`` could you please verify that this works for you?
2025-09-08Weakly export platform_version symbolsMads Marquart-0/+5
The symbols __isPlatformVersionAtLeast and __isOSVersionAtLeast. This allows the user to link both compiler_rt and std.
2025-09-08Reorder test to make failures clearerMads Marquart-3/+3