about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2025-08-04replace version placeholderBoxy-10/+10
2025-07-29Auto merge of #144658 - jhpratt:rollup-jdzhz27, r=jhprattbors-1/+41
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-29Rollup merge of #144510 - orlp:fix-location-ord, r=ibraheemdevJacob Pratt-1/+41
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-29Auto merge of #144393 - heiher:str-contains-lsx, r=tgross35bors-3/+16
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-29Fix Ord, Eq and Hash implementation of panic::LocationOrson Peters-1/+41
Faster equality compare Add tests Add missing files for tests
2025-07-29Rollup merge of #144634 - lucaswerkmeister:patch-1, r=lqdStuart Cook-1/+1
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-29LoongArch64 LSX fast-path for `str.contains(&str)`WANG Rui-3/+16
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-29Fix typo in `DropGuard` docLucas Werkmeister-1/+1
2025-07-29Rollup merge of #144167 - zachs18:rangebounds-not-unsized-reason, r=tgross35Stuart Cook-0/+48
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 :stuck_out_tongue:. 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-29Rollup merge of #144582 - usamoi:docs, r=RalfJungStuart Cook-9/+9
fix `Atomic*::as_ptr` wording r? `````@RalfJung````` cc rust-lang/rust#144072
2025-07-29Rollup merge of #144575 - xonx4l:patch-6, r=scottmcmStuart Cook-1/+1
fixed typo chunks->as_chunks Fixes rust-lang/rust#144555 info-: fix typo chunks -> as_chunks This now take us to as_chunks page when clicking on as_chunks link and not to chunks . Thanks .
2025-07-29Rollup merge of #144539 - RalfJung:const_with_exposed_provenance, r=oli-obkStuart Cook-2/+4
constify with_exposed_provenance We allow `int as ptr` in const, so it only makes sense to also allow this function. Otherwise, `const fn` can't be ported to use the more explicit exposed provenance APIs. Note that as of today, `with_exposed_provenance` in const is equivalent to `without_provenance`. However, we probably don't want to promise that: if someone does `with_exposed_provenance(MMIO_ADDR)` in const and then uses that pointer at runtime, that is something we should ensure keeps working; if someone does the same with `without_provenance` then I would consider that UB. Tracking: https://github.com/rust-lang/rust/issues/144538 Cc `````@rust-lang/wg-const-eval````` `````@rust-lang/opsem`````
2025-07-29Rollup merge of #144236 - yoshuawuyts:drop-guard, r=Mark-SimulacrumStuart Cook-0/+159
Add `core::mem::DropGuard` ## 1.0 Summary This PR introduces a new type `core::mem::DropGuard` which wraps a value and runs a closure when the value is dropped. ```rust use core::mem::DropGuard; // Create a new guard around a string that will // print its value when dropped. let s = String::from("Chashu likes tuna"); let mut s = DropGuard::new(s, |s| println!("{s}")); // Modify the string contained in the guard. s.push_str("!!!"); // The guard will be dropped here, printing: // "Chashu likes tuna!!!" ``` ## 2.0 Motivation A number of programming languages include constructs like `try..finally` or `defer` to run code as the last piece of a particular sequence, regardless of whether an error occurred. This is typically used to clean up resources, like closing files, freeing memory, or unlocking resources. In Rust we use the `Drop` trait instead, allowing us to [never having to manually close sockets](https://blog.skylight.io/rust-means-never-having-to-close-a-socket/). While `Drop` (and RAII in general) has been working incredibly well for Rust in general, sometimes it can be a little verbose to setup. In particular when upholding invariants are local to functions, having a quick inline way to setup an `impl Drop` can be incredibly convenient. We can see this in use in the Rust stdlib, which has a number of private `DropGuard` impls used internally: - [library/alloc/src/vec/drain.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/vec/drain.rs#L177) - [library/alloc/src/boxed/thin.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/boxed/thin.rs#L362) - [library/alloc/src/slice.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/slice.rs#L413) - [library/alloc/src/collections/linked_list.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/collections/linked_list.rs#L1135) - [library/alloc/src/collections/binary_heap/mod.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/collections/binary_heap/mod.rs#L1816) - [library/alloc/src/collections/btree/map.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/collections/btree/map.rs#L1715) - [library/alloc/src/collections/vec_deque/drain.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/collections/vec_deque/drain.rs#L95) - [library/alloc/src/vec/into_iter.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/alloc/src/vec/into_iter.rs#L488) - [library/std/src/os/windows/process.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/library/std/src/os/windows/process.rs#L320) - [tests/ui/process/win-proc-thread-attributes.rs](https://github.com/rust-lang/rust/blob/9982d6462bedf1e793f7b2dbd655a4e57cdf67d4/tests/ui/process/win-proc-thread-attributes.rs#L17) ## 3.0 Design This PR implements what can be considered about the simplest possible design: 1. A single type `DropGuard` which takes both a generic type `T` and a closure `F`. 2. `Deref` + `DerefMut` impls to make it easy to work with the `T` in the guard. 3. An `impl Drop` on the guard which calls the closure `F` on drop. 4. An inherent `fn into_inner` which takes the type `T` out of the guard without calling the closure `F`. Notably this design does not allow divergent behavior based on the type of drop that has occurred. The [`scopeguard` crate](https://docs.rs/scopeguard/latest/scopeguard/index.html) includes additional `on_success` and `on_onwind` variants which can be used to branch on unwind behavior instead. However [in a lot of cases](https://github.com/rust-lang/rust/issues/143612#issuecomment-3053928328) this doesn’t seem necessary, and using the arm/disarm pattern seems to provide much the same functionality: ```rust let guard = DropGuard::new((), |s| ...); // 1. Arm the guard other_function(); // 2. Perform operations guard.into_inner(); // 3. Disarm the guard ``` `DropGuard` combined with this pattern seems like it should cover the vast majority of use cases for quick, inline destructors. It certainly seems like it should cover all existing uses in the stdlib, as well as all existing uses in crates like [hashbrown](https://github.com/search?q=repo%3Arust-lang%2Fhashbrown%20guard&type=code). ## 4.0 Acknowledgements This implementation is based on the [mini-scopeguard crate](https://github.com/yoshuawuyts/mini-scopeguard) which in turn is based on the [scopeguard crate](https://docs.rs/scopeguard). The implementations only differ superficially; because of the nature of the problem there is only really one obvious way to structure the solution. And the scopeguard crate got that right! ## 5.0 Conclusion This PR adds a new type `core::mem::DropGuard` to the stdlib which adds a small convenience helper to create inline destructors with. This would bring the majority of the functionality of the `scopeguard` crate into the stdlib, which is the [49th most downloaded crate](https://crates.io/crates?sort=downloads) on crates.io (387 million downloads). Given the actual implementation of `DropGuard` is only around 60 lines, it seems to hit that sweet spot of low-complexity / high-impact that makes for a particularly efficient stdlib addition. Which is why I’m putting this forward for consideration; thanks!
2025-07-29Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhprattbors-326/+1
Remove `[T]::array_chunks(_mut)` Since libs-api is proposing as much in https://github.com/rust-lang/rust/issues/74985#issuecomment-3024465102 Closes rust-lang/rust#74985 Closes rust-lang/rust#76354 try-job: dist-various-1 try-job: dist-various-2
2025-07-28fix `Atomic*::as_ptr` wordingusamoi-9/+9
2025-07-28Add `core::mem::DropGuard`Yosh-0/+159
Fix CI for drop_guard fix CI fix all tidy lints fix tidy link add first batch of feedback from review Add second batch of feedback from review add third batch of feedback from review fix failing test Update library/core/src/mem/drop_guard.rs Co-authored-by: Ruby Lazuli <general@patchmixolydic.com> fix doctests Implement changes from T-Libs-API review And start tracking based on the tracking issue. fix tidy lint
2025-07-28fixed typo chunks->as_chunksxonx-1/+1
2025-07-28Rollup merge of #144472 - okaneco:char_bound, r=Mark-SimulacrumMatthias Krüger-14/+26
str: Mark unstable `round_char_boundary` feature functions as const Mark `floor_char_boundary`, `ceil_char_boundary` const Simplify the implementations, reducing the number of arithmetic operations It seems unnecessary to do the lower/upper bounds calculations and extra slicing when we can jump straight to inspecting the bytes, assuming the underlying data is valid UTF-8. Tracking issue https://github.com/rust-lang/rust/issues/93743
2025-07-28Rollup merge of #144072 - usamoi:docs, r=Mark-SimulacrumMatthias Krüger-9/+15
update `Atomic*::from_ptr` and `Atomic*::as_ptr` docs Since https://github.com/rust-lang/rust/pull/128778, it's allowed to perform atomic read and non-atomic read on the same atomic at the same time. Update the `Atomic*::from_ptr` and `Atomic*::as_ptr` documentation to remove expressions such as `not allowed to mix atomic and non-atomic accesses`. see also [std::sync::atomic](https://doc.rust-lang.org/std/sync/atomic/index.html#memory-model-for-atomic-accesses)
2025-07-27Remove `[T]::array_chunks(_mut)`Scott McMurray-326/+1
2025-07-27constify with_exposed_provenanceRalf Jung-2/+4
2025-07-26Rollup merge of #144331 - ↵Matthias Krüger-0/+2
jplatte:matches-allow-non_exhaustive_omitted_patterns, r=Nadrieril Disable non_exhaustive_omitted_patterns within matches! macro Closes rust-lang/rust#117304. I believe I can skip all of the bootstrap stuff mentioned in https://github.com/rust-lang/rust/issues/117304#issuecomment-1784414453 due to https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/, right? cc `@Jules-Bertholet`
2025-07-25str: Mark unstable `round_char_boundary` feature functions as constokaneco-14/+26
Mark `floor_char_boundary`, `ceil_char_boundary` const Simplify the implementations, reducing the number of arithmetic operations
2025-07-25Rollup merge of #144314 - kornelski:pivot-safely, r=jhprattMatthias Krüger-10/+10
Hint that choose_pivot returns index in bounds Instead of using `unsafe` in multiple places, one `hint::assert_unchecked` allows use of safe code instead. Part of #rust-lang/rust#144326
2025-07-25Rollup merge of #143970 - SunkenPotato:update_mem_copy_docs, r=scottmcmMatthias Krüger-1/+1
Update core::mem::copy documentation Update the documentation of `core::mem::copy` to include a `const` on the definition of the function.
2025-07-25Rollup merge of #143424 - hkBst:auto-deref, r=jhprattMatthias Krüger-7/+7
clippy fix: rely on autoderef Changes instances of `&**self` to `self`.
2025-07-24Rollup merge of #144278 - Qelxiros:rev-into-inner, r=tgross35León Orell Valerian Liehr-0/+19
add Rev::into_inner Tracking issue: rust-lang/rust#144277
2025-07-23add Rev::into_innerJeremy Smart-0/+19
2025-07-23Document (internally) that `Range*<&T> as RangeBounds<T>` impls are ↵Zachary S-0/+48
intentionally not `T: ?Sized`, and document (publically) an alternative.
2025-07-23Disable non_exhaustive_omitted_patterns within matches! macroJonas Platte-0/+2
2025-07-23Hint that choose_pivot returns index in boundsKornel-10/+10
2025-07-22Auto merge of #144205 - hkBst:flt2dec, r=workingjubileebors-11/+7
flt2dec: replace for loop by iter_mut Perf is explored in https://github.com/rust-lang/rust/issues/144118, which initially showed small losses, but then also showed significant gains. Both are real, but given the smallness of the losses, this seems a good change.
2025-07-22Rollup merge of #144212 - bjorn3:remove_unique_lang_item, r=oli-obk许杰友 Jieyou Xu (Joe)-2/+0
Remove the ptr_unique lang item Miri no longer uses it since https://github.com/rust-lang/miri/pull/4307.
2025-07-22Rollup merge of #143768 - Randl:const-try, r=oli-obk许杰友 Jieyou Xu (Joe)-69/+149
Constify Try, From, TryFrom and relevant traits
2025-07-21Constify Try, From, TryFromEvgenii Zheltonozhskii-69/+149
2025-07-20Option::as_slice: fix commentRalf Jung-1/+1
2025-07-20flt2dec: use fill instead of loopMarijn Schouten-11/+7
2025-07-20Rollup merge of #143423 - hkBst:clippy-fix-1, r=workingjubileeGuillaume Gomez-32/+28
address clippy formatting nits - int_log10.rs: change top level doc comments to outer - collect.rs: remove empty line after doc comment - clippy fix: markdown indentation for indented items after line break: a markdown list item continued over multiples lines, but those following lines which are part of the same item are not indented - clippy fix: bound in one place: when there is a bound in angle brackets and another bound on the same variable in a where clause
2025-07-20Rollup merge of #143282 - nxsaken:strict_sub_signed, r=jhprattGuillaume Gomez-4/+41
Add `uX::strict_sub_signed` rust-lang/rust#116090 missed `strict_sub_signed`, adding it here. Part of rust-lang/rust#118260. r? ``@m-ou-se``
2025-07-20Remove the ptr_unique lang itembjorn3-2/+0
Miri no longer uses it.
2025-07-20Rollup merge of #144169 - RalfJung:type-id-fix, r=oli-obkMatthias Krüger-1/+1
interpret: fix TypeId pointers being considered data pointers Fixes https://github.com/rust-lang/miri/issues/4477 r? ````@oli-obk````
2025-07-20Rollup merge of #144111 - clarfonthey:maybe-uninit-deprecated, r=jhprattMatthias Krüger-112/+2
Remove deprecated `MaybeUninit` slice methods These were left in to make migration a bit easier, although they should be removed now since they were never stable.
2025-07-20Rollup merge of #143604 - nxsaken:const_float_round_methods, r=RalfJungMatthias Krüger-24/+20
Stabilize `const_float_round_methods` Closes rust-lang/rust#141555, waiting for FCP.
2025-07-20Rollup merge of #141260 - LuigiPiucco:volatile-null, r=RalfJungMatthias Krüger-78/+108
Allow volatile access to non-Rust memory, including address 0 This PR relaxes the `ub_check` in the `read_volatile`/`write_volatile` pointer operations to allow passing null. This is needed to support processors which hard-code peripheral registers on address 0, like the AVR chip ATtiny1626. LLVM understands this as valid and handles it correctly, as tested in my [PR to add a note about it](https://github.com/llvm/llvm-project/pull/139803/commits/6387c82255c56d3035d249eb54110695e76b8030#diff-81bbb96298c32fa901beb82ab3b97add27a410c01d577c1f8c01000ed2055826) (rustc generates the same LLVM IR as expected there when this PR is applied, and consequently the same AVR assembly). Follow-up and implementation of the discussions in: - https://internals.rust-lang.org/t/pre-rfc-conditionally-supported-volatile-access-to-address-0/12881/7 - https://github.com/Rahix/avr-device/pull/185; - [#t-lang > Adding the possibility of volatile access to address 0](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Adding.20the.20possibility.20of.20volatile.20access.20to.20address.200/with/513303502) - https://discourse.llvm.org/t/rfc-volatile-access-to-non-dereferenceable-memory-may-be-well-defined/86303 r? ````@RalfJung```` Also fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/29 (about as good as it'll get, null will likely never be a "normal" address in Rust)
2025-07-19Remove deprecated MaybeUninit slice methodsltdk-112/+2
2025-07-20Add `#[rustc_intrinsic_const_stable_indirect]` to float roundingNurzhan Sakén-0/+20
intrinsics
2025-07-20Stabilize `const_float_round_methods`Nurzhan Sakén-24/+0
2025-07-19update `Atomic*::from_ptr` and `Atomic*::as_ptr` docsusamoi-9/+15
2025-07-19Auto merge of #144166 - matthiaskrgr:rollup-wccepuo, r=matthiaskrgrbors-41/+33
Rollup of 10 pull requests Successful merges: - rust-lang/rust#141076 (fix Zip unsoundness (again)) - rust-lang/rust#142444 (adding run-make test to autodiff) - rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner) - rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia) - rust-lang/rust#144083 (miri sleep tests: increase slack) - rust-lang/rust#144092 (bootstrap: Detect musl hosts) - rust-lang/rust#144098 (Do not lint private-in-public for RPITIT) - rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`) - rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling) - rust-lang/rust#144115 (fix outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-19interpret: fix TypeId pointers being considered data pointersRalf Jung-1/+1