about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2024-08-09Add an optimizer hint for the capacity that with_capacity_in returnsBen Kimock-1/+7
2024-08-09Hoist IS_ZST check out of RawVecInner::from_*_inBen Kimock-6/+15
2024-08-09Polymorphize RawVecBen Kimock-212/+369
2024-08-09Fix linkchecker issueLukas Bergdoll-1/+1
2024-08-07Rollup merge of #128261 - clarfonthey:iter-default, r=dtolnayMatthias Krüger-0/+70
impl `Default` for collection iterators that don't already have it There is a pretty strong precedent for implementing `Default` for collection iterators, and this does so for some where this implementation was missed. I don't think this needs a separate ACP (since this precedent already exists, and these feel like they were just missed), however, it *will* need an FCP since these implementations are instantly stable.
2024-08-07alloc: make `to_string_str!` a bit less complexMichael Howell-22/+35
2024-08-07Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieuMatthias Krüger-2/+22
PinCoerceUnsized trait into core cc ``@Darksonn`` ``@wedsonaf`` ``@ojeda`` This is a PR to introduce a `PinCoerceUnsized` trait in order to make trait impls generated by the proc-macro `#[derive(SmartPointer)]`, proposed by [RFC](https://github.com/rust-lang/rfcs/blob/e17e19ac7ad1c8ccad55d4babfaee1aa107d1da5/text/3621-derive-smart-pointer.md#pincoerceunsized-1), sound. There you may find explanation, justification and discussion about the alternatives. Note that we do not seek stabilization of this `PinCoerceUnsized` trait in the near future. The stabilisation of this trait does not block the eventual stabilization process of the `#[derive(SmartPointer)]` macro. Ideally, use of `DerefPure` is more preferrable except this will actually constitute a breaking change. `PinCoerceUnsized` emerges as a solution to the said soundness hole while avoiding the breaking change. More details on the `DerefPure` option have been described in this [section](https://github.com/rust-lang/rfcs/blob/e17e19ac7ad1c8ccad55d4babfaee1aa107d1da5/text/3621-derive-smart-pointer.md#derefpure) of the RFC linked above. Earlier discussion can be found in this [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Pin.20and.20soundness.20of.20unsizing.20coercions) and [rust-for-linux thread](https://rust-lang.zulipchat.com/#narrow/stream/425075-rust-for-linux/topic/.23.5Bderive.28SmartPointer.29.5D.20and.20pin.20unsoundness.20rfc.233621). try-job: dist-various-2
2024-08-06alloc: add ToString specialization for `&&str`Michael Howell-8/+35
Fixes #128690
2024-08-05Rollup merge of #128309 - kmicklas:btreeset-cursor, r=AmanieuMatthias Krüger-1/+582
Implement cursors for `BTreeSet` Tracking issue: https://github.com/rust-lang/rust/issues/107540 This is a straightforward wrapping of the map API, except that map's `CursorMut` does not make sense, because there is no value to mutate. Hence, map's `CursorMutKey` is wrapped here as just `CursorMut`, since it's unambiguous for sets and we don't normally speak of "keys". On the other hand, I can see some potential for confusion with `CursorMut` meaning different things in each module. I'm happy to take suggestions to improve that. r? ````@Amanieu````
2024-08-03Apply review comments to PartialOrd sectionLukas Bergdoll-7/+7
2024-08-03Rollup merge of #127586 - zachs18:more-must-use, r=cuviperMatthias Krüger-1/+7
Add `#[must_use]` to some `into_raw*` functions. cc #121287 r? ``@cuviper`` Adds `#[must_use = "losing the pointer will leak memory"]`[^1] to `Box::into_raw(_with_allocator)`, `Vec::into_raw_parts(_with_alloc)`, `String::into_raw_parts`[^2], and `rc::{Rc, Weak}::into_raw_with_allocator` (Rc's normal `into_raw` and all of `Arc`'s `into_raw*`s are already `must_use`). Adds `#[must_use = "losing the raw <resource name may leak resources"]` to `IntoRawFd::into_raw_fd`, `IntoRawSocket::into_raw_socket`, and `IntoRawHandle::into_raw_handle`. [^1]: "*will* leak memory" may be too-strong wording (since `Box`/`Vec`/`String`/`rc::Weak` might not have a backing allocation), but I left it as-is for simplicity and consistency. [^2]: `String::into_raw_parts`'s `must_use` message is changed from the previous (possibly misleading) "`self` will be dropped if the result is not used".
2024-08-01Fix mutability in doc tests for `BTreeSet` cursorsKen Micklas-10/+10
2024-08-01Introduce `Cursor`/`CursorMut`/`CursorMutKey` thrichotomy for `BTreeSet` ↵Ken Micklas-16/+194
like map API
2024-08-01Fix some uses of "map" instead of "set" in `BTreeSet` cursor API docsKen Micklas-4/+4
2024-08-01Share `UnorderedKeyError` with `BTReeMap` for set APIKen Micklas-29/+7
2024-07-31Apply review commentsLukas Bergdoll-41/+47
- Use if the implementation of [`Ord`] for `T` language - Link to total order wiki page - Rework total order help and examples - Improve language to be more precise and less prone to misunderstandings. - Fix usage of `sort_unstable_by` in `sort_by` example - Fix missing author mention - Use more consistent example input for sort - Use more idiomatic assert_eq! in examples - Use more natural "comparison function" language instead of "comparator function"
2024-07-31PinCoerceUnsized trait into coreXiangfei Ding-2/+22
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-1/+0
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-30Auto merge of #128234 - jcsp:retain-empty-case, r=tgross35bors-0/+6
Optimize empty case in Vec::retain While profiling some code that happens to call Vec::retain() in a tight loop, I noticed more runtime than expected in retain, even in a bench case where the vector was always empty. When I wrapped my call to retain in `if !myvec.is_empty()` I saw faster execution compared with doing retain on an empty vector. On closer inspection, Vec::retain is doing set_len(0) on itself even when the vector is empty, and then resetting the length again in BackshiftOnDrop::drop. Unscientific screengrab of a flamegraph illustrating how we end up spending time in set_len and drop: ![image](https://github.com/user-attachments/assets/ebc72ace-84a0-4432-9b6f-1b3c96d353ba)
2024-07-29Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomezMatthias Krüger-0/+1
Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro` I am not sure if the lint is supposed to be "ready enough" (since it is `allow` by default), but it does catch a couple issues in `core` (`alloc`, `std`, `test` and `proc_macro` are already clean), so I propose making it `warn` in all the crates rendered in the website. Cc: `@GuillaumeGomez`
2024-07-29Optimize empty case in Vec::retainJohn Spray-0/+6
2024-07-29Rollup merge of #128310 - kmicklas:btree-map-peek-next-docs, r=tgross35Matthias Krüger-3/+3
Add missing periods on `BTreeMap` cursor `peek_next` docs Tracking issue: https://github.com/rust-lang/rust/issues/107540
2024-07-29Warn on `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`Miguel Ojeda-0/+1
They are all clean now, so enable the lint to keep them clean going forward. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29Reformat `use` declarations.Nicholas Nethercote-190/+163
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28step cfg(bootstrap)Mark Rousskov-1/+0
2024-07-28Rollup merge of #128228 - slanterns:const_waker, r=dtolnay,oli-obkGuillaume Gomez-1/+0
Stabilize `const_waker` Closes: https://github.com/rust-lang/rust/issues/102012. For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under https://github.com/rust-lang/rust/issues/102012 from the beginning IMO.)~~ reused their own feature gates as suggested by ``@tgross35.`` ``@rustbot`` label: +T-libs-api r? libs-api
2024-07-28Rollup merge of #127765 - bitfield:fix_stdlib_doc_nits, r=dtolnayGuillaume Gomez-54/+60
Fix doc nits Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo"), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits.
2024-07-28stabilize const_wakerSlanterns-1/+0
2024-07-28Add missing periods on `BTreeMap` cursor `peek_next` docsKen Micklas-3/+3
2024-07-28Implement cursors for `BTreeSet`Ken Micklas-1/+426
2024-07-28Rollup merge of #128279 - slanterns:is_sorted, r=dtolnayMatthias Krüger-1/+0
Stabilize `is_sorted` Closes: https://github.com/rust-lang/rust/issues/53485. ~~Question: does~~ https://github.com/rust-lang/rust/blob/8fe0c753f23e7050b87a444b6622caf4d2272d5d/compiler/rustc_lint_defs/src/builtin.rs#L1986-L1994 ~~need a new example?~~ edit: It causes a test failure and needs to be changed anyway. ``@rustbot`` label: +T-libs-api r? libs-api
2024-07-28stabilize `is_sorted`Slanterns-1/+0
2024-07-27Rollup merge of #125897 - RalfJung:from-ref, r=AmanieuTrevor Gross-2/+2
from_ref, from_mut: clarify documentation This was brought up [here](https://github.com/rust-lang/rust/issues/56604#issuecomment-2143193486). The domain of quantification is generally always constrained by the type in the type signature, and I am not sure it's always worth spelling that out explicitly as that makes things exceedingly verbose. But since this was explicitly brought up, let's clarify.
2024-07-27Improve panic sections for sort*, sort_unstable* and select_nth_unstable*Lukas Bergdoll-3/+13
- Move panic information into # Panics section - Fix mentions of T: Ord that should be compare - Add missing information
2024-07-27Okay, I guess I have to give these a different feature nameltdk-5/+5
2024-07-27impl Default for collection iterators that don't already have itltdk-0/+70
2024-07-26Fix doc nitsJohn Arundel-54/+60
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-24Rollup merge of #128120 - compiler-errors:async-fn-name, r=oli-obkMatthias Krüger-0/+1
Gate `AsyncFn*` under `async_closure` feature T-lang has not come to a consensus on the naming of async closure callable bounds, and as part of allowing the async closures RFC merge, we agreed to place `AsyncFn` under the same gate as `async Fn` so that these syntaxes can be evaluated in parallel. See https://github.com/rust-lang/rfcs/pull/3668#issuecomment-2246435537 r? oli-obk
2024-07-24Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=AmanieuMatthias Krüger-45/+38
Replace some `mem::forget`'s with `ManuallyDrop` > but I would like to see a larger effort to replace all uses of `mem::forget`. _Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_ So, r? `@saethlin` Sorry, I have finished writing all of this before I got your response.
2024-07-24Rollup merge of #127481 - a1phyr:pattern_gat, r=AmanieuMatthias Krüger-14/+17
Remove generic lifetime parameter of trait `Pattern` Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway. cc #27721
2024-07-24Rollup merge of #125962 - Coekjan:const-binary-heap, r=AmanieuMatthias Krüger-1/+1
Update tracking issue for `const_binary_heap_new_in` This PR updates the tracking issue of `const_binary_heap_new_in` feature: - Old issue: #112353 - New issue: #125961
2024-07-23Gate AsyncFn* under async_closure featureMichael Goulet-0/+1
2024-07-22Rollup merge of #127415 - AljoschaMeyer:master, r=dtolnay许杰友 Jieyou Xu (Joe)-2/+81
Add missing try_new_uninit_slice_in and try_new_zeroed_slice_in The methods for fallible slice allocation in a given allocator were missing from `Box`, which was an oversight according to https://github.com/rust-lang/wg-allocators/issues/130 This PR adds them as `try_new_uninit_slice_in` and `try_new_zeroed_slice_in`. I simply copy-pasted the implementations of `try_new_uninit_slice` and `try_new_zeroed_slice` and adusted doc comment, typings, and the allocator it uses internally. Also adds missing punctuation to the doc comments of `try_new_uninit_slice` and `try_new_zeroed_slice`. Related issue is https://github.com/rust-lang/rust/issues/32838 (Allocator traits and std::heap) *I think*. Also relevant is https://github.com/rust-lang/rust/issues/63291, but I did not add the corresponding `#[unstable]` proc macro, since `try_new_uninit_slice` and `try_new_zeroed_slice` are also not annotated with it.
2024-07-22Use given allocator instad of GlobalAljoscha Meyer-2/+2
2024-07-17Adjust some comments on individual `use` declarations.Nicholas Nethercote-2/+1
When we do the big `use` reformatting there are a tiny number of cases where rustfmt moves a comment from one `use` item to another in an undesirable way. This commit pre-emptively rearranges things to prevent this from happening.
2024-07-15lib: replace some `mem::forget`'s with `ManuallyDrop`Pavel Grigorenko-45/+38
2024-07-15Remove generic lifetime parameter of trait `Pattern`Benoît du Garreau-14/+17
Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway.
2024-07-13Rollup merge of #127446 - zachs18:miri-stdlib-leaks-core-alloc, ↵Jubilee-1/+33
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-12Rollup merge of #124980 - zachs18:rc-allocator, r=AmanieuMatthias Krüger-20/+36
Generalize `fn allocator` for Rc/Arc. Split out from #119761 - For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees. - For `Weak`s, new methods are added. `````@rustbot````` label +A-allocators
2024-07-10Clarify/add `must_use` messages for more `into_raw*` functions of `alloc` types.Zachary S-1/+7