Commit Graph

9393 Commits

Author SHA1 Message Date
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
Matthias Krüger
15f21f43b3 Rollup merge of #140550 - Amanieu:stabilize_select_unpredictable, r=workingjubilee
Stabilize `select_unpredictable`

FCP completed in tracking issue #133962.
2025-05-02 19:37:59 +02:00
Stuart Cook
27d419a6b5 Rollup merge of #140389 - sayantn:avx512fp16, r=Amanieu
Remove `avx512dq` and `avx512vl` implication for `avx512fp16`

According to Intel, `avx512fp16` requires only `avx512bw`, but LLVM also enables `avx512vl` and `avx512dq` when `avx512fp16` is active. This is relic code, and will be fixed in LLVM soon. We should remove this from Rust too asap, especially before the stabilization of AVX512

Related:
 - llvm/llvm-project#136209
 - #138940
 - rust-lang/stdarch#1781
 - #111137

``@rustbot`` label O-x86_64 O-x86_32 A-SIMD A-target-feature T-compiler -T-libs
r? ``@Amanieu``

**Update: the LLVM fix has been merged**

cc ``@rust-lang/wg-llvm`` will it be possible to update the rustc llvm version to something after llvm/llvm-project#137450
2025-05-02 22:17:02 +10:00
Guillaume Gomez
6cb75d88eb Rollup merge of #140544 - m-ou-se:format-args-const-cleanup, r=fee1-dead
Clean up "const" situation in format_args!().

This cleans up the "const" situation in the format_args!() expansion/lowering.

Rather than marking the Argument::new_display etc. functions as non-const, this marks the Arguments::new_v1 functions as non-const.

Example expansion/lowering of format_args!() in const:

```rust
// Error: cannot call non-const formatting macro in constant functions
const {
    fmt::Arguments::new_v1( // Now the error is produced here.
        &["Hello, ", "!\n"],
        &[
            fmt::Argument::new_display(&world) // The error used to be produced here.
        ],
    )
}
```
2025-05-01 22:27:24 +02:00
Guillaume Gomez
5a25a7a020 Rollup merge of #140034 - RalfJung:simd_select_bitmask-padding, r=workingjubilee
simd_select_bitmask: the 'padding' bits in the mask are just ignored

Fixes https://github.com/rust-lang/rust/issues/137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here)  to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits.

Cc ````@Amanieu```` ````@workingjubilee````
2025-05-01 22:27:22 +02:00
Guillaume Gomez
b867d20279 Rollup merge of #139802 - Lee-Janggun:fix-allocate-hyperlink, r=workingjubilee
Fix some grammar errors and hyperlinks in doc for `trait Allocator`

I was reading the allocator docs and noticed some weird sentences and missing hyperlink, so I fixed them and made this small PR.

* "while until either" could also be changed to "for a while until either", but I just deleted "while".
* fixed sentence with incorrect "at" and "has/have".
* linked [*currently allocated*] similar to other methods. All other hyperlinks are fine.
2025-05-01 22:27:21 +02:00
Guillaume Gomez
931735a1b1 Rollup merge of #139780 - ongardie:iterator-take-by_ref-example, r=workingjubilee
docs: Add example to `Iterator::take` with `by_ref`

If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods.

After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
2025-05-01 22:27:20 +02:00
Guillaume Gomez
bd68c36ee0 Rollup merge of #139186 - TDecking:float, r=workingjubilee
Refactor `diy_float`

The refactor replaces bespoke algorithms with functions already inside the standard library, improving both codegen and readability.
2025-05-01 22:27:20 +02:00
Guillaume Gomez
c02964f446 Rollup merge of #138703 - pudongair:master, r=workingjubilee
chore: remove redundant words in comment

remove redundant words in comment
2025-05-01 22:27:19 +02:00
sayantn
7443d039a5 Update stdarch 2025-05-01 20:01:43 +05:30
Amanieu d'Antras
72b110ada3 Stabilize select_unpredictable
FCP completed in tracking issue #133962.
2025-05-01 13:49:28 +01:00
Mara Bos
36c6633b0f Clean up "const" situation in format_args!().
Rather than marking the Argument::new_display etc. functions as
non-const, this marks the Arguments::new_v1 functions as non-const.
2025-05-01 11:55:23 +02:00
Mara Bos
3e969d433d Move core::fmt::Arguments::new_v1* to rt.rs. 2025-05-01 11:53:24 +02:00
Natrix
b735dce5a6 docs: Specify that common sort functions sort in an ascending direction 2025-04-30 20:25:47 +02:00
Mathis B
e83a0a4bbe Stabilize #![feature(non_null_from_ref)] 2025-04-30 17:54:07 +02:00
Matthias Krüger
bc99a045cb Rollup merge of #139624 - m-ou-se:unconst-format-args, r=jhpratt
Don't allow flattened format_args in const.

Fixes https://github.com/rust-lang/rust/issues/139136

Fixes https://github.com/rust-lang/rust/issues/139621

We allow `format_args!("a")` in const, but don't allow any format_args with arguments in const, such as `format_args!("{}", arg)`.

However, we accidentally allow `format_args!("hello {}", "world")` in const, as it gets flattened to `format_args!("hello world")`.

This also applies to panic in const.

This wasn't supposed to happen. I added protection against this in the format args flattening code, ~~but I accidentally marked a function as const that shouldn't have been const~~ but this was removed in https://github.com/rust-lang/rust/pull/135139.

This is a breaking change. The crater found no breakage, however.

This breaks things like:

```rust
const _: () = if false { panic!("a {}", "a") };
```

and

```rust
const F: std::fmt::Arguments<'static> = format_args!("a {}", "a");
```
2025-04-30 17:27:57 +02:00
Matthias Krüger
aeec053e1b Rollup merge of #139192 - lolbinarycat:docs-wrapping_offset-provenance-139008, r=RalfJung
mention provenance in the pointer::wrapping_offset docs

fixes https://github.com/rust-lang/rust/issues/139008
2025-04-30 10:18:25 +02:00