summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2023-10-02Bump version placeholdersMark Rousskov-4/+4
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-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/+40
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.
2023-08-23Bump cfg(bootstrap)Mark Rousskov-3/+2
2023-08-22Replace version placeholders with 1.73.0Mark Rousskov-2/+2
2023-08-22Auto merge of #113365 - dima74:diralik/add-deprecated-suggestions, ↵bors-1/+2
r=workingjubilee Add `suggestion` for some `#[deprecated]` items Consider code: ```rust fn main() { let _ = ["a", "b"].connect(" "); } ``` Currently it shows deprecated warning: ```rust warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join --> src/main.rs:2:24 | 2 | let _ = ["a", "b"].connect(" "); | ^^^^^^^ | = note: `#[warn(deprecated)]` on by default ``` This PR adds `suggestion` for `connect` and some other deprecated items, so the warning will be changed to this: ```rust warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join --> src/main.rs:2:24 | 2 | let _ = ["a", "b"].connect(" "); | ^^^^^^^ | = note: `#[warn(deprecated)]` on by default help: replace the use of the deprecated method | 2 | let _ = ["a", "b"].join(" "); | ^^^^ ```
2023-08-21Add `suggestion` for some `#[deprecated]` itemsDmitry Murzin-1/+2
2023-08-19Correct and expand documentation of `handle_alloc_error` and ↵Kevin Reid-6/+19
`set_alloc_error_hook`. Add the following facts: * `handle_alloc_error` may panic instead of aborting. * 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.
2023-08-18resolve conflictsKyle Lin-0/+1
2023-08-18relax redundancy constraintKyle Lin-4/+2
2023-08-17Auto merge of #114799 - RalfJung:less-transmute, r=m-ou-sebors-2/+2
avoid transmuting Box when we can just cast raw pointers instead Always better to avoid a transmute, in particular when the layout assumptions it is making are not clearly documented. :)
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Rollup merge of #114867 - ttsugriy:ttsugriy-patch-1, r=scottmcmMatthias Krüger-1/+1
[nit] Fix a comment typo.
2023-08-16Rollup merge of #114861 - RalfJung:no-effect, r=wesleywiserMatthias Krüger-1/+1
fix typo: affect -> effect I just realized I made a silly typo when writing that comment...
2023-08-15other elementsManish Goregaokar-3/+3
2023-08-15[nit] Fix a comment typo.Taras Tsugrii-1/+1
2023-08-15fix typo: affect -> effectRalf Jung-1/+1
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Auto merge of #112387 - clarfonthey:non-panicking-ceil-char-boundary, r=m-ou-sebors-5/+2
Don't panic in ceil_char_boundary Implementing the alternative mentioned in this comment: https://github.com/rust-lang/rust/issues/93743#issuecomment-1579935853 Since `floor_char_boundary` will always work (rounding down to the length of the string is possible), it feels best for `ceil_char_boundary` to not panic either. However, the semantics of "rounding up" past the length of the string aren't very great, which is why the method originally panicked in these cases. Taking into account how people are using this method, it feels best to simply return the end of the string in these cases, so that the result is still a valid char boundary.
2023-08-14avoid transmuting Box when we can just cast raw pointers insteadRalf Jung-2/+2
2023-08-13core/any: remove Provider traitwayne warren-2/+1
* remove `impl Provider for Error` * rename `Demand` to `Request` * update docstrings to focus on the conceptual API provided by `Request` * move `core::any::{request_ref, request_value}` functions into `core::error` * move `core::any::tag`, `core::any::Request`, an `core::any::TaggedOption` into `core::error` * replace `provide_any` feature name w/ `error_generic_member_access` * move `core::error::request_{ref,value} tests into core::tests::error module * update unit and doc tests
2023-08-12aliasing guaranteeManish Goregaokar-25/+40
2023-08-10Rollup merge of #114402 - tifv:tifv-fix-rc-doc, r=cuviperMichael Goulet-3/+3
Fix documentation of impl From<Vec<T>> for Rc<[T]> The example in the documentation of `impl From<Vec<T>> for <Rc<[T]>` is irrelevant (likely was copied from `impl From<Box<T>> for <Rc<T>`). I suggest taking corresponding example from the documentation of `Arc` and replacing `Arc` with `Rc`.
2023-08-10Rollup merge of #114257 - rytheo:linked-list-avoid-unique, r=cuviperMichael Goulet-11/+13
Avoid using `ptr::Unique` in `LinkedList` code Addresses a [comment](https://github.com/rust-lang/rust/pull/103093#discussion_r1268506747) by `@RalfJung` about avoiding use of `core::ptr::Unique` in the standard library.
2023-08-07Rollup merge of #114365 - tshepang:patch-6, r=Mark-SimulacrumMatthias Krüger-6/+0
str.rs: remove "Basic usage" text Only one example is given
2023-08-07Rollup merge of #114362 - tshepang:patch-1, r=Mark-SimulacrumMatthias Krüger-72/+1
string.rs: remove "Basic usage" text Only a single example is given
2023-08-06Add #[rustc_never_returns_null_ptr] to std functionsest31-0/+6
Add the attribute to standard library functions that are guaranteed to never return null pointers, as their originating data wouldn't allow it.
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-03Fix documentation of Rc as From<Vec<T>>July Tikhonov-3/+3
2023-08-02str.rs: remove "Basic usage" textTshepang Mbambo-6/+0
Only one example is given
2023-08-02string.rs: remove "Basic usage" textTshepang Mbambo-72/+1
Only a single example is given