about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2023-11-28Address unused tuple struct fields in the standard libraryJake Goulding-0/+1
2023-11-28Auto merge of #110353 - the8472:in-place-flatten-chunks, r=cuviperbors-29/+128
Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunks This enables the following cases to collect in-place: ```rust let v = vec![[0u8; 4]; 1024] let v: Vec<_> = v.into_iter().flatten().collect(); let v: Vec<Option<NonZeroUsize>> = vec![NonZeroUsize::new(0); 1024]; let v: Vec<_> = v.into_iter().flatten().collect(); let v = vec![u8; 4096]; let v: Vec<_> = v.into_iter().array_chunks::<4>().collect(); ``` Especially the nicheful-option-flattening should be useful in real code.
2023-11-28Add proper cfgsr0cky-0/+11
2023-11-25Rollup merge of #117968 - Urgau:stabilize-ptr-addr-eq, r=dtolnayMichael Goulet-1/+0
Stabilize `ptr::addr_eq` This PR stabilize the `ptr_addr_eq` library feature, representing: ```rust // core::ptr pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool; ``` FCP has already started [on the tracking issue](https://github.com/rust-lang/rust/issues/116324#issuecomment-1813008697) and is waiting on the final period comment. Note: stabilizing this feature is somewhat of requirement for a new T-lang lint, cf. https://github.com/rust-lang/rust/pull/117758#issuecomment-1813183686.
2023-11-23Add UnorderedKeyErrorAmanieu d'Antras-31/+43
2023-11-23Update library/alloc/src/collections/btree/map.rsAmanieu d'Antras-1/+1
Co-authored-by: Joe ST <joe@fbstj.net>
2023-11-23Rewrite the BTreeMap cursor API using gapsAmanieu d'Antras-374/+519
Tracking issue: #107540 Currently, a `Cursor` points to a single element in the tree, and allows moving to the next or previous element while mutating the tree. However this was found to be confusing and hard to use. This PR completely refactors cursors to instead point to a gap between two elements in the tree. This eliminates the need for a "ghost" element that exists after the last element and before the first one. Additionally, `upper_bound` and `lower_bound` now have a much clearer meaning. The ability to mutate keys is also factored out into a separate `CursorMutKey` type which is unsafe to create. This makes the API easier to use since it avoids duplicated versions of each method with and without key mutation. API summary: ```rust impl<K, V> BTreeMap<K, V> { fn lower_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V> where K: Borrow<Q> + Ord, Q: Ord; fn lower_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V> where K: Borrow<Q> + Ord, Q: Ord; fn upper_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V> where K: Borrow<Q> + Ord, Q: Ord; fn upper_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V> where K: Borrow<Q> + Ord, Q: Ord; } struct Cursor<'a, K: 'a, V: 'a>; impl<'a, K, V> Cursor<'a, K, V> { fn next(&mut self) -> Option<(&'a K, &'a V)>; fn prev(&mut self) -> Option<(&'a K, &'a V)>; fn peek_next(&self) -> Option<(&'a K, &'a V)>; fn peek_prev(&self) -> Option<(&'a K, &'a V)>; } struct CursorMut<'a, K: 'a, V: 'a>; impl<'a, K, V> CursorMut<'a, K, V> { fn next(&mut self) -> Option<(&K, &mut V)>; fn prev(&mut self) -> Option<(&K, &mut V)>; fn peek_next(&mut self) -> Option<(&K, &mut V)>; fn peek_prev(&mut self) -> Option<(&K, &mut V)>; unsafe fn insert_after_unchecked(&mut self, key: K, value: V); unsafe fn insert_before_unchecked(&mut self, key: K, value: V); fn insert_after(&mut self, key: K, value: V); fn insert_before(&mut self, key: K, value: V); fn remove_next(&mut self) -> Option<(K, V)>; fn remove_prev(&mut self) -> Option<(K, V)>; fn as_cursor(&self) -> Cursor<'_, K, V>; unsafe fn with_mutable_key(self) -> CursorMutKey<'a, K, V, A>; } struct CursorMutKey<'a, K: 'a, V: 'a>; impl<'a, K, V> CursorMut<'a, K, V> { fn next(&mut self) -> Option<(&mut K, &mut V)>; fn prev(&mut self) -> Option<(&mut K, &mut V)>; fn peek_next(&mut self) -> Option<(&mut K, &mut V)>; fn peek_prev(&mut self) -> Option<(&mut K, &mut V)>; unsafe fn insert_after_unchecked(&mut self, key: K, value: V); unsafe fn insert_before_unchecked(&mut self, key: K, value: V); fn insert_after(&mut self, key: K, value: V); fn insert_before(&mut self, key: K, value: V); fn remove_next(&mut self) -> Option<(K, V)>; fn remove_prev(&mut self) -> Option<(K, V)>; fn as_cursor(&self) -> Cursor<'_, K, V>; unsafe fn with_mutable_key(self) -> CursorMutKey<'a, K, V, A>; } ```
2023-11-20docs(GH-118094): make docs a bit more explicitPetr Portnov-3/+3
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20chore(GH-118094): explicitly mark `_elem` as unusedPetr Portnov-1/+1
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-20feat: specialize `SpecFromElem` for `()`Petr Portnov-4/+19
While a better approach would be to implement it for all ZSTs which are `Copy` and have trivial `Clone`, the last property cannot be detected for now. Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2023-11-16Stabilize ptr_addr_eq library featureUrgau-1/+0
2023-11-15Re-format code with new rustfmtMark Rousskov-3/+1
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-11Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnaybors-2/+2
Add `std::hash::{DefaultHasher, RandomState}` exports (needs FCP) This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`. <details><summary>The below no longer applies, but is kept for clarity.</summary> This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API. I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier. I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred. </details>
2023-11-10Closure-consuming helper functions for `fmt::Debug` helpersJohn Millikin-0/+2
2023-11-09Remove trailing whitespaceMatt Harding-2/+2
2023-11-09Add note on how 0 flag overrides fill characterMatt Harding-0/+1
2023-11-08Add link to Formatting traits from alternate formsMatt Harding-0/+4
2023-11-07Stabilize `slice_group_by`Niklas Fiekas-3/+2
Renamed "group by" to "chunk by" a per #80552. Newly stable items: * `core::slice::ChunkBy` * `core::slice::ChunkByMut` * `[T]::chunk` * `[T]::chunk_by` Closes #80552.
2023-11-05Auto merge of #116218 - tgross35:const-maybe-uninit-zeroed, r=dtolnaybors-1/+0
Stabilize `const_maybe_uninit_zeroed` and `const_mem_zeroed` Make `MaybeUninit::zeroed` and `mem::zeroed` const stable. Newly stable API: ```rust // core::mem pub const unsafe fn zeroed<T>() ->; impl<T> MaybeUninit<T> { pub const fn zeroed() -> MaybeUninit<T>; } ``` This relies on features based around `const_mut_refs`. Per `@RalfJung,` this should be OK since we do not leak any `&mut` to the user. For this to be possible, intrinsics `assert_zero_valid` and `assert_mem_uninitialized_valid` were made const stable. Tracking issue: #91850 Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const_mut_refs.60.20dependents r? libs-api `@rustbot` label -T-libs +T-libs-api +A-const-eval cc `@RalfJung` `@oli-obk` `@rust-lang/wg-const-eval`
2023-11-05Auto merge of #117503 - kornelski:hint-try-reserved, r=workingjubileebors-4/+14
Hint optimizer about try-reserved capacity This is #116568, but limited only to the less-common `try_reserve` functions to reduce bloat in debug binaries from debug info, while still addressing the main use-case #116570
2023-11-04Stabilize `const_maybe_uninit_zeroed`Trevor Gross-1/+0
Make `MaybeUninit::zeroed` const stable. Newly stable API: // core::mem impl<T> MaybeUninit<T> { pub const fn zeroed() -> MaybeUninit<T>; } Use of `const_mut_refs` should be acceptable since we do not leak the mutability. Tracking issue: #91850
2023-11-04docs: clarify explicitly freeing heap allocated memoryalpharush-3/+11
2023-11-02Add insta-stable std::hash::{DefaultHasher, RandomState} exportsltdk-2/+2
2023-11-02Hint optimizer about reserved capacityKornel-4/+14
2023-10-31delegate box error provideBugen Zhao-0/+4
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
2023-10-30Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubileebors-6/+16
Increase the reach of panic_immediate_abort I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-6/+16
2023-10-28mark constructor of `BinaryHeap` as const fncoekjan-2/+4
2023-10-25Stabilize `[const_]pointer_byte_offsets`Maybe Waffle-1/+0
2023-10-21Update boxed.rsGimbles-1/+1
2023-10-20s/generator/coroutine/Oli Scherer-3/+3
2023-10-20s/Generator/Coroutine/Oli Scherer-5/+5
2023-10-19Stablize arc_unwrap_or_cloneMuhammad Hamza-4/+2
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+1
2023-10-16Add invariant to Vec::pop that len < cap if pop successfulArthur Carcano-0/+1
Fixes: https://github.com/rust-lang/rust/issues/114334
2023-10-14Auto merge of #116407 - Mark-Simulacrum:bootstrap-bump, r=onur-ozkanbors-10/+10
Bump bootstrap compiler to just-released beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2023-10-11Auto merge of #115948 - notriddle:notriddle/logo-lockup, r=fmeasebors-0/+2
rustdoc: show crate name beside smaller logo *Blocked on https://github.com/rust-lang/cargo/pull/12800* ## Summary In this PR, the crate name and version are always shown in the sidebar, even in subpages, and the lateral navigation is always shown in the sidebar, even in modules. Clicking the crate name does the same thing clicking the logo always did: take you to the crate root (the crate's home page, at least within Rustdoc). The Rust logo is also no longer shown by default for non-Rust docs. ### Screenshots <details><summary>Before</summary> | | Macro | Module | |--|-------|--------| | In crate | ![image](https://github.com/rust-lang/rust/assets/1593513/d5db0a46-2bb6-44a2-a3aa-2d915ecb8595) |![image](https://github.com/rust-lang/rust/assets/1593513/61f8c1ee-c298-4e2c-b791-18ecb79ab83b) | In module[^1] | ![image](https://github.com/rust-lang/rust/assets/1593513/73abca59-0b69-4650-a1e2-7278ca34795c) | ![image](https://github.com/rust-lang/rust/assets/1593513/0baf02c2-2ec7-4674-80e5-a6a74a973376) [^1]: This PR also includes a bug fix for derive macros not showing up in the lateral navigation part of the sidebar </details> #### Whole sidebar screenshots | | Macro | Module | |--|-------|--------| | In crate | ![image](https://github.com/rust-lang/rust/assets/1593513/75d1bd07-41f7-4f11-ba24-fd5476e0586a) | ![image](https://github.com/rust-lang/rust/assets/1593513/52960259-2b65-4131-b380-01826f0a0eb7) | In module | ![image](https://github.com/rust-lang/rust/assets/1593513/06e57928-8cb0-41bd-b152-be16cc53e5ec) | ![image](https://github.com/rust-lang/rust/assets/1593513/37291c69-2a07-4467-a382-d9b029084a47) #### Different logo configurations | | Short crate name | Long crate name | |---------|------------------|-----------------| | Root | ![short-root] | ![long-root] | Subpage | ![short-subpage] | ![long-subpage] [short-root]: https://github.com/rust-lang/rust/assets/1593513/9e2b4fa8-f581-4106-b562-1e0372c13f79 [short-subpage]: https://github.com/rust-lang/rust/assets/1593513/8331cdb8-fa13-4671-a1e2-dcc1cdca7451 [long-root]: https://github.com/rust-lang/rust/assets/1593513/7d377fec-0f1d-4343-9f82-0e35a8f58056 [long-subpage]: https://github.com/rust-lang/rust/assets/1593513/3b3094a4-63c9-477c-8c15-b6075837df30 ##### Without a logo ![image](https://github.com/rust-lang/rust/assets/1593513/66672b79-6c59-4be8-a527-25ef6f0b04ab) ### Preview pages https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket/index.html https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket_sync_db_pools/index.html https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust-compiler/index.html https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust/std/index.html https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/tokio/index.html ## Motivation This improves visual information density (the construct with the logo and crate name is *shorter* than the logo on its own, because it's not square) and navigation clarity (we can now see what clicking the Rust logo does, specifically). Compare this with the layout at [Phoenix's Hexdocs] (which is what this proposal is closely based on), the old proposal on [Internals Discourse] (which always says "Rust standard library" in the sidebar, but doesn't do the side-by-side layout). [Phoenix's Hexdocs]: https://hexdocs.pm/phoenix/1.7.7/overview.html [Internals Discourse]: https://internals.rust-lang.org/t/poc-of-a-new-design-for-the-generated-rustdoc/11018 ## Guide-level explanation This PR cleans up some of the sidebar navigation. It makes the logo in the desktop sidebar a bit smaller, and puts the crate name and version next to it (either beside it, or below it, depending on if there's space), making it clearer what clicking on it does: click the crate name to open the crate's home page. It also removes the Rust logo from non-official-Rust crates, again to make the navigation and supply chain clearer (since the crate name has been added, the logo is no longer necessary for navigation). It adds a bit more clarifying information for lateral navigation. On items that don't add their own sidebar items, it just shows its siblings directly below the crate name and logo, but for other items, it shows "In crate alloc" instead of just "In alloc". It also shows the lateral navigation tools on module pages, making modules consistent with every other item. ## Drawbacks While this actually takes up less screen real estate than the old layout on desktop, it takes up more HTML. It's also a bit more visually complex. ## Rationale and alternatives I could do what the Internals POC did and keep the vertically stacked layout all the time, instead of doing a horizontal stack where possible. It would take up more screen real estate, though. ## Prior art This design is lifted almost verbatim from Hexdocs. It seems to work for them. [`opentelemetry_process_propagator`], for example, has a long application name. [`opentelemetry_process_propagator`]: https://hexdocs.pm/opentelemetry_process_propagator/OpentelemetryProcessPropagator.html ## Unresolved questions Maybe we should encourage crate authors to include their own logo more often? It certainly helps give people a better sense of "place." This seems to be blocked on coming up with an API to do it without requiring them to host the file somewhere. ## Future possibilities Beyond this, plenty of other changes could be made to improve the layout, like * Fix things so that clicking an item in the sidebar doesn't cause it to scroll back to the top. * The [Internals demo](https://utherii.github.io/new.html) does this right: clicking an item in the sidebar changes the content area, but the sidebar itself does not change. This is nice, because clicking is cheap and I can skim the opening few paragraphs while browsing. * The layout of the docs sidebar causes trouble to implement this, because it's different on different pages, but at least fix this on the file browser. * Come up with a less cluttered way to do disclosure. There's a lot of `[-]` on the page. * We don't lack ideas to fix this one. We have *too many*. * Do a better job of separating local navigation (vec::Vec links to vec::IntoIter) and the table of contents (vec::Vec links to vec::Vec::new). * A possibility: add a Back arrow next to the "In [module]" header? ![image](https://github.com/rust-lang/rust/assets/1593513/e969faf7-7722-457a-b8c6-8d962e9e1e23) * Give readers more control of how much rustdoc shows them, and giving doc authors more control of how much it generates. Basically, https://github.com/rust-lang/rust/pull/115660 is great, let's do it too. But those are mostly orthogonal, not future possibilities unlocked by this change.
2023-10-11Rollup merge of #95967 - CAD97:from-utf16, r=dtolnayAli MJ Al-Nasrawy-0/+150
Add explicit-endian String::from_utf16 variants This adds the following APIs under `feature(str_from_utf16_endian)`: ```rust impl String { pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error>; pub fn from_utf16le_lossy(v: &[u8]) -> String; pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error>; pub fn from_utf16be_lossy(v: &[u8]) -> String; } ``` These are versions of `String::from_utf16` that explicitly take [UTF-16LE and UTF-16BE](https://unicode.org/faq/utf_bom.html#gen7). Notably, we can do better than just the obvious `decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes)).collect()` in that: - We handle the case where the byte slice is not an even number of bytes, and - In the case that the UTF-16 is native endian and the slice is aligned, we can forward to `String::from_utf16`. If the Unicode Consortium actively defines how to handle character replacement when decoding a UTF-16 bytestream with a trailing odd byte, I was unable to find reference. However, the behavior implemented here is fairly self-evidently correct: replace the single errant byte with the replacement character.
2023-10-09Make BTreeSet::new_in constSven Bartscher-1/+1
2023-10-09Make BTreeMap::new_in constSven Bartscher-1/+1
Closes rust-lang/wg-allocators#118
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+2
2023-10-08Bump to latest betaMark Rousskov-6/+6
2023-10-05Add more diagnostic items for clippyJason Newcomb-0/+4
2023-10-05Rollup merge of #116223 - catandcoder:master, r=cjgillotJubilee-1/+1
Fix misuses of a vs an Fixes the misuse of "a" vs "an", according to English grammatical expectations and using https://www.a-or-an.com/
2023-10-03Bump version placeholdersMark Rousskov-4/+4
2023-10-04Fix misuses of a vs ancui fliter-1/+1
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-02Use `addr_eq` in `{Arc,Rc}::ptr_eq`Scott McMurray-4/+5
Since it's made for stuff like this (see 106447)
2023-09-30Auto merge of #115546 - SUPERCILEX:patch-2, r=Amanieubors-4/+4
Weaken needlessly restrictive orderings on Arc::*_count Follow up to https://github.com/rust-lang/rust/pull/95183 from this zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Why.20does.20Arc.3A.3Astrong_count.20use.20Acquire.20instead.20of.20Relaxed.3F/near/386213850 I'd like to use the strong_count for a lockless algorithm I'm writing, but I don't need acquire semantics so that's pointlessly restrictive on arm/risc-v.
2023-09-29fix char importsChristopher Durham-6/+6