3256 Commits

Author SHA1 Message Date
Trevor Gross
fd06f6d658
Rollup merge of #142238 - RalfJung:nonnull_provenance, r=workingjubilee
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-09 12:17:55 -05:00
Trevor Gross
ab87ed150b
Rollup merge of #141993 - tgross35:use-in-tree-builtins, r=bjorn3
Use the in-tree `compiler-builtins` for the sysroot

Many of `std`'s dependency have a dependency on the crates.io `compiler-builtins` when used with the feature `rustc-std-workspace-core`. Use a Cargo patch to select the in-tree version instead.

`compiler-builtins` is also added as a dependency of `rustc-std-workspace-core` so these crates can remove their crates.io dependency in the future.

Zulip discussion: [#t-compiler > Using in-tree compiler-builtins](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20in-tree.20compiler-builtins/with/522445336)

Once this merges, the following PRs will need to make it to a release for the relevant crates:

- https://github.com/rust-lang/getopts/pull/119 (can merge at any time)
- https://github.com/rust-lang/hashbrown/pull/625 (can merge at any time)
- https://github.com/rust-lang/stdarch/pull/1825
- https://github.com/rust-lang/rustc-demangle/pull/80
- https://github.com/rust-lang/cfg-if/pull/84
- https://github.com/unicode-rs/unicode-width/pull/77

The above should cover all tier 1 targets with no `std` features enabled. The remaining cover the rest:

- https://github.com/alexcrichton/dlmalloc-rs/pull/50 (wasm, xous, sgx)
- https://github.com/gimli-rs/gimli/pull/769
- https://github.com/r-efi/r-efi/pull/89 (efi)
- https://github.com/r-efi/r-efi-alloc/pull/9 (efi)
- https://github.com/fortanix/rust-sgx/pull/770 (sgx)
- https://github.com/hermit-os/hermit-rs/pull/718 (hermit)
- https://github.com/bytecodealliance/wasi-rs/pull/108 (wasi)
- https://github.com/gimli-rs/addr2line/pull/345
- https://github.com/oyvindln/adler2/pull/2
- https://github.com/BurntSushi/memchr/pull/180
- https://github.com/Frommi/miniz_oxide/pull/173
- https://github.com/gimli-rs/object/pull/777

try-job: x86_64-gnu
try-job: test-various
2025-06-09 12:17:53 -05:00
Ralf Jung
3164ca8bb4 stabilize nonnull_provenance 2025-06-09 12:36:24 +02:00
Trevor Gross
cc3e57147e Use the in-tree compiler-builtins
Many of `std`'s dependency have a dependency on the crates.io
`compiler-builtins` when used with the feature
`rustc-std-workspace-core`. Use a Cargo patch to select the in-tree
version instead.

`compiler-builtins` is also added as a dependency of
`rustc-std-workspace-core` so these crates can remove their crates.io
dependency in the future.
2025-06-08 02:36:58 +00:00
Tshepang Mbambo
0ffff4657a remove extraneous text
"Basic usage" implies there is an example that shows advanced usage
2025-06-06 06:39:51 +02:00
Matthias Krüger
98421b765f
Rollup merge of #141924 - rs-sac:extr-doc, r=jhpratt
Lightly tweak docs for BTree{Map,Set}::extract_if

- Move explanations into comments to match style
- Explain the second examples
- Make variable names match the data structure

Related rust-lang/rust#70530
2025-06-04 16:24:09 +02:00
Josh Stone
c87b072952 Remove more library bootstrap 2025-06-02 14:46:19 -07:00
Sidney Cammeresi
a20cf473e7 Lightly tweak docs for BTree{Map,Set}::extract_if
- Move explanations into comments to match style
- Explain the second examples
- Make variable names match the data structure
2025-06-02 10:10:00 -07:00
Matthias Krüger
04641b14a3
Rollup merge of #141805 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.160

Includes the following changes:

* Enable `__powitf2` on MSVC [1]
* Update `CmpResult` to use a pointer-sized return type [2]
* Better code reuse between `libm` and `compiler-builtins` [3], [4]
* Stop building C versions of `__netf2` [5] since we have our own implementation

[1]: https://github.com/rust-lang/compiler-builtins/pull/918
[2]: https://github.com/rust-lang/compiler-builtins/pull/920
[3]: https://github.com/rust-lang/compiler-builtins/pull/879
[4]: https://github.com/rust-lang/compiler-builtins/pull/925
[5]: https://github.com/rust-lang/compiler-builtins/pull/828
2025-05-31 18:51:50 +02:00
Trevor Gross
ca1c67ad76 Update compiler-builtins to 0.1.160
Includes the following changes:

* Enable `__powitf2` on MSVC [1]
* Update `CmpResult` to use a pointer-sized return type [2]
* Better code reuse between `libm` and `compiler-builtins` [3], [4]
* Stop building C versions of `__netf2` [5] since we have our own
  implementation

[1]: https://github.com/rust-lang/compiler-builtins/pull/918
[2]: https://github.com/rust-lang/compiler-builtins/pull/920
[3]: https://github.com/rust-lang/compiler-builtins/pull/879
[4]: https://github.com/rust-lang/compiler-builtins/pull/925
[5]: https://github.com/rust-lang/compiler-builtins/pull/828
2025-05-30 16:09:12 +00:00
Sidney Cammeresi
8656d9e619 Unit test for Range parameter of BTreeMap::extract_if 2025-05-27 08:31:56 -07:00
Sidney Cammeresi
38c37eb3cb Update docs for new Range parameter to BTreeMap::extract_if etc. 2025-05-27 08:31:56 -07:00
Sidney Cammeresi
1ae96fcd79 Update tests with Range parameter to BTreeMap::extract_if etc. 2025-05-27 08:31:56 -07:00
Sidney Cammeresi
51d247c2cf Add Range parameter to BTreeMap::extract_if and BTreeSet::extract_if
This change was requested in the btree_extract_if tracking issue:

https://github.com/rust-lang/rust/issues/70530#issuecomment-2486566328
2025-05-27 08:31:40 -07:00
Jacob Pratt
3338ff7dcf
Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-Simulacrum
Docs(lib): Fix `extract_if` docs

Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change.

`@rustbot` label T-libs A-collections A-docs
2025-05-25 04:00:56 +02:00
Matthias Krüger
a31a39833a
Rollup merge of #141370 - WaffleLapkin:hiiii, r=jhpratt
add doc alias `replace_first` for `str::replacen`

`replace_first` is a sensible name for a function, analogous to actually existing `<[_]>::split_first`, for example. (I just saw someone try to search for it)

I think it's reasonable to add such an alias for `replacen`, which replaces the first occurrence of passed a 1.
2025-05-22 07:19:04 +02:00
waffle
cff790c98e
add doc alias replace_first for str::replacen 2025-05-21 23:43:57 +02:00
Matthias Krüger
b5edec2811
Rollup merge of #141230 - xizheyin:issue-141217, r=tgross35
std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque`

Fixes #141217

r? libs
2025-05-21 22:14:58 +02:00
Matthias Krüger
d4b7915a59
Rollup merge of #140526 - Natr1x:sort-direction-documentation, r=dtolnay
docs: Specify that common sort functions sort in an ascending direction

From [forum discussion](https://users.rust-lang.org/t/is-there-a-way-to-sort-a-slice-in-specifically-ascending-or-descending-order/128998?u=natr1x) it seems like the sorting direction can be expected to always be ascending (in terms of `cmp::Ordering`).

If this is the case then it would be nice to have this stated in the documentation.
2025-05-21 22:14:57 +02:00
xizheyin
46a5c91591 std: fix doctest and explain for as_slices and as_mut_slices in VecDeque
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-21 22:13:23 +08:00
Matthias Krüger
c052d263d0
Rollup merge of #141289 - compiler-errors:more-self, r=jhpratt
use `Self` alias in self types rather than manually substituting it

Of the rougly 145 uses of `self: Ty` in the standard library, 5 of them don't use `Self` but instead choose to manually "substitute" the `impl`'s self type into the type.

This leads to weird behavior sometimes (https://github.com/rust-lang/rust/issues/140611#issuecomment-2883761300) -- **to be clear**, none of these usages actually trigger any bugs, but it's possible that they may break in the future (or at least lead to lints), so let's just "fix" them proactively.
2025-05-20 20:57:28 +02:00
Michael Goulet
7b5ea0e7f5 use Self alias in self types rather than manually substituting it 2025-05-20 16:03:04 +02:00
Paul Mabileau
b1d7480acb
Docs(lib/extract_if): Unify example description
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:54:21 +02:00
Paul Mabileau
014434e96f
Docs(lib/extract_if): Unify paragraph about elements mutation
Take the one from `BTreeMap` that seems the best-worded and most
precise among the available variations.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:45:56 +02:00
Paul Mabileau
9205ee27a8
Docs(lib/extract_if): Unify paragraph about closure actions
Also fixes `HashSet`'s that incorrectly designated itself as a `list`.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:36:08 +02:00
Paul Mabileau
35f8473637
Docs(lib/coll/btm): Split extract_if's first sentence from the following ones
This also seems like a small mistake: the first main sentence is put in
the same paragraph as the other two following ones while other
equivalents all have it split. Therefore, do the same here.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:29:37 +02:00
Paul Mabileau
d29d1a332b
Docs(lib/alloc/vec): Add the missing an to extract_if's first sentence
As inspired by the equivalent methods from other collection types.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17 02:09:06 +02: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
7a8fd9985d
Rollup merge of #140685 - viliml:patch-1, r=Mark-Simulacrum
Simplify `Vec::as_non_null` implementation and make it `const`

Tracking issue: #130364.
2025-05-15 22:28:50 +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
Pietro Albini
ce6e29679c
bump compiler_builtins 2025-05-13 11:30:36 +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
Guillaume Gomez
aca12a8216
Rollup merge of #140724 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.158

Includes the following changes:

* Require `target_has_atomic = "ptr"` for runtime feature detection [1]

[1]: https://github.com/rust-lang/compiler-builtins/pull/909
2025-05-07 10:50:50 +02:00
Jacob Pratt
5b165aab89
Rollup merge of #140668 - vkrivopalov:vecdeque-truncate-front, r=jhpratt
Implement `VecDeque::truncate_front()`

Tracking issue: #140667
2025-05-07 00:29:24 +00:00
Jacob Pratt
25631ff093
Rollup merge of #140483 - baumanj:patch-1, r=workingjubilee
Comment on `Rc` abort-guard strategy without naming unrelated fn

`wrapped_add` is used, not `checked_add`, so avoid mentioning specific fn calls that may vary slightly based on "whatever produces the best code" and focus on things that will remain constant into the future.
2025-05-07 00:29:22 +00:00
Trevor Gross
4de822c3d2 Update compiler-builtins to 0.1.158
Includes the following changes:

* Require `target_has_atomic = "ptr"` for runtime feature detection

[1]: https://github.com/rust-lang/compiler-builtins/pull/909
2025-05-06 23:40:50 +00:00
Jon Bauman
6a4af821b0
Update rc.rs docs
Update comment per review feedback
2025-05-06 13:19:42 -07:00
Stuart Cook
d5c09b4aa6
Rollup merge of #139773 - thaliaarchi:vec-into-iter-last, r=workingjubilee
Implement `Iterator::last` for `vec::IntoIter`

Avoid iterating everything when we have random access to the last element.
2025-05-06 16:28:39 +10:00
Stuart Cook
5ca0053c79
Rollup merge of #139764 - dtolnay:extractif, r=Amanieu
Consistent trait bounds for ExtractIf Debug impls

Closes #137654. Refer to that issue for a table of the **4** different impl signatures we previously had in the standard library for Debug impls of various ExtractIf iterator types.

The one we are standardizing on is the one so far only used by `alloc::collections::linked_list::ExtractIf`, which is _no_ `F: Debug` bound, _no_ `F: FnMut` bound, only `T: Debug` bound.

This PR applies the following signature changes:

```diff
/* alloc::collections::btree_map */

    pub struct ExtractIf<'a, K, V, F, A = Global>
    where
-       F: 'a + FnMut(&K, &mut V) -> bool,
        Allocator + Clone,

    impl Debug for ExtractIf<'a, K, V, F,
+       A,
    >
    where
        K: Debug,
        V: Debug,
-       F: FnMut(&K, &mut V) -> bool,
+       A: Allocator + Clone,
```

```diff
/* alloc::collections::btree_set */

    pub struct ExtractIf<'a, T, F, A = Global>
    where
-       T: 'a,
-       F: 'a + FnMut(&T) -> bool,
        Allocator + Clone,

    impl Debug for ExtractIf<'a, T, F, A>
    where
        T: Debug,
-       F: FnMut(&T) -> bool,
        A: Allocator + Clone,
```

```diff
/* alloc::collections::linked_list */

    impl Debug for ExtractIf<'a, T, F,
+       A,
    >
    where
        T: Debug,
+       A: Allocator,
```

```diff
/* alloc::vec */

    impl Debug for ExtractIf<'a, T, F, A>
    where
        T: Debug,
-       F: Debug,
        A: Allocator,
-       A: Debug,
```

```diff
/* std::collections::hash_map */

    pub struct ExtractIf<'a, K, V, F>
    where
-       F: FnMut(&K, &mut V) -> bool,

    impl Debug for ExtractIf<'a, K, V, F>
    where
+       K: Debug,
+       V: Debug,
-       F: FnMut(&K, &mut V) -> bool,
```

```diff
/* std::collections::hash_set */

    pub struct ExtractIf<'a, T, F>
    where
-       F: FnMut(&T) -> bool,

    impl Debug for ExtractIf<'a, T, F>
    where
+       T: Debug,
-       F: FnMut(&T) -> bool,
```

I have made the following changes to bring these types into better alignment with one another.

- Delete `F: Debug` bounds. These are especially problematic because Rust closures do not come with a Debug impl, rendering the impl useless.

- Delete `A: Debug` bounds. Allocator parameters are unstable for now, but in the future this would become an API commitment that we do not debug-print a representation of the allocator when printing an iterator.

- Delete `F: FnMut` bounds. Requires `hashbrown` PR: https://github.com/rust-lang/hashbrown/pull/616. **API commitment:** we commit to not doing RefCell voodoo inside ExtractIf to have some way for its Debug impl (which takes &amp;self) to call a FnMut closure, if this is even possible.

- Add `T: Debug` bounds (or `K`/`V`), even on Debug impls that do not currently make use of them, but might in the future. **Breaking change.** Must backport into Rust 1.87 (current beta) or do a de-stabilization PR in beta to delay those types by one release.

- Render using `debug_struct` + `finish_non_exhaustive`, instead of `debug_tuple`.

- Do not render the _entire_ underlying collection.

- Show a "peek" field indicating the current position of the iterator.
2025-05-06 16:28:38 +10:00
David Tolnay
c35914383a
Consistent trait bounds for ExtractIf Debug impls 2025-05-05 19:46:46 -07:00
Vilim Lendvaj
53459ffa8c Simplify Vec::as_non_null implementation and make it const 2025-05-05 21:56:33 +02:00
Vladimir Krivopalov
cdf4143eb8 Implement VecDeque::truncate_front()
Tracking issue: #140667

Signed-off-by: Vladimir Krivopalov <vladimir.krivopalov@gmail.com>
2025-05-05 11:13:26 -04:00
Trevor Gross
512dab0bee
Rollup merge of #140648 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.157

Includes the following changes:

* Use runtime feature detection for fma routines on x86 [1]

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

[1]: https://github.com/rust-lang/compiler-builtins/pull/896
2025-05-05 00:20:58 -04:00
Trevor Gross
c44e1d65f3
Rollup merge of #135734 - nk9:extract_if-doc-equivalent, r=tgross35
Correct `extract_if` sample equivalent.

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

Original PR: #133265

The sample code marked as equivalent in the doc comment isn't currently equivalent. Given the same predicate and range, if your vector were `[1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6]`, then all of the 3s would be removed. `i` is only incremented when an element is dropped, but `range.end` is unchanged, so the items shift down. I got very confused when reading the docs and trying to square this sample code with the explanation of how the function works.

Fortunately, the real `extract_if()` does not have this problem. I've added an `end` variable to align the behavior. I've also taken the opportunity to simplify the predicate, which now just matches odd numbers, and to pad out the vec of numbers to line up the zero-indexed range with the integers in the vec.

r? the8472
2025-05-05 00:20:57 -04:00
Trevor Gross
435fc7d685 Update compiler-builtins to 0.1.157
Includes the following changes:

* Use runtime feature detection for fma routines on x86 [1]

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

[1]: https://github.com/rust-lang/compiler-builtins/pull/896
2025-05-04 22:54:55 +00:00
Nick Kocharhook
52d806a7c0 extract_if's sample equivalent now really equivalent.
Simpler predicate.
Compare sample code output to that of the library function.
2025-05-04 23:38:54 +01:00
Paolo Barbolini
5cbb27ff90 Suggest retain_mut over retain as Vec::extract_if alternative 2025-05-03 16:39:47 +00:00
Thalia Archibald
cbdd7134ff Implement Iterator::last for vec::IntoIter 2025-05-02 20:08:28 -07:00
Natrix
b735dce5a6 docs: Specify that common sort functions sort in an ascending direction 2025-04-30 20:25:47 +02:00