about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2025-06-12Delegate `<CStr as Debug>` to `ByteStr`Tamir Duberstein-1/+3
This allows UTF-8 characters to be printed without escapes, rather than just ASCII.
2025-06-12intrinsics: rename min_align_of to align_ofRalf Jung-18/+10
2025-06-12Tracking the old name of renamed unstable library attributexizheyin-18/+18
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-12chore(doctest): Remove redundant blank linesShun Sakai-3/+0
2025-06-12Allow `unpredictable_function_pointer_comparisons` lint in more placesUrgau-0/+1
2025-06-12Auto merge of #136594 - pascaldekloe:fmt-int128, r=tgross35bors-152/+128
Faster fmt::Display of 128-bit integers, without unsafe pointer In followup of #135265, hereby the 128-bit part. * Batches per 16 instead of 19 digits * Buffer access as array insteaf of unsafe pointer * Added test coverage for i128 and u128 r? tgross35 ChrisDenton
2025-06-11Fix Debug for Location.Mara Bos-1/+12
2025-06-11stabilize gaiBoxy-1/+0
2025-06-11faster fmt::Display of 128-bit integers, without unsafe pointerPascal S. de Kloe-152/+128
2025-06-11Add trim_prefix and trim_suffix for slice and str.Deven T. Corzine-0/+160
Implements `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types which remove at most one occurrence of a prefix/suffix while always returning a string/slice (rather than Option), enabling easy method chaining.
2025-06-11feat: Add `bit_width` for unsigned integer typesShun Sakai-0/+24
2025-06-10core docs: improve clarity of considerations about atomic CAS operationsGray Olson-33/+146
- Rewords existing Considerations section on `fetch_update` and friends to make clear that the limitations are inherent to an implementation based on any CAS operation, rather than the weak version of `compare_exchange` in particular - Add Considerations to `compare_exchange` and `compare_exchange_weak` which details similar considerations and when they may be relevant.
2025-06-10Rollup merge of #142262 - aDotInTheVoid:nomemchr, r=NoratriebLeón Orell Valerian Liehr-0/+1
Mark `core::slice::memchr` as `#[doc(hidden)]` It's purely internal, and not intended to be a public API, even on nightly. This stops it showing up and being misleading in rustdoc search. It also mirrors the (also internal) `core::slice::sort` module.
2025-06-10Rollup merge of #142101 - lolbinarycat:core-dedup-ptr-docs-139190-pt2, ↵León Orell Valerian Liehr-126/+68
r=workingjubilee core::ptr: deduplicate more method docs used `rg -Fxf library/core/src/ptr/{const,mut}_ptr.rs` to find duplicated doc comments, and `diff -u` after copying them to files to ensure they are actually identical. `sed 's| */// *||'` was then used to translate the doc comments to plain markdown. part of https://github.com/rust-lang/rust/issues/139190
2025-06-10Rollup merge of #140766 - sayantn:stabilize-keylocker, r=traviscross,tgross35León Orell Valerian Liehr-1/+0
Stabilize keylocker This PR stabilizes the feature flag `keylocker_x86` (tracking issue rust-lang/rust#134813). # Public API The 2 `x86` target features `kl` and `widekl`, and the associated intrinsics in stdarch. These target features are very specialized, and are only used to signal the presence of the corresponding CPU instruction. They don't have any nontrivial interaction with the ABI (contrary to something like AVX), and serve the only purpose of enabling 11 stdarch intrinsics, all of which have been implemented and propagated to rustc via a stdarch submodule update. Also, these were added way back in LLVM12, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too! # Associated PRs - rust-lang/rust#134814 - rust-lang/stdarch#1706 - rust-lang/rust#136831 (stdarch submodule update) - rust-lang/stdarch#1795 (stabilizing the runtime detection and intrinsics) - rust-lang/rust#141964 (stdarch submodule update for the stabilization of the runtime detection and intrinsics) As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now. cc ````@rust-lang/lang```` cc ````@rust-lang/libs-api```` for the intrinsics and runtime detection I don't think anyone else worked on this feature, so no one else to ping, maybe cc ````@Amanieu.```` I will send the reference pr soon.
2025-06-10Rollup merge of #134442 - epage:change, r=workingjubileeLeón Orell Valerian Liehr-0/+13
Specify the behavior of `file!` This takes the current behavior of `file!` and documents it so it is safe to make assumptions about. For example, Cargo could provide a `CARGO_RUSTC_CURRENT_DIR` as a base path for `file!`. Example use cases - Being able to look up test assets relative to the current file ([example](https://github.com/rust-lang/cargo/blob/b9026bf654d7fac283465e58b8b76742244ef07d/tests/testsuite/cargo_add/add_basic/mod.rs#L34)) - Inline snapshotting libraries being able to update Rust source code ([example](https://github.com/rust-lang/cargo/blob/b9026bf654d7fac283465e58b8b76742244ef07d/tests/testsuite/alt_registry.rs#L36-L45)) See rust-lang/cargo#3946 for more context. T-libs-api discussed two solutions in rust-lang/libs-team#478 - `file_absolute!`: - Has less meaning in other build tools like buck2 - Bakes in the assumption that a full path is available (e.g. with trim-paths) - Specifying `file!`s behavior (this PR): - Leaves it to the user to deal with trim-paths - Even though `file!` is currently unspecified, changing it would likely have too large of an impact on the ecosystem at this time. A future possibility is that rustc could have a flag that controls modifies the base path used for `file!`. That seems purely additive with specifying the behavior and we do not want to block on it. It would also likely be too disruptive for Cargo users (as mentioned). However, we tried to keep this in mind when specifying the behavior.
2025-06-09Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJungbors-2/+2
Enable Non-determinism of float operations in Miri and change std tests Links to [#4208](https://github.com/rust-lang/miri/issues/4208) and [#3555](https://github.com/rust-lang/miri/issues/3555) in Miri. Non-determinism of floating point operations was disabled in rust-lang/rust#137594 because it breaks the tests and doc-tests in core/coretests and std. This PR enables some of them. This pr includes the following changes: - Enables the float non-determinism but with a lower relative error of 4ULP instead of 16ULP - These operations now have a fixed output based on the C23 standard, except the pow operations, this is tracked in [#4286](https://github.com/rust-lang/miri/issues/4286#issue-3010677983) - Changes tests that made incorrect assumptions about the operations, not to make that assumption anymore (from `assert_eq!` to `assert_approx_eq!`. - Changed the doctests of the stdlib of these operations to compare against fixed constants instead of `f*::EPSILON`, which now succeed with Miri and `-Zmiri-many-seeds` - Added a constant `APPROX_DELTA` in `std/tests/floats/f32.rs` which is used for approximation tests, but with a different value when run in Miri. This is to make these tests succeed. - Added tests in the float tests of Miri to test the C23 behaviour. Fixes https://github.com/rust-lang/miri/issues/4208
2025-06-09Specify the behavior of `file!`Ed Page-0/+13
This takes the current behavior of `file!` and documents it so it is safe to make assumptions about. For example, Cargo could provide a `CARGO_RUSTC_CURRENT_DIR` as a base path for `file!`. Example use cases - Being able to look up test assets relative to the current file ([example](https://github.com/rust-lang/cargo/blob/b9026bf654d7fac283465e58b8b76742244ef07d/tests/testsuite/cargo_add/add_basic/mod.rs#L34)) - Inline snapshotting libraries being able to update Rust source code ([example](https://github.com/rust-lang/cargo/blob/b9026bf654d7fac283465e58b8b76742244ef07d/tests/testsuite/alt_registry.rs#L36-L45)) T-libs-api discussed two solutions - `file_absolute!`: - Has less meaning in other build tools like buck2 - Bakes in the assumption that a full path is available (e.g. with trim-paths) - Specifying `file!`s behavior (this PR): - Leaves it to the user to deal with trim-paths - Even though `file!` is currently unspecified, changing it would likely have too large of an impact on the ecosystem at this time. A future possibility is that rustc could have a flag that controls modifies the base path used for `file!`. That seems purely additive with specifying the behavior and we do not want to block on it. It would also likely be too disruptive for Cargo users (as mentioned). However, we tried to keep this in mind when specifying the behavior.
2025-06-09Mark `core::slice::memchr` as `#[doc(hidden)]`Alona Enraght-Moony-0/+1
It's purely internal, and not intended to be a public API, even on nightly. This stops it showing up and being misleading in rustdoc search. It also mirrors the (also internal) `core::slice::sort` module.
2025-06-09core::ptr: deduplicate more method docsbinarycat-126/+68
2025-06-09Rollup merge of #142238 - RalfJung:nonnull_provenance, r=workingjubileeTrevor Gross-3/+4
stabilize nonnull_provenance Fixes https://github.com/rust-lang/rust/issues/135243 FCP passed in https://github.com/rust-lang/rust/issues/135243
2025-06-09Rollup merge of #141001 - hkBst:nonzero-char, r=dtolnayTrevor Gross-0/+3
Make NonZero<char> possible I'd like to use `NonZero<char>` for representing units of CStr in https://github.com/rust-lang/literal-escaper
2025-06-09Rollup merge of #140767 - sayantn:stabilize-sha512, r=traviscross,tgross35Trevor Gross-1/+0
Stabilize `sha512`, `sm3` and `sm4` for x86 This PR stabilizes the feature flag `sha512_sm_x86` (tracking issue rust-lang/rust#126624). # Public API The 3 `x86` target features `sha512`, `sm3` and `sm4`, and the associated intrinsics in stdarch. These target features are very specialized, and are only used to signal the presence of the corresponding CPU instruction. They don't have any nontrivial interaction with the ABI (contrary to something like AVX), and serve the only purpose of enabling 10 stdarch intrinsics, all of which have been implemented and propagated to rustc via a stdarch submodule update. Also, these were added in LLVM17, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too! # Associated PRs - rust-lang/rust#126704 - rust-lang/stdarch#1592 - rust-lang/stdarch#1790 - rust-lang/rust#140389 (stdarch submodule update) - rust-lang/stdarch#1796 (stabilizing the runtime detection and intrinsics) - rust-lang/rust#141964 (stdarch submodule update for the stabilization of the runtime detection and intrinsics) As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now. cc `@rust-lang/lang` cc `@rust-lang/libs-api` for the intrinsics and runtime detection I don't think anyone else worked on this feature, so no one else to ping, maybe cc `@Amanieu.` I will send the reference pr soon.
2025-06-09Auto merge of #142242 - matthiaskrgr:rollup-1sgx0ji, r=matthiaskrgrbors-46/+2
Rollup of 7 pull requests Successful merges: - rust-lang/rust#129121 (Stabilize `tcp_quickack`) - rust-lang/rust#142192 (De-duplicate f16 & f128 doctest attributes) - rust-lang/rust#142193 (add tests for pattern binding drop order edge cases) - rust-lang/rust#142222 (Dont make `ObligationCtxt`s with diagnostics unnecessarily) - rust-lang/rust#142228 (rustc-dev-guide subtree update) - rust-lang/rust#142231 (Run `calculate_matrix` job on `master` to cache citool builds) - rust-lang/rust#142232 (add `Cargo.lock` to CI-rustc allowed list for non-CI env) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-09Rollup merge of #142192 - Urgau:dedup-f16-f128-test-attrs, r=tgross35Matthias Krüger-46/+2
De-duplicate f16 & f128 doctest attributes Now that rustdoc supports `#[doc(test(attr(...)))]` at every level, thanks to https://github.com/rust-lang/rust/pull/140560, we can de-duplicate the f16 & f128 doctest attributes. Unfortunately we can de-duplicate the `cfg`s attribute as rustdoc would complain about missing `main`, but it's already much better than before. Addresses https://github.com/rust-lang/rust/pull/140323/files#r2062702761 r? `@tgross35`
2025-06-09stabilize nonnull_provenanceRalf Jung-3/+4
2025-06-09Rollup merge of #142160 - Urgau:check-cfg-bootstrap-only-rustc, r=KobzolMatthias Krüger-1/+1
Only allow `bootstrap` cfg in rustc & related Fixes https://github.com/rust-lang/rust/issues/142150 r? bootstrap
2025-06-08Rollup merge of #142162 - RalfJung:unsafe-pinned-get, ↵Jubilee-17/+16
r=workingjubilee,traviscross UnsafePinned: update get() docs and signature to allow shared mutation Follow-up to https://github.com/rust-lang/rust/pull/140638, making `get` consistent with the fact that there's an `UnsafeCell` inside this type now by returning `*mut T` instead of `*const T`. Cc ``@rust-lang/libs-api`` Tracking issue: https://github.com/rust-lang/rust/issues/125735
2025-06-08Rollup merge of #142053 - heiher:loong32-none, r=wesleywiserJubilee-3/+7
Add new Tier-3 targets: `loongarch32-unknown-none*` MCP: https://github.com/rust-lang/compiler-team/issues/865 NOTE: LoongArch32 ELF object support is available starting with object v0.37.0.
2025-06-08Remove rustc's notion of "preferred" alignment AKA `__alignof`Jubilee Young-9/+0
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`. However, the intrinsic and its supporting code 1. is a nightly feature, so can be removed at compiler/libs discretion 2. requires considerable effort in the compiler to support, as it necessarily complicates every single site reasoning about alignment 3. has been justified based on relevance to codegen, but it is only a requirement for C++ (not C, not Rust) stack frame layout for AIX, in ways Rust would not consider even with increased C++ interop 4. is only used by rustc to overalign some globals, not correctness 5. can be adequately replaced by other rules for globals, as it mostly affects alignments for a few types under 16 bytes of alignment 6. has only one clear benefactor: automating C -> Rust translation for GNU extensions like `__alignof` 7. such code was likely intended to be `alignof` or `_Alignof`, because the GNU extension is a "false friend" of the C keyword, which makes the choice to support such a mapping very questionable 8. makes it easy to do incorrect codegen in the compiler by its mere presence as usual Rust rules of alignment (e.g. `size == align * N`) do not hold with preferred alignment The implementation is clearly damaging the code quality of the compiler. Thus it is within the compiler team's purview to simply rip it out. If T-lang wishes to have this intrinsic restored for c2rust's benefit, it would have to use a radically different implementation that somehow does not cause internal incorrectness. Until then, remove the intrinsic and its supporting code, as one tool and an ill-considered GCC extension cannot justify risking correctness. Because we touch a fair amount of the compiler to change this at all, and unfortunately the duplication of AbiAndPrefAlign is deep-rooted, we keep an "AbiAlign" type which we can wean code off later.
2025-06-08Auto merge of #141700 - RalfJung:atomic-intrinsics-part2, r=bjorn3bors-985/+211
Atomic intrinsics : use const generic ordering, part 2 This completes what got started in https://github.com/rust-lang/rust/pull/141507 by using a const generic for the ordering for all intrinsics. It is based on that PR; only the last commit is new. Blocked on: - https://github.com/rust-lang/rust/pull/141507 - https://github.com/rust-lang/rust/pull/141687 - https://github.com/rust-lang/stdarch/pull/1811 - https://github.com/rust-lang/rust/pull/141964 r? `@bjorn3`
2025-06-08Mark `slice::swap_with_slice` unstably constPaolo Barbolini-1/+2
2025-06-08De-duplicate f16 & f128 doctest attributesUrgau-46/+2
2025-06-07Rollup merge of #142154 - RalfJung:no-more-cfg-bootstrap, r=oli-obkGuillaume Gomez-3/+0
get rid of spurious cfg(bootstrap) r? ```@oli-obk```
2025-06-07Rollup merge of #142065 - ↵Guillaume Gomez-2/+2
paolobarbolini:stabilize-const_eq_ignore_ascii_case, r=Mark-Simulacrum Stabilize `const_eq_ignore_ascii_case` Tracking issue: rust-lang/rust#131719 Closes rust-lang/rust#131719 FCP Completed: https://github.com/rust-lang/rust/issues/131719#issuecomment-2941829167
2025-06-07Rollup merge of #141447 - y86-dev:option-layout-docs, r=RalfJungGuillaume Gomez-1/+1
Document representation of `Option<unsafe fn()>` https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Option.20Layout.20with.20.60fn.60.20pointers/with/520055652
2025-06-07centralize aliasing rules discussion in UnsafeCell docsRalf Jung-15/+11
2025-06-07intrinsics: use const generic to set atomic orderingRalf Jung-985/+211
2025-06-07Address documentation issues identified with FutureDiggory Blake-7/+16
2025-06-07Stabilize `sha512_sm_x86`, and the `sha512`, `sm3` and `sm4` target featuressayantn-1/+0
2025-06-07Stabilize the `keylocker_x86` flag, and the `kl` and `widekl` target featuressayantn-1/+0
2025-06-07Fix usage of `bootstrap` in coreUrgau-4/+1
2025-06-07UnsafePinned: update get() docs and signature to allow shared mutationRalf Jung-9/+12
2025-06-07Make NonZero<char> possibleMarijn Schouten-0/+3
2025-06-07get rid of spurious cfg(bootstrap)Ralf Jung-3/+0
2025-06-06Rollup merge of #142114 - GuillaumeGomez:u128-const, r=UrgauGuillaume Gomez-2/+2
Compute number of digits instead of relying on constant value for u128 display code As discussed in https://github.com/rust-lang/rust/pull/142098/files#r2132084991, the code should reuse the same logic as the rest of file instead of using a constant value. r? `@tamird`
2025-06-06Compute number of digits instead of relying on constant value for u128 ↵Guillaume Gomez-2/+2
display code
2025-06-06remove extraneous textTshepang Mbambo-33/+0
"Basic usage" implies there is an example that shows advanced usage
2025-06-06Add new Tier-3 targets: `loongarch32-unknown-none*`WANG Rui-3/+7
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-06-05change tests to use fixed constants to let them pass with miriLorrensP-2158466-2/+2