about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2025-03-27Use char::is_whitespace directly in str::trim*DaniPopes-3/+3
2025-03-26Pass `Alignment` for `RawVecInner::new_in`James Wainwright-0/+8
Encodes the safety constraint that `Unique`'s pointer must be non-zero into the API.
2025-03-26Expose `Unique::from<NonNull>` in const internallyJames Wainwright-1/+7
2025-03-26Use cfg_match in coreChristopher Durham-118/+53
2025-03-26mark cfg_match! semitransparentChristopher Durham-3/+4
2025-03-26chore: remove redundant words in commentpudongair-3/+3
Signed-off-by: pudongair <744355276@qq.com>
2025-03-26Keeps the inspect() classification the same as in ResultHegui Dai-3/+7
2025-03-26Update the index of Result to make the summary more comprehensiveHegui Dai-2/+23
2025-03-26Add target-specific NaN payloads for the missing tier 2 targetsbeetrees-3/+5
2025-03-25Rollup merge of #138945 - DaniPopes:override-partialord-bool, r=scottmcmJacob Pratt-27/+23
Override PartialOrd methods for bool I noticed that `PartialOrd` implementation for `bool` does not override the individual operator methods, unlike the other primitive types like `char` and integers. This commit extracts these `PartialOrd` overrides shared by the other primitive types into a macro and calls it on `bool` too. CC `@scottmcm` for our recent adventures in `PartialOrd` land
2025-03-26Update the index.html of Option to make the summary more comprehensiveHegui Dai-2/+21
2025-03-25Override PartialOrd methods for boolDaniPopes-27/+23
I noticed that `PartialOrd` implementation for `bool` does not override the individual operator methods, unlike the other primitive types like `char` and integers. This commit extracts these `PartialOrd` overrides shared by the other primitive types into a macro and calls it on `bool` too.
2025-03-25Rollup merge of #135745 - bardiharborow:std/net/rfc9602, r=cuviperMatthias Krüger-0/+2
Recognise new IPv6 non-global range from IETF RFC 9602 This PR adds the `5f00::/16` range defined by [IETF RFC 9602](https://datatracker.ietf.org/doc/rfc9602/) to those ranges which `Ipv6Addr::is_global` recognises as a non-global IP. This range is used for Segment Routing (SRv6) SIDs. See also: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml Unstable tracking issue: #27709
2025-03-23Rollup merge of #138135 - scottmcm:chaining-ord, r=Mark-SimulacrumJacob Pratt-11/+109
Simplify `PartialOrd` on tuples containing primitives We noticed in https://github.com/rust-lang/rust/pull/133984#issuecomment-2704011800 that currently the tuple comparison code, while it [does optimize down](https://github.com/rust-lang/rust/blob/master/tests/codegen/comparison-operators-2-tuple.rs) today, is kinda huge: <https://rust.godbolt.org/z/xqMoeYbhE> This PR changes the tuple code to go through an overridable "chaining" version of the comparison functions, so that for simple things like `(i16, u16)` and `(f32, f32)` (as seen in the new MIR pre-codegen test) we just directly get the ```rust if lhs.0 == rhs.0 { lhs.0 OP rhs.0 } else { lhs.1 OP rhs.1 } ``` version in MIR, rather than emitting a mess for LLVM to have to clean up. Test added in the first commit, so you can see the MIR diff in the second one.
2025-03-23Stop using specialization for thisScott McMurray-82/+93
Uses `__`-named `doc(hidden)` methods instead.
2025-03-23Rollup merge of #138854 - TaKO8Ki:invalid-extern-fn-body, r=compiler-errorsMichael Goulet-1/+1
Fix ICE #138415 for invalid extern function body Fixes #138415
2025-03-23Rollup merge of #136040 - mu001999-contrib:cleanup, r=Mark-SimulacrumMichael Goulet-55/+0
Remove unused trait BoundedSize Detected by #128637 The usage of this trait is removed in #135104 r? `@the8472`
2025-03-23fix typoTakayuki Maeda-1/+1
2025-03-23Auto merge of #138833 - joboet:optimize-repeat-n, r=thomccbors-4/+55
core: optimize `RepeatN` ...by adding an optimized implementation of `try_fold` and `fold` as well as replacing some unnecessary `mem::replace` calls with `MaybeUninit` helper methods.
2025-03-22Auto merge of #138831 - matthiaskrgr:rollup-3t0dqiz, r=matthiaskrgrbors-0/+4
Rollup of 7 pull requests Successful merges: - #138609 (Add stack overflow handler for cygwin) - #138639 (Clean UI tests 2 of n) - #138773 (catch_unwind intrinsic: document return value) - #138782 (test(ui): add tuple-struct-where-clause-suggestion ui test for #91520) - #138794 (expand: Do not report `cfg_attr` traces on macros as unused attributes) - #138801 (triagebot: add autolabel rules for D-* and L-*) - #138804 (Allow inlining for `Atomic*::from_ptr`) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-22core: optimize `RepeatN`joboet-4/+55
...by adding an optimized implementation of `try_fold` and `fold` as well as replacing some unnecessary `mem::replace` calls with `MaybeUninit` helper methods.
2025-03-22Rollup merge of #138804 - tgross35:atomic-from-ptr-inline, r=RalfJungMatthias Krüger-0/+3
Allow inlining for `Atomic*::from_ptr` Currently this cannot be inlined, which among other things means it can't be used in `compiler-builtins` [1]. These are trivial functions that should be inlineable, so add `#[inline]`. [1]: https://github.com/rust-lang/compiler-builtins/pull/790#issuecomment-2744371738
2025-03-22Rollup merge of #138773 - RalfJung:catch_unwind_docs, r=jhprattMatthias Krüger-0/+1
catch_unwind intrinsic: document return value Seems like we forgot to document this. The comment reflects what Miri does, which seems to also match what codegen does at least [in `codegen_gnu_try`](https://github.com/rust-lang/rust/blob/b754ef727ca87050a8d758fc44f524cfb4310eff/compiler/rustc_codegen_llvm/src/intrinsic.rs#L953-L964).
2025-03-22Auto merge of #136974 - m-ou-se:fmt-options-64-bit, r=scottmcmbors-187/+234
Reduce FormattingOptions to 64 bits This is part of https://github.com/rust-lang/rust/issues/99012 This reduces FormattingOptions from 6-7 machine words (384 bits on 64-bit platforms, 224 bits on 32-bit platforms) to just 64 bits (a single register on 64-bit platforms). Before: ```rust pub struct FormattingOptions { flags: u32, // only 6 bits used fill: char, align: Option<Alignment>, width: Option<usize>, precision: Option<usize>, } ``` After: ```rust pub struct FormattingOptions { /// Bits: /// - 0-20: fill character (21 bits, a full `char`) /// - 21: `+` flag /// - 22: `-` flag /// - 23: `#` flag /// - 24: `0` flag /// - 25: `x?` flag /// - 26: `X?` flag /// - 27: Width flag (if set, the width field below is used) /// - 28: Precision flag (if set, the precision field below is used) /// - 29-30: Alignment (0: Left, 1: Right, 2: Center, 3: Unknown) /// - 31: Always set to 1 flags: u32, /// Width if width flag above is set. Otherwise, always 0. width: u16, /// Precision if precision flag above is set. Otherwise, always 0. precision: u16, } ```
2025-03-21Allow inlining for `Atomic*::from_ptr`Trevor Gross-0/+3
Currently this cannot be inlined, which among other things means it can't be used in `compiler-builtins` [1]. These are trivial functions that should be inlineable, so add `#[inline]`. [1]: https://github.com/rust-lang/compiler-builtins/pull/790#issuecomment-2744371738
2025-03-21Add todo comment on using a niche type for fmt flags.Mara Bos-0/+2
2025-03-21Rollup merge of #138717 - jdonszelmann:pin-macro, r=WaffleLapkinMatthias Krüger-0/+1
Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it Fixes a regression, see issue below. This is a temporary fix, super let is the real solution. Closes #138596
2025-03-21catch_unwind intrinsic: document return valueRalf Jung-0/+1
2025-03-21Recognise new IPv6 non-global range from RFC9602Bardi Harborow-0/+2
This commit adds the 5f00::/16 range defined by RFC9602 to those ranges which Ipv6Addr::is_global recognises as a non-global IP. This range is used for Segment Routing (SRv6) SIDs.
2025-03-21Rollup merge of #138650 - thaliaarchi:io-write-fmt-known, r=ibraheemdevMatthias Krüger-1/+2
Optimize `io::Write::write_fmt` for constant strings When the formatting args to `fmt::Write::write_fmt` are a statically known string, it simplifies to only calling `write_str` without a runtime branch. Do the same in `io::Write::write_fmt` with `write_all`. Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-19add rustc_macro_edition_2021Jana Dönszelmann-0/+1
2025-03-19Add chaining versions of lt/le/gt/ge and use them in tuple PartialOrdScott McMurray-11/+98
2025-03-19Rollup merge of #138540 - okaneco:const_split_off_first_last, r=m-ou-seMatthias Krüger-8/+18
core/slice: Mark some `split_off` variants unstably const Tracking issue: #138539 Add feature gate `#![feature(const_split_off_first_last)]` Mark `split_off_first`, `split_off_first_mut`, `split_off_last`, and `split_off_last_mut` slice methods unstably const
2025-03-19Rollup merge of #135394 - clarfonthey:uninit-slices-part-2, r=tgross35Matthias Krüger-139/+181
`MaybeUninit` inherent slice methods part 2 These were moved out of #129259 since they require additional libs-api approval. Tracking issue: #117428. New API surface: ```rust impl<T> [MaybeUninit<T>] { // replacing fill; renamed to avoid conflict pub fn write_filled(&mut self, value: T) -> &mut [T] where T: Clone; // replacing fill_with; renamed to avoid conflict pub fn write_with<F>(&mut self, value: F) -> &mut [T] where F: FnMut() -> T; // renamed to remove "fill" terminology, since this is closer to the write_*_of_slice methods pub fn write_iter<I>(&mut self, iter: I) -> (&mut [T], &mut Self) where I: Iterator<Item = T>; } ``` Relevant motivation for these methods; see #129259 for earlier methods' motiviations. * I chose `write_filled` since `filled` is being used as an object here, whereas it's being used as an action in `fill`. * I chose `write_with` instead of `write_filled_with` since it's shorter and still matches well. * I chose `write_iter` because it feels completely different from the fill methods, and still has the intent clear. In all of the methods, it felt appropriate to ensure that they contained `write` to clarify that they are effectively just special ways of doing `MaybeUninit::write` for each element of a slice. Tracking issue: https://github.com/rust-lang/rust/issues/117428 r? libs-api
2025-03-19use thenbendn-5/+1
2025-03-18Optimize io::Write::write_fmt for constant stringsThalia Archibald-1/+2
When the formatting args to `fmt::Write::write_fmt` are a statically known string, it simplifies to only calling `write_str` without a runtime branch. Do the same in `io::Write::write_fmt` with `write_all`. Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-17Rollup merge of #137449 - compiler-errors:control-flow, r=Amanieu,lnicolaMatthias Krüger-0/+1
Denote `ControlFlow` as `#[must_use]` I've repeatedly hit bugs in the compiler due to `ControlFlow` not being marked `#[must_use]`. There seems to be an accepted ACP to make the type `#[must_use]` (https://github.com/rust-lang/libs-team/issues/444), so this PR implements that part of it. Most of the usages in the compiler that trigger this new warning are "root" usages (calling into an API that uses control-flow internally, but for which the callee doesn't really care) and have been suppressed by `let _ = ...`, but I did legitimately find one instance of a missing `?` and one for a never-used `ControlFlow` value in #137448. Presumably this needs an FCP too, so I'm opening this and nominating it for T-libs-api. This PR also touches the tools (incl. rust-analyzer), but if this went into FCP, I'd split those out into separate PRs which can land before this one does. r? libs-api `@rustbot` label: T-libs-api I-libs-api-nominated
2025-03-17Auto merge of #138583 - jhpratt:rollup-h699hty, r=jhprattbors-3/+6
Rollup of 5 pull requests Successful merges: - #136293 (document capacity for ZST as example) - #136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove) - #136816 (refactor `notable_traits_button` to use iterator combinators instead of for loop) - #138552 (Misc print request handling cleanups + a centralized test for print request stability gating) - #138573 (Make `_Unwind_Action` a type alias, not enum) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-16Rollup merge of #136359 - hkBst:ptr_copy_docs, r=AmanieuJacob Pratt-3/+6
doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove Fixes #79430
2025-03-17Auto merge of #138363 - beetrees:f16-f128-integer-convert, r=Amanieubors-2/+48
Add `From<{integer}>` for `f16`/`f128` impls This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`. The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example: ```rust fn f<T: From<u64>>(x: T) -> T { x } fn main() { let x = f(1.0); // the type of the literal is inferred to be `f128` } ``` None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`. This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of #125198). cc `@bjoernager` r? `@tgross35` Tracking issue: #116909
2025-03-16Make ControlFlow must_useMichael Goulet-0/+1
2025-03-16Auto merge of #138537 - yotamofek:pr/lib/multi-char-pattern, r=jhprattbors-4/+4
Optimize multi-char string patterns Uses specialization for `[T]::contains` from #130991 to optimize multi-char patterns in string searches. Requesting a perf run to see if this actually has an effect 🙏 (I think that adding `char` to the list of types for which the `SliceContains` is specialized is a good idea, even if it doesn't show up on perf - might be helpful for downstream users)
2025-03-16Rollup merge of #135080 - Enselic:debug-ptr-metadata, r=thomcc许杰友 Jieyou Xu (Joe)-1/+26
core: Make `Debug` impl of raw pointers print metadata if present Make Rust pointers appear less magic by including metadata information in their `Debug` output. This does not break Rust stability guarantees because `Debug` impl are explicitly exempted from stability: https://doc.rust-lang.org/std/fmt/trait.Debug.html#stability > ## Stability > > Derived `Debug` formats are not stable, and so may change with future Rust versions. Additionally, `Debug` implementations of types provided by the standard library (`std`, `core`, `alloc`, etc.) are not stable, and may also change with future Rust versions. Note that a regression test is added as a separate commit to make it clear what impact the last commit has on the output. Closes #128684 because the output of that code now becomes: ``` thread 'main' panicked at src/main.rs:5:5: assertion `left == right` failed left: Pointer { addr: 0x7ffd45c6fc6b, metadata: 5 } right: Pointer { addr: 0x7ffd45c6fc6b, metadata: 3 } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```
2025-03-16Rollup merge of #138329 - scottmcm:assert-hint, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-0/+9
debug-assert that the size_hint is well-formed in `collect` Closes #137919 In the hopes of helping to catch any future accidentally-incorrect rustc or stdlib iterators (like the ones #137908 accidentally found), this has `Iterator::collect` call `size_hint` and check its `low` doesn't exceed its `Some(high)`. There's of course a bazillion more places this *could* be checked, but the hope is that this one is a good tradeoff of being likely to catch lots of things while having minimal maintenance cost (especially compared to putting it in *every* container's `from_iter`).
2025-03-16Rollup merge of #138323 - kpreid:offset-of-doc, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-36/+48
Expand and organize `offset_of!` documentation. * Give example of how to get the offset of an unsized tail field (prompted by discussion <https://github.com/rust-lang/rust/pull/133055#discussion_r1986422206>). * Specify the return type. * Add section headings. * Reduce “Visibility is respected…”, to a single sentence. * Move `offset_of_enum` documentation to unstable book (with link to it). * Add `offset_of_slice` documentation in unstable book. r? Mark-Simulacrum
2025-03-16Rollup merge of #138309 - DiuDiu777:intrinsic-doc-fix, r=thomcc许杰友 Jieyou Xu (Joe)-7/+24
Add missing doc for intrinsic (Fix PR135334) The previous [PR135334](https://github.com/rust-lang/rust/pull/135334) mentioned that some of the intrinsic APIs were missing safety descriptions. Among intrinsic APIs that miss safety specifications, most are related to numerical operations. They might need to be discussed and then seen how to organize. Apart from them, only a few intrinsics lack safety. So this PR deals with the APIs with non-numerical operations in priority.
2025-03-16Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc许杰友 Jieyou Xu (Joe)-114/+79
Remove `#[cfg(not(test))]` gates in `core` These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-16Rollup merge of #133055 - kpreid:clone-uninit-doc, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-30/+145
Expand `CloneToUninit` documentation. * Clarify relationship to `dyn` after #133003. * Add an example of using it with `dyn` as #133003 enabled. * Replace parameter name `dst` with `dest` to avoid confusion between abbreviations for “DeSTination” and “Dynamically-Sized Type”. * Add an example of implementing it. * Add links to Rust Reference for the mentioned concepts. * Mention that its method should rarely be called. * Various small corrections. Please review the `unsafe` code closely, as I am not an expert in the best possible ways to express these operations. (It might also be better to omit the implementation example entirely.) cc `@zachs18` #126799
2025-03-15core/slice: Mark some `split_off` variants unstably constokaneco-8/+18
Introduce feature `const_split_off_first_last` Mark `split_off_first`, `split_off_first_mut`, `split_off_last`, and `split_off_last_mut` unstably const
2025-03-15Optimize multi-char string patternsYotam Ofek-4/+4