about summary refs log tree commit diff
path: root/library
AgeCommit message (Collapse)AuthorLines
2025-09-23Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercotebors-91/+84
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 #146892 - GuillaumeGomez:rollup-fa7lp0n, r=GuillaumeGomezbors-18/+0
Rollup of 5 pull requests Successful merges: - rust-lang/rust#146795 (Enable `limit_rdylib_exports` on wasm targets) - rust-lang/rust#146828 (fix a crash in rustdoc merge finalize without input file) - rust-lang/rust#146848 (Add x86_64-unknown-motor (Motor OS) tier 3 target) - rust-lang/rust#146884 (Fix modification check of `rustdoc-json-types`) - rust-lang/rust#146887 (Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples) r? `@ghost` `@rustbot` modify labels: rollup
2025-09-22Rollup merge of #146887 - taiki-e:rc-doc-feature, r=joboetGuillaume Gomez-18/+0
Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examples https://github.com/rust-lang/rust/pull/93109 removed the use of APIs enabled by this feature in these examples, but the `#![feature]` attributes ware not removed.
2025-09-22Auto merge of #146683 - clarfonthey:safe-intrinsics, r=RalfJung,Amanieubors-178/+150
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-22constify {float}::total_cmp()Nathaniel McCallum-90/+93
2025-09-22Remove unused #![feature(get_mut_unchecked)] in Rc and Arc examplesTaiki Endo-18/+0
2025-09-22Rollup merge of #146878 - RalfJung:check_language_ub, r=tgross35Stuart Cook-9/+10
assert_unsafe_precondition: fix some incorrect check_language_ub r? `@tgross35`
2025-09-22Rollup merge of #146846 - hkBst:btree-2, r=tgross35Stuart Cook-2/+3
btree InternalNode::new safety comments
2025-09-22Rollup merge of #146397 - pthariensflame:patch-1, r=AmanieuStuart Cook-5/+17
std_detect on Darwin AArch64: update features Synchronizes the list (and re-sorts it alphabetically by `FEAT` name) with the initial release version of macOS Tahoe.
2025-09-22avoid violating `slice::from_raw_parts` safety contract in `Vec::extract_if`Petros Angelatos-25/+39
The implementation of the `Vec::extract_if` iterator violates the safety contract adverized by `slice::from_raw_parts` by always constructing a mutable slice for the entire length of the vector even though that span of memory can contain holes from items already drained. The safety contract of `slice::from_raw_parts` requires that all elements must be properly initialized. As an example we can look at the following code: ```rust let mut v = vec![Box::new(0u64), Box::new(1u64)]; for item in v.extract_if(.., |x| **x == 0) { drop(item); } ``` In the second iteration a `&mut [Box<u64>]` slice of length 2 will be constructed. The first slot of the slice contains the bitpattern of an already deallocated box, which is invalid. This fixes the issue by only creating references to valid items and using pointer manipulation for the rest. I have also taken the liberty to remove the big `unsafe` blocks in place of targetted ones with a SAFETY comment. The approach closely mirrors the implementation of `Vec::retain_mut`. Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2025-09-22assert_unsafe_precondition: fix some incorrect check_language_ubRalf Jung-9/+10
2025-09-21Mark float intrinsics with no preconditions as safeltdk-178/+150
2025-09-21Rollup merge of #146639 - joboet:shared-stdiopipes, r=Mark-SimulacrumMatthias Krüger-34/+21
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-21Rollup merge of #146486 - ferrocene:pvdrz/improve-atomic-coverage, r=ibraheemdevMatthias Krüger-4/+240
Improve `core::sync::atomic` coverage This PR improves the `core::sync::atomic` coverage by adding new tests to `coretests`. r? libs
2025-09-21Allow shared access to `Exclusive<T>` when `T: Sync`Jules Bertholet-10/+104
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-74/+74
2025-09-21Add panic=immediate-abortBen Kimock-91/+84
2025-09-21btree InternalNode::new safety commentsMarijn Schouten-2/+3
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 #146820 - cammeresi:alloc-20250919, r=tgross35Stuart Cook-2/+11
Add unstable attribute to BTreeMap-related allocator generics Although these types aren't directly constructable externally, since they're pub, I think this omission was an oversight. r? libs-api
2025-09-21Rollup merge of #145664 - Darksonn:stab-file-with-nul, r=Mark-SimulacrumStuart Cook-1/+2
Stabilize `std::panic::Location::file_as_c_str` Closes: rust-lang/rust#141727 Nominating this for T-lang as per ```@traviscross``` https://github.com/rust-lang/rust/issues/141727#issuecomment-3201318429
2025-09-21Rollup merge of #144091 - thaliaarchi:stabilize-new-zeroed, r=Mark-SimulacrumStuart Cook-41/+6
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-21Rollup merge of #140983 - tkr-sh:master, r=ibraheemdevStuart Cook-16/+16
Improve doc of some methods that take ranges Some methods that were taking some range in parameter were a bit inconsistent / unclear in the panic documentation. Here is the recap: - Replaced "start/end point" by "start/end bound" to be coherent with [`RangeBounds`](https://doc.rust-lang.org/stable/std/ops/trait.RangeBounds.html) naming (it's also easier to understand I think) - Previously, it was written "_[...] or if the end point is greater than the length of [...]_", but this is not entirely true! Actually, you can have a start bound that is greater than the length, with an end bound that is unbounded and it will also panic. Therefore I think that "_[...] one of the range bound is bounded and greater than the length of [...]_" is better! - `String` methods weren't mentionning that the method panics if `start_bound > end_bound` but it actually does! It uses `slice::range` which panics when `start > end`. (https://doc.rust-lang.org/stable/src/alloc/string.rs.html#1932-1934, https://doc.rust-lang.org/stable/src/core/slice/index.rs.html#835-837). You can also test it with: ```rs struct MyRange; impl std::ops::RangeBounds<usize> for MyRange { fn start_bound(&self) -> std::ops::Bound<&usize> { std::ops::Bound::Included(&3usize) } fn end_bound(&self) -> std::ops::Bound<&usize> { std::ops::Bound::Included(&1usize) } } fn main() { let mut s = String::from("I love Rust!"); s.drain(MyRange); // panics! } ```
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/+3
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/+96
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-20docs: improve doc of some methods w/ rangestk-16/+16
2025-09-20Auto merge of #146621 - cammeresi:peek-20250915, r=Amanieubors-44/+51
Make `PeekMut` generic over the allocator - plumb in allocator generic - additional testing Related: rust-lang/rust#122742
2025-09-19Add unstable attribute to BTreeMap-related allocator genericsSidney Cammeresi-2/+11
Although these types aren't directly constructable externally, since they're pub, I think this omission was an oversight.
2025-09-19Update cfg_if! to cfg_select!Thalia Archibald-1/+1
The macro is now builtin.
2025-09-19Fix std build for xtensaThalia Archibald-0/+1
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 #146785 - hkBst:btree-1, r=joboetMatthias Krüger-1/+7
btree: safety comments for init and new
2025-09-19Rollup merge of #146690 - npmccallum:convo, r=tgross35Matthias Krüger-1/+3
add `[const] PartialEq` bound to `PartialOrd` This change is included for discussion purposes. The PartialOrd bound on PartialEq is not strictly necessary. It is, rather, logical: anything which is orderable should by definition have equality. Is the same true for constness? Should every type which is const orderable also have const equality?
2025-09-19btree: safety comments for init and newMarijn Schouten-1/+7
2025-09-19Rollup merge of #146709 - a4lg:stdarch-sync-20250917, r=KobzolStuart Cook-10367/+1891
stdarch subtree update Subtree update of `stdarch` to [rust-lang/stdarch@9f12c1a](https://github.com/rust-lang/stdarch/commit/9f12c1af60d390b7ed7024113184cf2a8073fc54). Created using https://github.com/rust-lang/josh-sync. r? ```@Kobzol```
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/+96
2025-09-19std: simplify host lookupjoboet-193/+50
2025-09-18Plumb Allocator generic into `std::vec::PeekMut`Sidney Cammeresi-44/+51
2025-09-18Auto merge of #137122 - yotamofek:pr/std/iter-eq-exact-size, r=the8472bors-4/+48
Specialize `Iterator::eq{_by}` for `TrustedLen` iterators I'm sure I got some stuff wrong here, but opening this to get feedback and make sure it's a viable idea at all. ### Motivation I had a piece of code that open-coded `Iterator::eq`, something like: ```rust if current.len() != other.len() || current.iter().zip(other.iter()).any(|(a, b)| a != b) { ... } ``` ... where both `current` and `other` are slices of the same type. Changing the code to use `current.iter().eq(other)` made it a lot slower, since it wasn't checking the length of the two slices beforehand anymore, which in this instance made a big difference in perf. So I thought I'd see if I can improve `Iterator::eq`. ### Questions 1. I can't specialize for `ExactSizeIterator`, I think it's a limitation of `min_specialization` but not sure exactly why. Is specializing for `TrustedLen` good enough? 2. Should I make a codegen test for this? If so, then how? (I manually checked the assembly to make sure it works as expected) 3. Where should I put `SpecIterCompare`? 4. Can I get a perf run for this, please? I think the compiler uses this in a few places, so it might have an affect.
2025-09-18Specialize `Iterator::eq[_by]` for `TrustedLen` iteratorsYotam Ofek-4/+48
2025-09-18Rollup merge of #146487 - ferrocene:pvdrz/improve-num-coverage, r=joboetMatthias Krüger-0/+7
Improve `core::num` coverage This PR improves the `core::num` coverage by adding a new test to `coretests`. r? libs
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-17add `[const] PartialEq` bound to `PartialOrd`Nathaniel McCallum-1/+3
This change is included for discussion purposes. The PartialOrd bound on PartialEq is not strictly necessary. It is, rather, logical: anything which is orderable should by definition have equality. Is the same true for constness? Should every type which is const orderable also have const equality?
2025-09-17Auto merge of #146685 - jdonszelmann:rollup-kwuih4z, r=jdonszelmannbors-1/+1
Rollup of 7 pull requests Successful merges: - rust-lang/rust#146458 (Add parallel-frontend-threads to bootstrap.toml and enable multi-threaded parallel compilation) - rust-lang/rust#146485 (Remove unsized arg handling in `ArgAbiBuilderMethods::store_fn_arg` implementations) - rust-lang/rust#146536 (clean up several trait related UI tests) - rust-lang/rust#146598 (Make llvm_enzyme a regular cargo feature) - rust-lang/rust#146647 (Move `#[rustc_coherence_is_core]` to the `crate_level` file) - rust-lang/rust#146654 (Do not use `git -C dir`) - rust-lang/rust#146681 (Add space after brace in `Box<[T]>::new_uninit_slice` example) r? `@ghost` `@rustbot` modify labels: rollup
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`