about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2025-05-20Rollup merge of #141282 - DJMcNab:core-float-math-math, r=tgross35Matthias Krüger-772/+828
`core_float_math`: Move functions to `math` module When these functions were added in https://github.com/rust-lang/rust/pull/138087 It made a relatively common pattern for emulating these functions using an extension trait (which internally uses `libm`) much more fragile. If `core::f32` happened to be imported by the user (to access a constant, say), then that import in the module namespace would take precedence over the `f32` in the type namespace for resolving these functions, running headfirst into the stability attribute. We ran into this in [Color](https://github.com/linebender/color) and chose to release the remedial 0.3.1 and 0.2.4, to allow downstream crates to build on `docs.rs`. As these methods are perma-unstable, moving them into a new module should not have any long-term concerns, and ensures that this "breakage" doesn't adversely impact anyone else. I believe that I've made the module unstable correctly. I presume that this does not require a test to make sure stable code can't depend on the module existing? I've left the stability attribute on each function - happy to tweak this if a different pattern is more correct. Tracking issue for `core_float_math`: https://github.com/rust-lang/rust/issues/137578. This PR is as requested in https://github.com/rust-lang/rust/pull/138087. r? `@tgross35` Recommended reviewing with whitespace hidden. (This is my first PR to `std/core`/this repository, as far as I can remember)
2025-05-20`core_float_math`: Move functions to `math` folderDaniel McNab-772/+828
When these functions were added in https://github.com/rust-lang/rust/pull/138087 It made a relatively common pattern for emulating these functions using an extension trait (which internally uses `libm`) much more fragile. If `core::f32` happened to be imported by the user (to access a constant, say), then that import in the module namespace would take precedence over `f32` in the type namespace for resolving these functions, running headfirst into the stability attribute. We ran into this in Color - https://github.com/linebender/color - and chose to release the remedial 0.3.1 and 0.2.4, to allow downstream crates to build on `docs.rs`. As these methods are perma-unstable, moving them into a new module should not have any long-term concerns, and ensures that this breakage doesn't adversely impact anyone else.
2025-05-20use Self alias in self types rather than manually substituting itMichael Goulet-1/+1
2025-05-20Split `autodiff` into `autodiff_forward` and `autodiff_reverse`Marcelo Domínguez-1/+15
Pending fix. ``` error: cannot find a built-in macro with name `autodiff_forward` --> library\core\src\macros\mod.rs:1542:5 | 1542 | / pub macro autodiff_forward($item:item) { 1543 | | /* compiler built-in */ 1544 | | } | |_____^ error: cannot find a built-in macro with name `autodiff_reverse` --> library\core\src\macros\mod.rs:1549:5 | 1549 | / pub macro autodiff_reverse($item:item) { 1550 | | /* compiler built-in */ 1551 | | } | |_____^ error: could not compile `core` (lib) due to 2 previous errors ```
2025-05-20make std::intrinsic functions actually be intrinsicsRalf Jung-303/+309
2025-05-18add exact_div functionsJeremy Smart-1/+207
2025-05-19Rollup merge of #141110 - xizheyin:issue-141107, r=workingjubileeStuart Cook-2/+2
[std] fix the presentation of `split_off_mut` and `split_off` documentation Fixes #141107 r? libs
2025-05-18Auto merge of #127013 - tgross35:f16-format-parse, r=Mark-Simulacrumbors-4/+113
Add `f16` formatting and parsing Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing. try-job: x86_64-gnu-aux
2025-05-18Rollup merge of #138940 - sayantn:stabilize-avx512, r=Amanieu,traviscrossLeón Orell Valerian Liehr-1/+1
Stabilize the avx512 target features This PR stabilizes the AVX512 target features - see [this comment](https://github.com/rust-lang/rust/issues/111137#issuecomment-2745821279). Tracking Issue - #44839 The target feature UI tests have been changed to `x87` (chosen because this is very unlikely to stablize ever, please comment if some other feature will be better) related: #111137
2025-05-18float: Add `f16` parsing and printingTrevor Gross-4/+113
Use the existing Lemire (decimal -> float) and Dragon / Grisu algorithms (float -> decimal) to add support for `f16`. This allows updating the implementation for `Display` to the expected behavior for `Display` (currently it prints the a hex bitwise representation), matching other floats, and adds a `FromStr` implementation. In order to avoid crashes when compiling with Cranelift or on targets where f16 is not well supported, a fallback is used if `cfg(target_has_reliable_f16)` is not true.
2025-05-18[std] fix the presentation of `split_off_mut` and `split_off` documentationxizheyin-2/+2
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-18Rollup merge of #140511 - mathisbot:master, r=dtolnayLeón Orell Valerian Liehr-3/+4
Stabilize `#![feature(non_null_from_ref)]` This PR stabilizes the following: ```rust impl<T: ?Sized> NonNull<T> { pub const fn from_ref(reference: &T) -> NonNull<T>; pub const fn from_mut(reference: &mut T) -> NonNull<T>; } ``` The feature is tracked in [#130823](https://github.com/rust-lang/rust/issues/130823).
2025-05-18Stabilize `avx512_target_feature`sayantn-1/+1
2025-05-17Auto merge of #138087 - tgross35:core-float-math, r=Amanieubors-2/+1684
Initial implementation of `core_float_math` Since [1], `compiler-builtins` makes a certain set of math symbols weakly available on all platforms. This means we can begin exposing some of the related functions in `core`, so begin this process here. It is not possible to provide inherent methods in both `core` and `std` while giving them different stability gates, so standalone functions are added instead. This provides a way to experiment with the functionality while unstable; once it is time to stabilize, they can be converted to inherent. For `f16` and `f128`, everything is unstable so we can move the inherent methods. The following are included to start: * floor * ceil * round * round_ties_even * trunc * fract * mul_add * div_euclid * rem_euclid * powi * sqrt * abs_sub * cbrt These mirror the set of functions that we have in `compiler-builtins` since [1], with the exception of `powi` that has been there longer. Details for each of the changes is in the commit messages. Tracking issue: https://github.com/rust-lang/rust/issues/137578 [1]: https://github.com/rust-lang/compiler-builtins/pull/763 try-job: aarch64-gnu tru-job: armhf-gnu try-job: i686-msvc-1 try-job: test-various try-job: x86_64-mingw-1 try-job: x86_64-mingw-2
2025-05-17Rollup merge of #137432 - djscythe:char_u8_str_as_ascii_unchecked, r=scottmcmMatthias Krüger-0/+63
Add as_ascii_unchecked() methods to char, u8, and str This PR adds the `as_ascii_unchecked()` method to `char`, `u8`, and `str`, allowing users to convert these types to `ascii::Char`s (see #110998) in an `unsafe` context without first checking for validity. This method was already available for `[u8]`, so this PR makes the API more consistent across other types.
2025-05-17Switch library rustc_unimplemented to use `Self` and `This`mejrs-69/+66
2025-05-17Rollup merge of #140957 - JulianKnodt:array_must_use, r=Mark-SimulacrumMatthias Krüger-0/+1
Add `#[must_use]` to Array::map The output of Array::map is intended to be an array of the same size, and does not modify the original in place nor is it intended for side-effects. Thus, under normal circumstances it should be consumed. See [discussion](https://internals.rust-lang.org/t/array-map-annotate-with-must-use/22813/26). Attaching to tracking issue #75243
2025-05-16Implement `advance_by` via `try_fold` for `Sized` iteratorsBenoît du Garreau-5/+31
When `try_fold` is overriden, it is usually easier for compilers to optimize.
2025-05-16Add assert_unsafe_precondition!()s to as_ascii_unchecked() methodssam skeoch-0/+20
2025-05-16Add as_ascii_unchecked() methods to char, str, and u8sam skeoch-0/+43
2025-05-16Updated feature and stable flagsRyan van Polen-4/+3
2025-05-16Rollup merge of #140791 - xizheyin:issue-140761, r=ibraheemdevMatthias Krüger-2/+8
std: explain prefer `TryInto` over `TryFrom` when specifying traits bounds on generic function Fixes #140761 This PR keeps the explanations of `Into` and `From` consistent and adds explanations for `TryInto` and `TryFrom`. r? libs
2025-05-15Updated std doctests for wasmEric Huss-8/+8
This updates some doctests that fail to run on wasm. We will soon be supporting cross-compiled doctests, and the test-various job fails to run these tests. These tests fail because wasm32-wasip1 does not support threads.
2025-05-15Auto merge of #141050 - matthiaskrgr:rollup-uyzqbmj, r=matthiaskrgrbors-5/+5
Rollup of 7 pull requests Successful merges: - #139749 (docs(library/core/src/pin): fix typo "necessarily" -> "necessary") - #140685 (Simplify `Vec::as_non_null` implementation and make it `const`) - #140712 (normalization: avoid incompletely constraining GAT args) - #140768 (Improve `dangerous_implicit_aurorefs` diagnostic output) - #140947 (Flush errors before deep normalize in `dropck_outlives`) - #140990 (VxWorks: updates from recent libc versions) - #141027 (remove `RustfmtState` to reduce `initial_rustfmt` complexity) r? `@ghost` `@rustbot` modify labels: rollup
2025-05-15Rollup merge of #139749 - ↵Matthias Krüger-5/+5
ruancomelli:docs/library/core/src/pin/fix-typo-necessarily-to-necessary, r=joboet docs(library/core/src/pin): fix typo "necessarily" -> "necessary" Fix a typo in [`library/core/src/pin.rs`](https://github.com/ruancomelli/rust/blob/14662fabeb69fe5ab6c6e68051bf9f80d4aaaa35/library/core/src/pin.rs), from > As we'll see later, this is **necessarily** from the time the value is first pinned until the end of its lifespan. to > As we'll see later, this is **necessary** from the time the value is first pinned until the end of its lifespan. (my emphasis).
2025-05-15Auto merge of #136264 - GuillaumeGomez:optimize-integers-to-string, r=Amanieubors-9/+19
Optimize `ToString` implementation for integers Part of https://github.com/rust-lang/rust/issues/135543. Follow-up of https://github.com/rust-lang/rust/pull/133247 and https://github.com/rust-lang/rust/pull/128204. The benchmark results are: | name| 1.87.0-nightly (3ea711f17 2025-03-09) | With this PR | diff | |-|-|-|-| | bench_i16 | 32.06 ns/iter (+/- 0.12) | 17.62 ns/iter (+/- 0.03) | -45% | | bench_i32 | 31.61 ns/iter (+/- 0.04) | 15.10 ns/iter (+/- 0.06) | -52% | | bench_i64 | 31.71 ns/iter (+/- 0.07) | 15.02 ns/iter (+/- 0.20) | -52% | | bench_i8 | 13.21 ns/iter (+/- 0.14) | 14.93 ns/iter (+/- 0.16) | +13% | | bench_u16 | 31.20 ns/iter (+/- 0.06) | 16.14 ns/iter (+/- 0.11) | -48% | | bench_u32 | 33.27 ns/iter (+/- 0.05) | 16.18 ns/iter (+/- 0.10) | -51% | | bench_u64 | 31.44 ns/iter (+/- 0.06) | 16.62 ns/iter (+/- 0.21) | -47% | | bench_u8 | 10.57 ns/iter (+/- 0.30) | 13.00 ns/iter (+/- 0.43) | +22% | More information about it in [the original comment](https://github.com/rust-lang/rust/pull/136264#discussion_r1987542954). r? `@workingjubilee`
2025-05-14Rollup merge of #140988 - mathisbot:docfix_maybeuninit_write, r=tgross35Matthias Krüger-1/+1
MaybeUninit::write: fix doc # Fix doc for `MaybeUninit::write` The documentation refers to the way `MaybeUninit` stores data internally. The property of not dropping content on context exit is the responsibility of `ManuallyDrop`.
2025-05-14Skip {f32,f64}::mul_add tests on MinGWTrevor Gross-0/+6
Per [1], MinGW has an incorrect fma implementation. This showed up in tests run with cranelift after adding float math operations to `core`. Presumably we hadn't noticed this when running tests with LLVM because LLVM was constant folding the result away. Rust issue: https://github.com/rust-lang/rust/issues/140515 [1]: https://sourceforge.net/p/mingw-w64/bugs/848/
2025-05-14Add `Ipv4Addr` and `Ipv6Addr` diagnostic itemsSamuel Tardieu-0/+2
They will be used in Clippy to detect runtime parsing of known-valid IP addresses.
2025-05-14MaybeUninit::write: fix docMathis Bottinelli-1/+1
2025-05-13Initial implementation of `core_float_math`Trevor Gross-2/+1678
Since [1], `compiler-builtins` makes a certain set of math symbols weakly available on all platforms. This means we can begin exposing some of the related functions in `core`, so begin this process here. It is not possible to provide inherent methods in both `core` and `std` while giving them different stability gates, so standalone functions are added instead. This provides a way to experiment with the functionality while unstable; once it is time to stabilize, they can be converted to inherent. For `f16` and `f128`, everything is unstable so we can move the inherent methods. The following are included to start: * floor * ceil * round * round_ties_even * trunc * fract * mul_add * div_euclid * rem_euclid * powi * sqrt * abs_sub * cbrt These mirror the set of functions that we have in `compiler-builtins` since [1]. Tracking issue: https://github.com/rust-lang/rust/issues/137578 [1]: https://github.com/rust-lang/compiler-builtins/pull/763
2025-05-13Format and skip formatting for pinMichael Goulet-0/+2
2025-05-13Add `#[must_use]` to Array::mapJulian Knodt-0/+1
The output of Array::map is intended to be an array of the same size, and does not modify the original in place nor is it intended for side-effects. Thus, under normal circumstances it should be consumed. See [discussion](https://internals.rust-lang.org/t/array-map-annotate-with-must-use/22813/26). Attaching to tracking issue #75243
2025-05-12Specify that split_ascii_whitespace uses the same definition as ↵Simon Sapin-1/+3
is_ascii_whitespace
2025-05-12update cfg(bootstrap)Pietro Albini-66/+29
2025-05-12update version placeholdersPietro Albini-26/+26
2025-05-11Rollup merge of #140882 - Dietr1ch:dev/duration_constructors_lite, r=BurntSushiLeón Orell Valerian Liehr-4/+4
Split duration_constructors to get non-controversial constructors out This implements #140881
2025-05-11Rollup merge of #140792 - Urgau:minimum-maximum-intrinsics, ↵León Orell Valerian Liehr-84/+180
r=scottmcm,traviscross,tgross35 Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operations This PR creates intrinsics for `{f16,f32,f64,f64}::{minimum,maximum}` operations. This wasn't done when those operations were added as the LLVM support was too weak but now that LLVM has libcalls for unsupported platforms we can finally use them. Cranelift and GCC[^1] support are partial, Cranelift doesn't support `f16` and `f128`, while GCC doesn't support `f16`. r? `@tgross35` try-job: aarch64-gnu try-job: dist-various-1 try-job: dist-various-2 [^1]: https://www.gnu.org/software///gnulib/manual/html_node/Functions-in-_003cmath_002eh_003e.html
2025-05-10Rollup merge of #140660 - RalfJung:more-order, r=WaffleLapkinMatthias Krüger-12/+0
remove 'unordered' atomic intrinsics As their doc comment already indicates, these operations do not currently have a place in our memory model. The intrinsics were introduced to support a hack in compiler-builtins, but that hack recently got removed (see https://github.com/rust-lang/compiler-builtins/issues/788).
2025-05-10Rollup merge of #140151 - RalfJung:drop_in_place-is-not-an-intrinsic, ↵Matthias Krüger-9/+0
r=Mark-Simulacrum remove intrinsics::drop_in_place This was only ever accidentally stable, and has been marked as deprecated since Rust 1.52, released almost 4 years ago. We've removed the old serialization `derive`s, maybe we can remove this one as well? As suggested by ``@jhpratt,`` let's see what crater says for this one.
2025-05-10Rollup merge of #129334 - ChayimFriedman2:more-lazy-methods, r=AmanieuMatthias Krüger-1/+9
Implement (part of) ACP 429: add `DerefMut` to `Lazy[Cell/Lock]` `DerefMut` is instantly stable, as a trait impl. That means this needs an FCP. ``@rustbot`` label +needs-fcp https://github.com/rust-lang/libs-team/issues/429
2025-05-09Split duration_constructors to get non-controversial bits out faster.Dietrich Daroch-4/+4
2025-05-09Add intrinsic fallback for `{minimum,maximum}{16,32,64,128}`Urgau-164/+108
2025-05-09remove 'unordered' atomic intrinsicsRalf Jung-12/+0
2025-05-09Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operationsUrgau-76/+228
2025-05-08Rollup merge of #140341 - saethlin:black-box-qoi, r=Mark-SimulacrumMatthias Krüger-0/+4
Clarify black_box warning a bit Trying to bring the docs on black_box more in line with the advice that we have discussed in Zulip. https://github.com/rust-lang/rust/pull/140341#issuecomment-2832592382
2025-05-08Indicate that the warning on black_box is a general property of RustBen Kimock-0/+4
And note that the same limitation applies to all LLVM-based compilers Co-authored-by: Ralf Jung <post@ralfj.de>
2025-05-08std: Explain prefer `TryInto` over `TryFrom` when specifying traits bounds ↵xizheyin-0/+6
on generic function Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-08std: Make consistence between `From` and `Into`xizheyin-2/+2
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-07Rollup merge of #134273 - RalfJung:de-stabilize-bench, r=ibraheemdev,traviscrossJacob Pratt-1/+0
de-stabilize bench attribute This has been soft-unstable since forever (https://github.com/rust-lang/rust/pull/64066), and shown in future-compat reports since Rust 1.77 (https://github.com/rust-lang/rust/pull/116274). The feature covering `bench` itself is tracked in https://github.com/rust-lang/rust/issues/50297, which has been closed despite still having active feature gates referencing it. Cc `@rust-lang/libs-api`