about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2020-09-16Add array window fnkadmin-0/+3
Updated issue to #75027 Update to rm oob access And hopefully fix docs as well Fixed naming conflict in test Fix test which used 1-indexing Nth starts from 0, woops Fix a bunch of off by 1 errors See https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=757b311987e3fae1ca47122969acda5a Add even more off by 1 errors And also write `next` and `next_back` in terms of `nth` and `nth_back`. Run fmt Fix forgetting to change fn name in test add nth_back test & document unsafe Remove as_ref().unwrap() Documented occurrences of unsafe, noting what invariants are maintained
2020-09-16Rollup merge of #76662 - RalfJung:lib-test-miri, r=Mark-SimulacrumRalf Jung-7/+6
Fix liballoc test suite for Miri Mostly, fix the regression introduced by https://github.com/rust-lang/rust/pull/75207 that caused slices (i.e., references) to be created to invalid memory or memory that has aliasing pointers that we want to keep valid. @dylni this changes the type of `check_range` to only require the length, not the full reference to the slice, which indeed is all the information this function requires. Also reduce the size of a test introduced in https://github.com/rust-lang/rust/pull/70793 to make it not take 3 minutes in Miri. This makes https://github.com/RalfJung/miri-test-libstd work again.
2020-09-16Rollup merge of #76534 - notriddle:doc-comments, r=jyn514Ralf Jung-0/+4
Add doc comments for From impls https://github.com/rust-lang/rust/issues/51430
2020-09-16Rollup merge of #76062 - pickfire:patch-13, r=jyn514Ralf Jung-1/+3
Vec slice example fix style and show type elision
2020-09-16Rollup merge of #76056 - pickfire:patch-10, r=jyn514Ralf Jung-0/+1
Add more info for Vec Drain doc See its documentation for more
2020-09-16BTreeMap: avoid slices even moreStein Somers-16/+29
2020-09-15fix slice::check_range aliasing problemsRalf Jung-7/+6
2020-09-15Test and fix Sync & Send traits of BTreeMap artefactsStein Somers-0/+143
2020-09-15Vec doc use elision as code rather than commentIvan Tham-1/+3
2020-09-15Auto merge of #76682 - richkadel:vec-take, r=Mark-Simulacrumbors-0/+5
Optimize behavior of vec.split_off(0) (take all) Optimization improvement to `split_off()` so the performance meets the intuitively expected behavior when `at == 0`, avoiding the current behavior of copying the entire vector. The change honors documented behavior that the original vector's "previous capacity unchanged". This improvement better supports the pattern for building and flushing a buffer of elements, such as the following: ```rust let mut vec = Vec::new(); loop { vec.push(something); if condition_is_met { process(vec.split_off(0)); } } ``` `Option` wrapping is the first alternative I thought of, but is much less obvious and more verbose: ```rust let mut capacity = 1; let mut vec: Option<Vec<Stuff>> = None; loop { vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something); if condition_is_met { capacity = vec.capacity(); process(vec.take().unwrap()); } } ``` Directly using `mem::replace()` (instead of calling`split_off()`) could work, but `mem::replace()` is a more advanced tool for Rust developers, and in this case, I believe developers would assume the standard library should be sufficient for the purpose described here. The benefit of the approach to this change is it does not change the existing API contract, but improves the peformance of `split_off(0)` for `Vec`, `String` (which delegates `split_off()` to `Vec`), and any other existing use cases. This change adds tests to validate the behavior of `split_off()` with regard to capacity, as originally documented, and confirm that behavior still holds, when `at == 0`. The change is an implementation detail, and does not require a documentation change, but documenting the new behavior as part of its API contract may benefit future users. (Let me know if I should make that documentation update.) Note, for future consideration: I think it would be helpful to introduce an additional method to `Vec` (if not also to `String`): ``` pub fn take_all(&mut self) -> Self { self.split_off(0) } ``` This would make it more clear how `Vec` supports the pattern, and make it easier to find, since the behavior is similar to other `take()` methods in the Rust standard library. r? `@wesleywiser` FYI: `@tmandry`
2020-09-13Optimize behavior of vec.split_off(0) (take all)Rich Kadel-0/+5
Optimization improvement to `split_off()` so the performance meets the intuitively expected behavior when `at == 0`, avoiding the current behavior of copying the entire vector. The change honors documented behavior that the method leaves the original vector's "previous capacity unchanged". This improvement better supports the pattern for building and flushing a buffer of elements, such as the following: ```rust let mut vec = Vec::new(); loop { vec.push(something); if condition_is_met { process(vec.split_off(0)); } } ``` `Option` wrapping is the first alternative I thought of, but is much less obvious and more verbose: ```rust let mut capacity = 1; let mut vec: Option<Vec<Stuff>> = None; loop { vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something); if condition_is_met { capacity = vec.capacity(); process(vec.take().unwrap()); } } ``` Directly applying `mem::replace()` could work, but `mem::` functions are typically a last resort, when a developer is actively seeking better performance than the standard library provides, for example. The benefit of the approach to this change is it does not change the existing API contract, but improves the peformance of `split_off(0)` for `Vec`, `String` (which delegates `split_off()` to `Vec`), and any other existing use cases. This change adds tests to validate the behavior of `split_off()` with regard to capacity, as originally documented, and confirm that behavior still holds, when `at == 0`. The change is an implementation detail, and does not require a documentation change, but documenting the new behavior as part of its API contract may benefit future users. (Let me know if I should make that documentation update.) Note, for future consideration: I think it would be helpful to introduce an additional method to `Vec` (if not also to `String`): ``` pub fn take_all(&mut self) -> Self { self.split_off(0) } ``` This would make it more clear how `Vec` supports the pattern, and make it easier to find, since the behavior is similar to other `take()` methods in the Rust standard library.
2020-09-13Rollup merge of #76527 - fusion-engineering-forks:cleanup-uninit, ↵Jonas Schievink-5/+4
r=jonas-schievink Remove internal and unstable MaybeUninit::UNINIT. Looks like it is no longer necessary, as `uninit_array()` can be used instead in the few cases where it was needed. (I wanted to just add `#[doc(hidden)]` to remove clutter from the documentation, but looks like it can just be removed entirely.)
2020-09-12Auto merge of #76538 - ↵bors-0/+2
fusion-engineering-forks:check-useless-unstable-trait-impl, r=lcnr Warn for #[unstable] on trait impls when it has no effect. Earlier today I sent a PR with an `#[unstable]` attribute on a trait `impl`, but was informed that this attribute has no effect there. (comment: https://github.com/rust-lang/rust/pull/76525#issuecomment-689678895, issue: https://github.com/rust-lang/rust/issues/55436) This PR adds a warning for this situation. Trait `impl` blocks with `#[unstable]` where both the type and the trait are stable will result in a warning: ``` warning: An `#[unstable]` annotation here has no effect. See issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information. --> library/std/src/panic.rs:235:1 | 235 | #[unstable(feature = "integer_atomics", issue = "32976")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` --- It detects three problems in the existing code: 1. A few `RefUnwindSafe` implementations for the atomic integer types in `library/std/src/panic.rs`. Example: https://github.com/rust-lang/rust/blob/d92155bf6ae0b7d79fc83cbeeb0cc0c765353471/library/std/src/panic.rs#L235-L236 2. An implementation of `Error` for `LayoutErr` in `library/std/srd/error.rs`: https://github.com/rust-lang/rust/blob/d92155bf6ae0b7d79fc83cbeeb0cc0c765353471/library/std/src/error.rs#L392-L397 3. `From` implementations for `Waker` and `RawWaker` in `library/alloc/src/task.rs`. Example: https://github.com/rust-lang/rust/blob/d92155bf6ae0b7d79fc83cbeeb0cc0c765353471/library/alloc/src/task.rs#L36-L37 Case 3 interesting: It has a bound with an `#[unstable]` trait (`W: Wake`), so appears to have much effect on stable code. It does however break similar blanket implementations. It would also have immediate effect if `Wake` was implemented for any stable type. (Which is not the case right now, but there are no warnings in place to prevent it.) Whether this case is a problem or not is not clear to me. If it isn't, adding a simple `c.visit_generics(..);` to this PR will stop the warning for this case.
2020-09-12Add tests for weak into/from rawCAD97-0/+84
2020-09-12Allow Weak::as_ptr and friends for unsized TCAD97-9/+9
2020-09-12Adjust sync::Weak::from_raw to support unsized TCAD97-11/+12
2020-09-12?Sized bounds for rc::Weak::as_ptr and friendsCAD97-14/+14
2020-09-12Adjust rc::Weak::from_raw to support unsized TCAD97-11/+12
2020-09-12Rollup merge of #76530 - carbotaniuman:fix-rc, r=RalfJungRalf Jung-38/+75
Eliminate mut reference UB in Drop impl for Rc<T> This changes `self.ptr.as_mut()` with `get_mut_unchecked` which does not use an intermediate reference. Arc<T> already handled this case properly. Fixes #76509
2020-09-12Auto merge of #75021 - cuviper:array_chunks_mut, r=scottmcmbors-0/+2
Add `slice::array_chunks_mut` This follows `array_chunks` from #74373 with a mutable version, `array_chunks_mut`. The implementation is identical apart from mutability. The new tests are adaptations of the `chunks_exact_mut` tests, plus an inference test like the one for `array_chunks`. I reused the unstable feature `array_chunks` and tracking issue #74985, but I can separate that if desired. r? `@withoutboats` cc `@lcnr`
2020-09-11Auto merge of #73951 - pickfire:liballoc-intoiter, r=Mark-Simulacrumbors-33/+25
Liballoc intoiter refactor
2020-09-11Address review commentscarbotaniuman-8/+14
2020-09-11Allow unstable From impl for [Raw]Waker.Mara Bos-0/+2
2020-09-10Auto merge of #74437 - ssomers:btree_no_root_in_noderef, r=Mark-Simulacrumbors-117/+163
BTreeMap: move up reference to map's root from NodeRef Since the introduction of `NodeRef` years ago, it also contained a mutable reference to the owner of the root node of the tree (somewhat disguised as *const). Its intent is to be used only when the rest of the `NodeRef` is no longer needed. Moving this to where it's actually used, thought me 2 things: - Some sort of "postponed mutable reference" is required in most places that it is/was used, and that's exactly where we also need to store a reference to the length (number of elements) of the tree, for the same reason. The length reference can be a normal reference, because the tree code does not care about tree length (just length per node). - It's downright obfuscation in `from_sorted_iter` (transplanted to #75329) - It's one of the reasons for the scary notice on `reborrow_mut`, the other one being addressed in #73971. This does repeat the raw pointer code in a few places, but it could be bundled up with the length reference. r? `@Mark-Simulacrum`
2020-09-09Rollup merge of #76543 - ssomers:btree_cleanup_4, r=Mark-SimulacrumTyler Mandry-0/+3
Document btree's unwrap_unchecked #74693's second wind
2020-09-10Document btree's unwrap_uncheckedStein Somers-0/+3
2020-09-09Rollup merge of #76504 - Flying-Toast:master, r=lcnrTyler Mandry-2/+2
Capitalize safety comments
2020-09-09Rollup merge of #76481 - moonheart08:vec_deque_constify, r=sfacklerTyler Mandry-6/+2
Convert repetitive target_pointer_width checks to const solution. Simply a quick code tidying change. Not sure if more needs to be said.
2020-09-10BTreeMap: pull the map's root out of NodeRefStein Somers-117/+163
2020-09-09Add documentation for `impl<T> From<BinaryHeap<T>> for Vec<T>`Michael Howell-0/+4
2020-09-09Formatcarbotaniuman-3/+3
2020-09-09Add WeakInner<'_> and have Weak::inner() return itcarbotaniuman-39/+70
This avoids overlapping a reference covering the data field, which may be changed due in concurrent conditions. This fully fixed the UB mainfested with `new_cyclic`.
2020-09-09Disable AsRef implementations for String's Drain.Mara Bos-14/+15
Since trait implementations cannot be unstable, we should only add them when the as_str feature gets stabilized. Until then, only `.as_str()` is available (behind a feature gate).
2020-09-09Eliminate mut reference UB in Drop impl for Rc<T>carbotaniuman-1/+1
This changes `self.ptr.as_mut()` with `get_mut_unchecked` which does not use an intermediate reference. Arc<T> already handled this case properly.
2020-09-09Mark AsRef impls for String's Drain as stable.Mara Bos-2/+2
Trait implementations effectively can't be #[unstable].
2020-09-09Remove internal and unstable MaybeUninit::UNINIT.Mara Bos-5/+4
Looks like it is no longer necessary, as uninit_array() can be used instead in the few cases where it was needed.
2020-09-09Add AsRef<[u8]> for String's Drain.Mara Bos-0/+7
2020-09-09Show remaining data in string::Drain's Debug impl.Mara Bos-1/+1
2020-09-09Add as_str() and AsRef to string::Drain.Mara Bos-0/+26
2020-09-09BTreeMap: avoid aliasing by avoiding slicesStein Somers-167/+204
2020-09-09make as_leaf return a raw pointer, to reduce aliasing assumptionsRalf Jung-7/+12
2020-09-08Capitalize safety commentsFlying-Toast-2/+2
2020-09-08Update library/alloc/src/collections/vec_deque.rs Braden Nelson-1/+1
Replace lshift with multiply Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-09-08Convert MAXIMUM_ZST_CAPACITY to be calculated in amoonheart08-6/+2
const instead of multiple target_pointer_width checks.
2020-09-07Typo fix scottmcm-1/+1
Thanks, Amanieu Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2020-09-07Rollup merge of #76303 - jyn514:vec-assert-doc, r=Dylan-DPCDylan DPC-0/+3
Link to `#capacity-and-reallocation` when using with_capacity Follow up to https://github.com/rust-lang/rust/pull/76058#discussion_r479655750. r? @pickfire
2020-09-05Auto merge of #76217 - RalfJung:maybe-uninit-slice, r=KodrAusbors-11/+15
rename MaybeUninit slice methods The `first` methods conceptually point to the whole slice, not just its first element, so rename them to be consistent with the raw ptr methods on ref-slices. Also, do the equivalent of https://github.com/rust-lang/rust/pull/76047 for the slice reference getters, and make them part of https://github.com/rust-lang/rust/issues/63569 (so far they somehow had no tracking issue). * first_ptr -> slice_as_ptr * first_ptr_mut -> slice_as_mut_ptr * slice_get_ref -> slice_assume_init_ref * slice_get_mut -> slice_assume_init_mut
2020-09-05Nightly is currently 1.48scottmcm-1/+1
2020-09-05rename MaybeUninit slice methodsRalf Jung-11/+15
first_ptr -> slice_as_ptr first_ptr_mut -> slice_as_mut_ptr slice_get_ref -> slice_assume_init_ref slice_get_mut -> slice_assume_init_mut
2020-09-05Rollup merge of #76060 - pickfire:patch-12, r=jyn514Dylan DPC-1/+3
Link vec doc to & reference It is not always obvious that people could see the docs for `&` especially for beginners, it also helps learnability.