about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2023-11-10Closure-consuming helper functions for `fmt::Debug` helpersJohn Millikin-0/+2
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-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-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
2023-09-28add str_from_utf16_endian tracking issueChristopher Durham-4/+4
2023-09-28style nitsChristopher Durham-6/+6
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2023-09-28Add feature(str_from_utf16_endian)CAD97-0/+150
2023-09-28Auto merge of #114041 - nvzqz:nvzqz/shared_from_array, r=dtolnaybors-0/+42
Implement `From<[T; N]>` for `Rc<[T]>` and `Arc<[T]>` Given that `Box<[T]>` already has this conversion, the shared counterparts should also have it.
2023-09-28Auto merge of #111278 - EFanZh:implement-from-array-refs-for-vec, r=dtolnaybors-0/+30
Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone` Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation? ACP: rust-lang/libs-team#220. [Accepted] Closes #100880.
2023-09-17Rollup merge of #115477 - kellerkindt:stabilized_int_impl, r=dtolnayDylan DPC-1/+0
Stabilize the `Saturating` type Closes #87920 Closes #92354 Stabilization report https://github.com/rust-lang/rust/issues/87920#issuecomment-1652346124 FCP https://github.com/rust-lang/rust/issues/87920#issuecomment-1676438885
2023-09-16Rollup merge of #115895 - 52:patch-docs-vec-truncate, r=dtolnayMatthias Krüger-4/+4
Improve Vec(Deque)::truncate documentation Fixes #115784
2023-09-16Rollup merge of #115560 - ShE3py:format-results, r=dtolnayMatthias Krüger-5/+9
Update doc for `alloc::format!` and `core::concat!` Closes #115551. Used comments instead of `assert!`s as [`std::fmt`](https://doc.rust-lang.org/std/fmt/index.html#usage) uses comments. Should all the str-related macros (`format!`, `format_args!`, `concat!`, `stringify!`, `println!`, `writeln!`, etc.) references each others? For instance, [`concat!`](https://doc.rust-lang.org/core/macro.concat.html) mentions that integers are stringified, but don't link to `stringify!`. `@rustbot` label +A-docs +A-fmt
2023-09-16Rollup merge of #115487 - ModProg:patch-1, r=dtolnayMatthias Krüger-2/+2
Improve documentation on when signes are printed by default I found the original formulation a bit irritating, but not sure if I really improved it.
2023-09-16edit `std::collections::VecDeque` docsmxnkarou-2/+2
2023-09-16edit `std::vec::Vec::truncate` docsmxnkarou-2/+2
2023-09-16Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726bors-0/+6
Make useless_ptr_null_checks smarter about some std functions This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc. This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`). Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null. Follow-up of PR #113657 Fixes #114442
2023-09-06Update doc for `alloc::format!` and `core::concat!`ShE3py-5/+9
2023-09-04Weaken needlessly restrictive orderings on Arc::*_countAlex Saveau-4/+4
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-09-03Stabilize the Saturating type (saturating_int_impl, gh-87920)Michael Watzko-1/+0
Also stabilizes saturating_int_assign_impl, gh-92354. And also make pub fns const where the underlying saturating_* fns became const in the meantime since the Saturating type was created.
2023-09-03Improve documentation on when signes are printed by defaultRoland Fredenhagen-2/+2
2023-08-29Auto merge of #113859 - Manishearth:vec-as-mut-ptr-stacked-borrow, r=dtolnaybors-0/+51
Add note that Vec::as_mut_ptr() does not materialize a reference to the internal buffer See discussion on https://github.com/thomcc/rust-typed-arena/issues/62 and [t-opsem](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/is.20this.20typed_arena.20code.20sound.20under.20stacked.2Ftree.20borrows.3F) This method already does the correct thing here, but it is worth guaranteeing that it does so it can be used more freely in unsafe code without having to worry about potential Stacked/Tree Borrows violations. This moves one more unsafe usage pattern from the "very likely sound but technically not fully defined" box into "definitely sound", and currently our surface area of the latter is woefully small. I'm not sure how best to word this, opening this PR as a way to start discussion.
2023-08-28format, format_args: Make xref to std::fmt much more prominentIan Jackson-3/+4
That xref contains the actual documentation for what format! does. It should be very prominent - particularly, more so than the other links.
2023-08-28Rollup merge of #115280 - RalfJung:panic-cleanup-triple-backtrace, r=AmanieuMatthias Krüger-3/+4
avoid triple-backtrace due to panic-during-cleanup Supersedes https://github.com/rust-lang/rust/pull/115020 Cc https://github.com/rust-lang/rust/issues/114954 r? ``@Amanieu``
2023-08-27avoid triple-backtrace due to panic-during-cleanupRalf Jung-3/+4
2023-08-27Rollup merge of #115007 - kpreid:alloc, r=Mark-SimulacrumMatthias Krüger-6/+19
Correct and expand documentation of `handle_alloc_error` and `set_alloc_error_hook`. The primary goal of this change is to remove the false claim that `handle_alloc_error` always aborts; instead, code should be prepared for `handle_alloc_error` to possibly unwind, and be sound under that condition. I saw other opportunities for improvement, so I have added all the following information: * `handle_alloc_error` may panic instead of aborting. (Fixes #114898) * What happens if a hook returns rather than diverging. * A hook may panic. (This was already demonstrated in an example, but not stated in prose.) * A hook must be sound to call — it cannot assume that it is only called by the runtime, since its function pointer can be retrieved by safe code. I've checked these statements against the source code of `alloc` and `std`, but there may be nuances I haven't caught, so a careful review is welcome.