about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2022-11-20Rollup merge of #104641 - tshepang:grammar, r=Mark-SimulacrumMatthias Krüger-2/+2
replace unusual grammar
2022-11-20Rollup merge of #101310 - zachs18:rc_get_unchecked_mut_docs_soundness, ↵Matthias Krüger-8/+74
r=Mark-Simulacrum Clarify and restrict when `{Arc,Rc}::get_unchecked_mut` is allowed. (Tracking issue for `{Arc,Rc}::get_unchecked_mut`: #63292) (I'm using `Rc` in this comment, but it applies for `Arc` all the same). As currently documented, `Rc::get_unchecked_mut` can lead to unsoundness when multiple `Rc`/`Weak` pointers to the same allocation exist. The current documentation only requires that other `Rc`/`Weak` pointers to the same allocation "must not be dereferenced for the duration of the returned borrow". This can lead to unsoundness in (at least) two ways: variance, and `Rc<str>`/`Rc<[u8]>` aliasing. ([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d7e2d091c389f463d121630ab0a37320)). This PR changes the documentation of `Rc::get_unchecked_mut` to restrict usage to when all `Rc<T>`/`Weak<T>` have the exact same `T` (including lifetimes). I believe this is sufficient to prevent unsoundness, while still allowing `get_unchecked_mut` to be called on an aliased `Rc` as long as the safety contract is upheld by the caller. ## Alternatives * A less strict, but still sound alternative would be to say that the caller must only write values which are valid for all aliased `Rc`/`Weak` inner types. (This was [mentioned](https://github.com/rust-lang/rust/issues/63292#issuecomment-568284090) in the tracking issue). This may be too complicated to clearly express in the documentation. * A more strict alternative would be to say that there must not be any aliased `Rc`/`Weak` pointers, i.e. it is required that get_mut would return `Some(_)`. (This was also mentioned in the tracking issue). There is at least one codebase that this would cause to become unsound ([here](https://github.com/kaimast/lsm-rs/blob/be5a164d770d850d905e510e2966ad4b1cc9aa5e/src/memtable.rs#L166), where additional locking is used to ensure unique access to an aliased `Rc<T>`; I saw this because it was linked on the tracking issue).
2022-11-20Unify stable and unstable sort implementations in same core moduleLukas Bergdoll-309/+39
This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`.
2022-11-20enable fuzzy_provenance_casts lint in liballocRalf Jung-0/+1
2022-11-20replace unusual grammarTshepang Mbambo-2/+2
2022-11-20Update VecDeque implementationMarkus Everling-1230/+760
2022-11-20Auto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errorsbors-1/+1
Minimal implementation of implicit deref patterns for Strings cc `@compiler-errors` `@BoxyUwU` https://github.com/rust-lang/lang-team/issues/88 #87121 ~~I forgot to add a feature gate, will do so in a minute~~ Done
2022-11-20Rollup merge of #104435 - scottmcm:iter-repeat-n, r=thomccYuki Okushi-2/+8
`VecDeque::resize` should re-use the buffer in the passed-in element Today it always copies it for *every* appended element, but one of those clones is avoidable. This adds `iter::repeat_n` (https://github.com/rust-lang/rust/issues/104434) as the primitive needed to do this. If this PR is acceptable, I'll also use this in `Vec` rather than its custom `ExtendElement` type & infrastructure that is harder to share between multiple different containers: https://github.com/rust-lang/rust/blob/101e1822c3e54e63996c8aaa014d55716f3937eb/library/alloc/src/vec/mod.rs#L2479-L2492
2022-11-20Rollup merge of #104112 - yancyribbens:add-copy-to-repeat-description, ↵Yuki Okushi-1/+1
r=JohnTitor rustdoc: Add copy to the description of repeat Small nit, but it's more clear to say `copy` here instead of defining `repeat` in terms of itself.
2022-11-18Change undefined-behavior doctests from ignore to no_run.Zachary S-4/+4
2022-11-18Apply suggestions from code review zachs18-2/+2
Fix spelling error.
2022-11-18Add examples to show when `{Arc,Rc}::get_mut_unchecked` is disallowed.Zachary S-0/+64
2022-11-18Clarify and restrict when `{Arc,Rc}::get_mut_unchecked` is allowed.Zachary S-8/+10
2022-11-18Remove Vec/Rc storage reuse optclubby789-107/+12
2022-11-18Rm diagnostic item, use lang itemDeadbeef-2/+1
2022-11-17Minimal implementation of implicit deref patternsDeadbeef-0/+1
2022-11-17Auto merge of #104205 - clubby789:grow-rc, r=thomccbors-38/+131
Attempt to reuse `Vec<T>` backing storage for `Rc/Arc<[T]>` If a `Vec<T>` has sufficient capacity to store the inner `RcBox<[T]>`, we can just reuse the existing allocation and shift the elements up, instead of making a new allocation.
2022-11-15`VecDeque::resize` should re-use the buffer in the passed-in elementScott McMurray-2/+8
Today it always copies it for *every* appended element, but one of those clones is avoidable.
2022-11-14rustdoc: Add copy to the description of repeatyancy-1/+1
2022-11-14Add `Vec` storage optimization to `Arc` and add testsclubby789-19/+66
2022-11-14Reuse `Vec<T>` backing storage for `Rc<[T]>`clubby789-19/+65
Co-authored-by: joboet <jonas.boettiger@icloud.com>
2022-11-14Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-21/+17
Bump bootstrap compiler to 1.66 This PR: - Bumps version placeholders to release - Bumps to latest beta - cfg-steps code r? `@pietroalbini`
2022-11-08Rollup merge of #104097 - RalfJung:miri-alloc-benches, r=thomccGuillaume Gomez-16/+19
run alloc benchmarks in Miri and fix UB Miri since recently has a "fake monotonic clock" that works even with isolation. Its measurements are not very meaningful but it means we can run these benches and check them for UB. And that's a good thing since there was UB here: fixes https://github.com/rust-lang/rust/issues/104096. r? ``@thomcc``
2022-11-08Rollup merge of #104093 - RalfJung:test-sizes, r=thomccGuillaume Gomez-0/+1
disable btree size tests on Miri Seems fine not to run these in Miri, they can't have UB anyway. And this lets us do layout randomization in Miri. r? ``@thomcc``
2022-11-07fmtRalf Jung-5/+5
2022-11-07Rollup merge of #104090 - wanghaha-dev:master, r=Dylan-DPCDylan DPC-1/+1
Modify comment syntax error Modify comment syntax error
2022-11-07run alloc benchmarks in Miri and fix UBRalf Jung-16/+19
2022-11-07disable btree size tests on MiriRalf Jung-0/+1
2022-11-07Modify comment syntax errorwanghaha-dev-1/+1
2022-11-07Rollup merge of #104056 - ripytide:patch-1, r=Mark-SimulacrumYuki Okushi-3/+3
Vec: IntoIterator signature consistency Also makes the code dryer.
2022-11-06cfg-step codeMark Rousskov-8/+4
2022-11-06Bump version placeholders to releaseMark Rousskov-13/+13
2022-11-06Vec: IntoIterator signature consistencyripytide-3/+3
Also makes the code dryer.
2022-11-05Fix unused_must_use warning for Box::from_rawAnett Seeker-1/+1
2022-11-05Enforce Tuple trait on Fn traitsMichael Goulet-0/+32
2022-11-03Fixed typosDouwe Schulte-2/+2
Fixed a typo that has been found on two locations in comments.
2022-11-02Rollup merge of #103807 - H4x5:string-extend-from-within-tracking-issue, ↵Dylan DPC-1/+1
r=Dylan-DPC Add tracking issue for `string_extend_from_within` Tracking issue: #103806 The original PR didn't create a tracking issue.
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-6/+5
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-31Add tracking issue for `string_extend_from_within`Sky-1/+1
2022-10-26ptr::eq: clarify that comparing dyn Trait is fragileRalf Jung-10/+10
2022-10-24Clairify Vec::capacity docsNixon Enraght-Moony-2/+3
Fixes #103326
2022-10-24Rollup merge of #99578 - steffahn:remove_redundant_bound, r=thomccYuki Okushi-1/+0
Remove redundant lifetime bound from `impl Borrow for Cow` The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference, because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types will outlive lifetimes outlived by the `Self` type (and all the trait's generic parameters, of which there are none in this case), so the implicit `B: 'a` implies `B::Owned: 'a` anyway. The explicit lifetime bound here does however [end up in documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html#impl-Borrow%3CB%3E), and that's confusing in my opinion, so let's remove it ^^ _(Documentation right now, compare to `AsRef`, too:)_ ![Screenshot_20220722_014055](https://user-images.githubusercontent.com/3986214/180332665-424d0c05-afb3-40d8-a330-a57a2c9a494b.png)
2022-10-22Fix typo in docs of `String::leak`.Finn Bear-1/+1
2022-10-22Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, ↵Dylan DPC-2/+2
r=dtolnay Adjust argument type for mutable with_metadata_of (#75091) The method takes two pointer arguments: one `self` supplying the pointer value, and a second pointer supplying the metadata. The new parameter type more clearly reflects the actual requirements. The provenance of the metadata parameter is disregarded completely. Using a mutable pointer in the call site can be coerced to a const pointer while the reverse is not true. In some cases, the current parameter type can thus lead to a very slightly confusing additional cast. [Example](https://github.com/HeroicKatora/static-alloc/commit/cad93775eb9adc62f744651e3abf19513e69e7d0). ```rust // Manually taking an unsized object from a `ManuallyDrop` into another allocation. let val: &core::mem::ManuallyDrop<T> = …; let ptr = val as *const _ as *mut T; let ptr = uninit.as_ptr().with_metadata_of(ptr); ``` This could then instead be simplified to: ```rust // Manually taking an unsized object from a `ManuallyDrop` into another allocation. let val: &core::mem::ManuallyDrop<T> = …; let ptr = uninit.as_ptr().with_metadata_of(&**val); ``` Tracking issue: https://github.com/rust-lang/rust/issues/75091 ``@dtolnay`` you're reviewed #95249, would you mind chiming in?
2022-10-22Rollup merge of #103280 - finnbear:impl_string_leak_2, r=joshtriplettDylan DPC-1/+30
(#102929) Implement `String::leak` (attempt 2) Implementation of `String::leak` (#102929) ACP: https://github.com/rust-lang/libs-team/issues/109 Supersedes #102941 (see previous reviews there) ```@rustbot``` label +T-libs-api -T-libs
2022-10-22Rollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcmMatthias Krüger-3/+1
Remove incorrect comment in `Vec::drain` r? ``@scottmcm`` Turns out this comment wasn't correct for 6 years, since #34951, which switched from using `slice::IterMut` into using `slice::Iter`.
2022-10-21Remove incorrect comment in `Vec::drain`Maybe Waffle-3/+1
2022-10-21Reduce mutability in std-use of with_metadata_ofAndreas Molzer-2/+2
2022-10-19Put fn in the right place.Finn Bear-29/+29
2022-10-19Copy of #102941.Finn Bear-1/+30