Commit Graph

9459 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
2f6811eff8 Rollup merge of #138940 - sayantn:stabilize-avx512, r=Amanieu,traviscross
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-18 18:44:10 +02:00
Trevor Gross
6fc60b8b04 float: Add f16 parsing and printing
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 16:43:13 +00:00
xizheyin
8b48bac63d [std] fix the presentation of split_off_mut and split_off documentation
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-18 23:22:08 +08:00
León Orell Valerian Liehr
15859331d0 Rollup merge of #140511 - mathisbot:master, r=dtolnay
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-18 11:03:44 +02:00
sayantn
cf7caded0b Stabilize avx512_target_feature 2025-05-18 11:12:15 +05:30
bors
777d372772 Auto merge of #138087 - tgross35:core-float-math, r=Amanieu
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-17 19:31:39 +00:00
Matthias Krüger
eb01ba0b57 Rollup merge of #137432 - djscythe:char_u8_str_as_ascii_unchecked, r=scottmcm
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-17 15:45:19 +02:00
mejrs
c9b6ccc11c Switch library rustc_unimplemented to use Self and This 2025-05-17 12:50:37 +02:00
Matthias Krüger
642cd65ab2 Rollup merge of #140957 - JulianKnodt:array_must_use, r=Mark-Simulacrum
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-17 10:33:09 +02:00
Benoît du Garreau
5240cd3a82 Implement advance_by via try_fold for Sized iterators
When `try_fold` is overriden, it is usually easier for compilers to
optimize.
2025-05-16 15:46:44 +02:00
sam skeoch
101e24a223 Add assert_unsafe_precondition!()s to as_ascii_unchecked() methods 2025-05-16 13:54:02 +01:00
sam skeoch
7d9f437f99 Add as_ascii_unchecked() methods to char, str, and u8 2025-05-16 13:53:32 +01:00
Ryan van Polen
7e3e8bdec4 Updated feature and stable flags 2025-05-16 11:59:08 +02:00
Matthias Krüger
315296b0b9 Rollup merge of #140791 - xizheyin:issue-140761, r=ibraheemdev
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-16 07:19:38 +02:00
Eric Huss
db950fa77f Updated std doctests for wasm
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-15 19:59:22 -07:00
bors
6d1875f99b Auto merge of #141050 - matthiaskrgr:rollup-uyzqbmj, r=matthiaskrgr
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-15 23:30:38 +00:00
Matthias Krüger
8768188533 Rollup merge of #139749 - 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`](14662fabeb/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-15 22:28:49 +02:00
bors
d97326eabf Auto merge of #136264 - GuillaumeGomez:optimize-integers-to-string, r=Amanieu
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-15 20:20:30 +00:00
Matthias Krüger
8395461fa4 Rollup merge of #140988 - mathisbot:docfix_maybeuninit_write, r=tgross35
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-14 18:43:40 +02:00
Trevor Gross
65117eeda8 Skip {f32,f64}::mul_add tests on MinGW
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-14 14:30:03 +00:00
Samuel Tardieu
7b1ba425e7 Add Ipv4Addr and Ipv6Addr diagnostic items
They will be used in Clippy to detect runtime parsing of known-valid
IP addresses.
2025-05-14 09:34:25 +02:00
Mathis Bottinelli
c610177558 MaybeUninit::write: fix doc 2025-05-14 09:02:22 +02:00
Trevor Gross
36790d2881 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].

Tracking issue: https://github.com/rust-lang/rust/issues/137578

[1]: https://github.com/rust-lang/compiler-builtins/pull/763
2025-05-13 22:08:18 +00:00
Michael Goulet
8ce7783c7c Format and skip formatting for pin 2025-05-13 11:30:39 +02:00
Julian Knodt
ab1c49a7fa 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-13 12:34:53 +09:00
Simon Sapin
9a0c85655c Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace 2025-05-12 18:43:00 +02:00
Pietro Albini
2ce08ca5d6 update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Pietro Albini
a360940ac9 update version placeholders 2025-05-12 15:33:30 +02:00
León Orell Valerian Liehr
e5835d5f76 Rollup merge of #140882 - Dietr1ch:dev/duration_constructors_lite, r=BurntSushi
Split duration_constructors to get non-controversial constructors out

This implements #140881
2025-05-11 02:44:39 +02:00
León Orell Valerian Liehr
3c8950c30d Rollup merge of #140792 - Urgau:minimum-maximum-intrinsics, 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-11 02:44:36 +02:00
Matthias Krüger
b8c55b438d Rollup merge of #140660 - RalfJung:more-order, r=WaffleLapkin
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-10 16:26:02 +02:00
Matthias Krüger
f28428ea58 Rollup merge of #140151 - RalfJung:drop_in_place-is-not-an-intrinsic, 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-10 16:26:02 +02:00
Matthias Krüger
c6b9253ad5 Rollup merge of #129334 - ChayimFriedman2:more-lazy-methods, r=Amanieu
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-10 16:26:01 +02:00
Dietrich Daroch
ed799c2019 Split duration_constructors to get non-controversial bits out faster. 2025-05-09 22:52:39 -04:00
Urgau
dc69020aa4 Add intrinsic fallback for {minimum,maximum}{16,32,64,128} 2025-05-09 20:58:06 +02:00
Ralf Jung
79dfd0a472 remove 'unordered' atomic intrinsics 2025-05-09 17:39:52 +02:00
Urgau
e7247df590 Use intrinsics for {f16,f32,f64,f128}::{minimum,maximum} operations 2025-05-09 17:11:23 +02:00
Matthias Krüger
32e3207969 Rollup merge of #140341 - saethlin:black-box-qoi, r=Mark-Simulacrum
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-08 20:22:13 +02:00
Ben Kimock
f501775ec8 Indicate that the warning on black_box is a general property of Rust
And note that the same limitation applies to all LLVM-based compilers

Co-authored-by: Ralf Jung <post@ralfj.de>
2025-05-08 09:03:57 -04:00
xizheyin
4101d90818 std: Explain prefer TryInto over TryFrom when specifying traits bounds on generic function
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-08 18:12:05 +08:00
xizheyin
b6c2a429ef std: Make consistence between From and Into
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-08 18:09:29 +08:00
Jacob Pratt
60a4b939a3 Rollup merge of #134273 - RalfJung:de-stabilize-bench, r=ibraheemdev,traviscross
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`
2025-05-07 00:29:20 +00:00
Guillaume Gomez
8929f8a180 Rollup merge of #136183 - hkBst:patch-25, r=Amanieu
Update iterator.rs to use arrays by value

Update examples to no longer avoid iterating arrays for #84513
2025-05-06 19:27:38 +02:00
Marijn Schouten
18a3599fe3 Update iterator.rs to use arrays by value
Update examples to no longer avoid iterating arrays for #84513
2025-05-06 12:19:24 +00:00
Stuart Cook
6238555e72 Rollup merge of #140598 - ShE3py:iter-misc-docs, r=workingjubilee
Steer docs to `utf8_chunks` and `Iterator::take`

- Adds `limit` as an alias of `take` (as this is [what Java calls this operation](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#limit-long-));
- Says that [`Utf8Chunks`](https://doc.rust-lang.org/std/str/struct.Utf8Chunks.html) comes from [`[u8]::utf8_chunks`](https://doc.rust-lang.org/std/primitive.slice.html#method.utf8_chunks).

``@rustbot`` label +A-docs
2025-05-06 16:28:41 +10:00
Michael Rieder
1ddb4d0062 Fix parameter order for _by() variants of min / max/ minmax in std::cmp 2025-05-05 13:06:39 +02:00
Trevor Gross
cac28ed674 Rollup merge of #140644 - the8472:revert-copy-clone-adapters, r=Mark-Simulacrum
Revert "Avoid unused clones in Cloned<I> and Copied<I>"

Per libs decision in https://github.com/rust-lang/rust/issues/140207#issuecomment-2842996190 this reverts commit ed5f31ab01 (#139745)
2025-05-05 00:20:58 -04:00
Trevor Gross
fcb9da597a Rollup merge of #137280 - RalfJung:const_swap_nonoverlapping, r=lcnr
stabilize ptr::swap_nonoverlapping in const

Closes https://github.com/rust-lang/rust/issues/133668

The blocking issue mentioned there is resolved by documentation. We may in the future actually support such code, but that is blocked on https://github.com/rust-lang/const-eval/issues/72 which is non-trivial to implement. Meanwhile, this completes stabilization of all `const fn` in `ptr`. :)

Here's a version of the problematic example to play around with:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6c390452379fb593e109b8f8ee854d2a

Should be FCP'd with both `@rust-lang/libs-api`  and `@rust-lang/lang`  since  `swap_nonoverlapping` is documented to work as an "untyped" operation but due to the limitation mentioned above, that's not entirely true during const evaluation. I expect this limitation will only be hit in niche corner cases, so the benefits of having this function work most of the time outweigh the downsides of users running into this problem. (Note that unsafe code could already hit this limitation before this PR by doing cursed pointer casts, but having it hidden inside `swap_nonoverlapping` feels a bit different.)
2025-05-04 18:11:47 -04:00
The 8472
e6030468dd Revert "Avoid unused clones in Cloned<I> and Copied<I>"
This reverts commit ed5f31ab01.
2025-05-04 22:29:57 +02:00
Lieselotte
415a73e3eb docs: alias limit to Iterator::take, cite [u8]::utf8_chunks in Utf8Chunks 2025-05-02 23:41:52 +02:00