rust/library/alloc/src
Jubilee 285d45d299
Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, r=Mark-Simulacrum
Remove memory leaks in doctests in `core`, `alloc`, and `std`

cc `@RalfJung`  https://github.com/rust-lang/rust/issues/126067 https://github.com/rust-lang/miri/issues/3670

Should be no actual *documentation* changes[^1], all added/modified lines in the doctests are hidden with `#`,

This PR splits the existing memory leaks in doctests in `core`, `alloc`, and `std` into two general categories:

1. "Non-focused" memory leaks that are incidental to the thing being documented, and/or are easy to remove, i.e. they are only there because preventing the leak would make the doctest less clear and/or concise.
    - These doctests simply have a comment like `# // Prevent leaks for Miri.` above the added line that removes the memory leak.
    - [^2]Some of these would perhaps be better as part of the public documentation part of the doctest, to clarify that a memory leak can happen if it is not otherwise mentioned explicitly in the documentation  (specifically the ones in `(A)Rc::increment_strong_count(_in)`).
2. "Focused" memory leaks that are intentional and documented, and/or are possibly fragile to remove.
    - These doctests have a `# // FIXME` comment above the line that removes the memory leak, with a note that once `-Zmiri-disable-leak-check` can be applied at test granularity, these tests should be "un-unleakified" and have `-Zmiri-disable-leak-check` enabled.
    - Some of these are possibly fragile (e.g. unleaking the result of `Vec::leak`) and thus should definitely not be made part of the documentation.

This should be all of the leaks currently in `core` and `alloc`. I only found one leak in `std`, and it was in the first category (excluding the modules `@RalfJung` mentioned in https://github.com/rust-lang/rust/issues/126067 , and reducing the number of iterations of [one test](https://github.com/rust-lang/rust/blob/master/library/std/src/sync/once_lock.rs#L49-L94) from 1000 to 10)

[^1]: assuming [^2] is not added
[^2]: backlink
2024-07-13 20:18:23 -07:00
..
alloc run alloc benchmarks in Miri and fix UB 2022-11-07 10:34:04 +01:00
boxed Convert some module-level // and /// comments to //!. 2024-06-20 09:23:18 +10:00
collections Rollup merge of #127355 - aceArt-GmbH:126475, r=oli-obk 2024-07-08 16:28:15 +02:00
ffi replace version placeholder 2024-06-11 16:52:02 +02:00
raw_vec try_with_capacity for RawVec 2024-03-01 18:20:48 +00:00
rc Generalize {Rc,Arc}::make_mut() to unsized types. 2024-06-22 08:08:00 -07:00
slice do not run test where it cannot run 2024-07-10 01:00:55 +02:00
sync Detect unused structs which derived Default 2024-06-25 23:29:44 +08:00
testing Share testing utilities with non-btree test cases 2022-05-02 10:07:50 +02:00
vec Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, r=Mark-Simulacrum 2024-07-13 20:18:23 -07:00
alloc.rs Replace WriteCloneIntoRaw with CloneToUninit. 2024-06-22 08:08:00 -07:00
borrow.rs Impl DerefPure for more std types 2024-04-05 00:02:42 +02:00
boxed.rs Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, r=Mark-Simulacrum 2024-07-13 20:18:23 -07:00
fmt.rs Mark format! with must_use hint 2024-07-06 14:24:20 +02: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 Rollup merge of #127355 - aceArt-GmbH:126475, r=oli-obk 2024-07-08 16:28:15 +02:00
macros.rs Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
raw_vec.rs Avoid MIR bloat in inlining 2024-07-01 05:17:13 -07:00
rc.rs Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, r=Mark-Simulacrum 2024-07-13 20:18:23 -07:00
slice.rs Fix wrong big O star bracing in the doc comments 2024-06-20 18:07:04 +02:00
str.rs Simplify str::clone_into 2024-06-25 22:34:41 +02:00
string.rs Mitigate focused memory leaks in alloc doctests for Miri. 2024-07-06 22:35:19 -05:00
sync.rs Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, r=Mark-Simulacrum 2024-07-13 20:18:23 -07:00
task.rs lib: fix some unnecessary_cast clippy lint 2024-03-25 23:19:40 +03:00
tests.rs remove redundant imports 2023-12-10 10:56:22 +08:00