Commit Graph

2968 Commits

Author SHA1 Message Date
Amogh Shivaram
c1d32d8533 fix wording in assert 2025-06-07 08:18:44 -05:00
Amogh Shivaram
343db27aa6 cfg for no no_global_oom_handling 2025-06-07 01:14:24 -05:00
Amogh Shivaram
e4e77737f9 put feature attribute in example 2025-06-06 23:06:23 -05:00
Amogh Shivaram
230b55dcf8 Add into_chunks 2025-06-06 22:14:30 -05:00
Jeremy Smart
cc80429021 fix tests 2025-06-06 19:22:15 -04: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
Jeremy Smart
188c40126d add Vec::peek_mut 2025-06-04 18:15:12 -04: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
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
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
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
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
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
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
bors
427288b3ce Auto merge of #140188 - nnethercote:streamline-format-macro, r=cuviper
Streamline the `format` macro.

Removing the unnecessary local variable speeds up compilation a little.

r? `@cuviper`
2025-04-30 04:04:21 +00:00
Jon Bauman
dd20225681 Update rc.rs docs
`wrapped_add` is used, not `checked_add`
2025-04-29 11:24:31 -07:00
DaniPopes
f07cc409d3 Rename sub_ptr to offset_from_unsigned in docs 2025-04-28 13:58:27 +02:00
bors
a932eb36f8 Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross
Implement a lint for implicit autoref of raw pointer dereference - take 2

*[t-lang nomination comment](https://github.com/rust-lang/rust/pull/123239#issuecomment-2727551097)*

This PR aims at implementing a lint for implicit autoref of raw pointer dereference, it is based on #103735 with suggestion and improvements from https://github.com/rust-lang/rust/pull/103735#issuecomment-1370420305.

The goal is to catch cases like this, where the user probably doesn't realise it just created a reference.

```rust
pub struct Test {
    data: [u8],
}

pub fn test_len(t: *const Test) -> usize {
    unsafe { (*t).data.len() }  // this calls <[T]>::len(&self)
}
```

Since #103735 already went 2 times through T-lang, where they T-lang ended-up asking for a more restricted version (which is what this PR does), I would prefer this PR to be reviewed first before re-nominating it for T-lang.

----

Compared to the PR it is as based on, this PR adds 3 restrictions on the outer most expression, which must either be:
   1. A deref followed by any non-deref place projection (that intermediate deref will typically be auto-inserted)
   2. A method call annotated with `#[rustc_no_implicit_refs]`.
   3. A deref followed by a `addr_of!` or `addr_of_mut!`. See bottom of post for details.

There are several points that are not 100% clear to me when implementing the modifications:
 - ~~"4. Any number of automatically inserted deref/derefmut calls." I as never able to trigger this. Am I missing something?~~ Fixed
 - Are "index" and "field" enough?

----

cc `@JakobDegen` `@WaffleLapkin`
r? `@RalfJung`

try-job: dist-various-1
try-job: dist-various-2
2025-04-28 08:25:23 +00:00
bors
0134651fb8 Auto merge of #136316 - GrigorenkoPV:generic_atomic, r=Mark-Simulacrum
Create `Atomic<T>` type alias (rebase)

Rebase of #130543.

Additional changes:
- Switch from `allow` to `expect` for `private_bounds` on `AtomicPrimitive`
- Unhide `AtomicPrimitive::AtomicInner` from docs, because rustdoc shows the definition `pub type Atomic<T> = <T as AtomicPrimitive>::AtomicInner;` and generated links for it.
  - `NonZero` did not have this issue, because they kept the new alias private before the direction was changed.
- Use `Atomic<_>` in more places, including inside `Once`'s `Futex`. This is possible thanks to https://github.com/rust-lang/rust-clippy/pull/14125

The rest will either get moved back to #130543 or #130543 will be closed in favor of this instead.

---

* ACP: https://github.com/rust-lang/libs-team/issues/443#event-14293381061
* Tracking issue: #130539
2025-04-28 05:12:59 +00:00