about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2022-12-28Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errorsfee1-dead-1/+1
Fix `unused_must_use` warning for `Box::from_raw`
2022-12-28Rollup merge of #94145 - ssomers:binary_heap_tests, r=jyn514fee1-dead-60/+109
Test leaking of BinaryHeap Drain iterators Add test cases about forgetting the `BinaryHeap::Drain` iterator, and slightly fortifies some other test cases. Consists of separate commits that I don't think are relevant on their own (but I'll happily turn these into more PRs if desired).
2022-12-27Update the documentation of `Vec` to use `extend(array)` instead of ↵Chayim Refael Friedman-1/+1
`extend(array.iter().copied())`
2022-12-23fix one more unaligned self.ptr, and add testsRalf Jung-1/+1
2022-12-23fix IntoIter::drop on high-alignment ZSTRalf Jung-10/+11
2022-12-20Auto merge of #105127 - Sp00ph:const_new, r=dtolnaybors-3/+4
Make `VecDeque::new` const (See #105072)
2022-12-19Update coerce_unsized tracking issue from #27732 to #18598Anders Kaseorg-5/+5
Issue #27732 was closed as a duplicate of #18598. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-12-17std::fmt: Use args directly in example codeEvan Jones-2/+2
The lint "clippy::uninlined_format_args" recommends inline variables in format strings. Fix two places in the docs that do not do this. I noticed this because I copy/pasted one example in to my project, then noticed this lint error. This fixes: error: variables can be used directly in the `format!` string --> src/main.rs:30:22 | 30 | let string = format!("{:.*}", decimals, magnitude); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: variables can be used directly in the `format!` string --> src/main.rs:39:2 | 39 | write!(&mut io::stdout(), "{}", args).unwrap();
2022-12-15doc: Fix a few small issuesHannes Körber-1/+1
* A few typos around generic types (`;` vs `,`) * Use inline code formatting for code fragments * One instance of wrong wording
2022-12-08Apply review feedback; Fix no_global_oom_handling buildScott McMurray-0/+5
2022-12-09Implement allow-by-default multiple_supertrait_upcastable lintGary Guo-0/+2
2022-12-08Make `VecDeque::from_iter` O(1) from `vec(_deque)::IntoIter`Scott McMurray-11/+98
2022-12-05Add O(1) `Vec -> VecDeque` conversion guaranteeMarkus Everling-3/+3
2022-12-05Auto merge of #105046 - scottmcm:vecdeque-vs-vec, r=Mark-Simulacrumbors-5/+12
Send `VecDeque::from_iter` via `Vec::from_iter` Since it's O(1) to convert between them now, might as well reuse the logic. Mostly for the various specializations it does, but might also save some monomorphization work if, say, people collect slice iterators into both `Vec`s and `VecDeque`s.
2022-12-03Rollup merge of #105032 - HintringerFabian:improve_docs, r=JohnTitorYuki Okushi-1/+10
improve doc of into_boxed_slice and impl From<Vec<T>> for Box<[T]> Improves description of `into_boxed_slice`, and adds example to `impl From<Vec<T>> for Box<[T]>`. Fixes #98908
2022-12-01Fix typo in commentMarkus Everling-1/+1
2022-12-01Make `VecDeque::new` constMarkus Everling-3/+4
2022-12-01Make `VecDeque::new_in` unstably constMarkus Everling-2/+1
2022-11-29Send `VecDeque::from_iter` via `Vec::from_iter`Scott McMurray-5/+12
Since it's O(1) to convert between them now, might as well reuse the logic. Mostly for the various specializations it does, but might also save some monomorphization work if, say, people collect slice iterators into both `Vec`s and `VecDeque`s.
2022-11-28improve docFabian Hintringer-1/+10
2022-11-28Auto merge of #102991 - Sp00ph:master, r=scottmcmbors-1277/+925
Update VecDeque implementation to use head+len instead of head+tail (See #99805) This changes `alloc::collections::VecDeque`'s internal representation from using head and tail indices to using a head index and a length field. It has a few advantages over the current design: * It allows the buffer to be of length 0, which means the `VecDeque::new` new longer has to allocate and could be changed to a `const fn` * It allows the `VecDeque` to fill the buffer completely, unlike the old implementation, which always had to leave a free space * It removes the restriction for the size to be a power of two, allowing it to properly `shrink_to_fit`, unlike the old `VecDeque` * The above points also combine to allow the `Vec<T> -> VecDeque<T>` conversion to be very cheap and guaranteed O(1). I mention this in the `From<Vec<T>>` impl, but it's not a strong guarantee just yet, as that would likely need some form of API change proposal. All the tests seem to pass for the new `VecDeque`, with some slight adjustments. r? `@scottmcm`
2022-11-26Add second test case in `make_contiguous_head_to_end`Markus Everling-10/+49
2022-11-26Improve slow path in `make_contiguous`Markus Everling-36/+76
2022-11-26Don't use `Take` in `SpecExtend` implMarkus Everling-21/+23
2022-11-24Tune RepeatWith::try_fold and Take::for_each and Vec::extend_trustedScott McMurray-5/+9
2022-11-25Changes according to code reviewMarkus Everling-144/+181
2022-11-24Stop peeling the last iteration of the loop in `Vec::repeat_with`Scott McMurray-11/+1
2022-11-24Extract the logic for `TrustedLen` to a named method that can be called directlyScott McMurray-32/+37
2022-11-22Rollup merge of #104647 - RalfJung:alloc-strict-provenance, r=thomccManish Goregaokar-0/+1
enable fuzzy_provenance_casts lint in liballoc and libstd r? ````@thomcc````
2022-11-22Rollup merge of #101655 - dns2utf8:box_docs, r=dtolnayManish Goregaokar-1/+1
Make the Box one-liner more descriptive I would like to avoid a definition that relies on itself. r? `@GuillaumeGomez`
2022-11-21Touch up Box<T> one-linerDavid Tolnay-2/+2
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