rust/library/alloc/src
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
..
boxed library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
collections Remove some unnecessary clones. 2025-04-24 11:12:34 +10:00
ffi Rollup merge of #137714 - DiuDiu777:doc-fix, r=tgross35 2025-04-27 11:54:57 +02:00
raw_vec Swap usize -> ptr transmute for strict_pov API 2025-03-26 21:41:11 +00:00
vec Rollup merge of #135734 - nk9:extract_if-doc-equivalent, r=tgross35 2025-05-05 00:20:57 -04:00
alloc.rs update cfgs 2025-04-09 12:29:59 +01:00
borrow.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
boxed.rs replace version placeholder 2025-04-09 12:29:59 +01:00
bstr.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
fmt.rs Fix typo in documentation 2025-04-12 22:26:38 +08:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
macros.rs Streamline the format macro. 2025-04-28 06:56:13 +10:00
rc.rs fix copy typo 2025-03-10 16:46:18 +08:00
slice.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
str.rs Rollup merge of #137714 - DiuDiu777:doc-fix, r=tgross35 2025-04-27 11:54:57 +02:00
string.rs Add #[rustc_no_implicit_autorefs] and apply it to std methods 2025-04-20 11:36:22 +02:00
sync.rs Auto merge of #136316 - GrigorenkoPV:generic_atomic, r=Mark-Simulacrum 2025-04-28 05:12:59 +00:00
task.rs Stabilize noop_waker 2024-12-05 14:14:17 -08:00