about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2020-06-20Remove uses of `Vec::remove_item`Lukas Kalbertodt-16/+0
2020-06-20Deprecate `Vec::remove_item`Lukas Kalbertodt-10/+8
2020-06-19Rollup merge of #73465 - lzutao:spec-char-tostring, r=sfacklerManish Goregaokar-0/+8
Add specialization of `ToString for char` Closes #73462
2020-06-19Rollup merge of #72709 - LeSeulArtichaut:unsafe-liballoc, r=nikomatsakisManish Goregaokar-257/+387
`#[deny(unsafe_op_in_unsafe_fn)]` in liballoc This PR proposes to make use of the new `unsafe_op_in_unsafe_fn` lint, i.e. no longer consider the body of an unsafe function as an unsafe block and require explicit unsafe block to perform unsafe operations. This has been first (partly) suggested by @Mark-Simulacrum in https://github.com/rust-lang/rust/pull/69245#issuecomment-587817065 Tracking issue for the feature: #71668. ~~Blocked on #71862.~~ r? @Mark-Simulacrum cc @nikomatsakis can you confirm that those changes are desirable? Should I restrict it to only BTree for the moment?
2020-06-19Apply suggestions from code reviewLeSeulArtichaut-9/+11
Co-authored-by: nikomatsakis <niko@alum.mit.edu>
2020-06-19`#[deny(unsafe_op_in_unsafe_fn)]` in liballocLeSeulArtichaut-261/+389
2020-06-19Rollup merge of #73479 - pickfire:liballoc-spell, r=dtolnayRalf Jung-3/+3
Minor tweaks to liballoc
2020-06-19Rollup merge of #73459 - cuviper:into_boxed_slice-unicast, r=dtolnayRalf Jung-1/+1
Reduce pointer casts in Box::into_boxed_slice We only need to cast the pointer once to change `Box<T>` to an array `Box<[T; 1]>`, then we can let unsized coercion return `Box<[T]>`.
2020-06-19Rearrange liballoc __impl_slice_eq1Ivan Tham-1/+1
2020-06-19Liballoc clean up macro_rules styleIvan Tham-1/+1
2020-06-19Fix liballoc doc spellingIvan Tham-1/+1
2020-06-18Ensure std benchmarks get tested.Eric Huss-0/+1
2020-06-18Add specialization of `ToString for char`Lzu Tao-0/+8
2020-06-17Reduce pointer casts in Box::into_boxed_sliceJosh Stone-1/+1
We only need to cast the pointer once to change `Box<T>` to an array `Box<[T; 1]>`, then we can let unsized coercion return `Box<[T]>`.
2020-06-15Rollup merge of #72584 - CAD97:stabilize-58957, r=dtolnayRalf Jung-2/+8
Stabilize vec::Drain::as_slice and add `AsRef<[T]> for Drain<'_, T>`. Tracking issue: #58957. Does not stabilize `slice::IterMut::as_slice` yet. cc @cuviper This PR proposes stabilizing just the `vec::Drain::as_slice` part of that tracking issue. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
2020-06-12Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnayDylan DPC-17/+17
Migrate to numeric associated consts The deprecation PR is #72885 cc #68490 cc rust-lang/rfcs#2700
2020-06-10Migrate to numeric associated constsLzu Tao-17/+17
2020-06-09Rename some identifiers in `RawVec` and `libarena`.Nicholas Nethercote-53/+36
- Use `len` more consistently for the number of elements in a vector, because that's the usual name. - Use `additional` more consistently for the number of elements we want to add, because that's what `Vec::reserve()` uses. - Use `cap` consistently rather than `capacity`. - Plus a few other tweaks. This increases consistency and conciseness.
2020-06-09Remove `RawVec::reserve_in_place`.Nicholas Nethercote-39/+6
Also remove a now-unnecessary `placement` argument.
2020-06-08Rollup merge of #72811 - pickfire:liballoc-impl, r=AmanieuRalf Jung-42/+40
Liballoc impl Mainly code rearrangements
2020-06-08Rollup merge of #72583 - CAD97:vec-iter-asref-slice, r=dtolnayRalf Jung-0/+7
impl AsRef<[T]> for vec::IntoIter<T> Adds `impl<T> AsRef<[T]> for vec::IntoIter<T>`. This mirrors the same trait impl for [`slice::Iter`](https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html). Both types already offer `fn as_slice(&self) -> &[T]`, this just adds the trait impl for `vec::IntoIter`. If/when `fn as_slice(&self) -> &[T]` stabilizes for `vec::Drain` and `slice::IterMut`, they should get `AsRef<[T]>` impls as well. As thus, tangentially related to #58957. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
2020-06-06Elide type on liballoc vecIvan Tham-1/+1
2020-06-05Auto merge of #73025 - Dylan-DPC:rollup-a1uzj5u, r=Dylan-DPCbors-1/+1
Rollup of 5 pull requests Successful merges: - #72260 (Spell out `Self` in async function return) - #72996 (Remove unsused `NodeId` related APIs in hir map) - #73010 (Update RELEASES.md) - #73017 (Use assert_eq for liballoc test) - #73019 (add test for #72960) Failed merges: r? @ghost
2020-06-05Auto merge of #72957 - Mark-Simulacrum:bootstrap-bump, r=sfacklerbors-24/+5
Bump bootstrap compiler to 1.45 Pretty standard update.
2020-06-05Use assert_eq for liballoc testIvan Tham-1/+1
2020-06-05Add more assert to Vec with_capacity docsIvan Tham-0/+3
Show assertion on len too to show them how adding new items will affect both the length and capacity, before and after.
2020-06-03Bump to 1.46Mark Rousskov-24/+5
2020-06-03Add assert to Vec with_capacity docsIvan Tham-0/+2
2020-05-31Merge raw_vec into_box with previous impl<T, Global>Ivan Tham-26/+24
There are two separate `impl<T, Global>` which no special reason, it would be better to merge both of them.
2020-05-31Rearrange impl blocks with Deref as firstIvan Tham-16/+16
The other blocks depends on Deref to make it easier for readers when reimplementing or reading the implementations.
2020-05-30Rollup merge of #72499 - mendess:master, r=dtolnayRalf Jung-0/+41
Override Box::<[T]>::clone_from Avoid dropping and reallocating when cloning to an existing box if the lengths are the same. It would be nice if this could also be specialized for `Copy` but I don't know how that works since it's not on stable. Will gladly look into it if it's deemed as a good idea. This is my first PR with code, hope I did everything right :smile:
2020-05-30Rollup merge of #72162 - cuviper:extend_one, r=Mark-SimulacrumYuki Okushi-0/+126
Add Extend::{extend_one,extend_reserve} This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
2020-05-29Add Extend::{extend_one,extend_reserve}Josh Stone-0/+126
This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
2020-05-29Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJungbors-0/+19
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
2020-05-29Rollup merge of #71095 - pickfire:box-from-array, r=dtolnayRalf Jung-0/+19
impl From<[T; N]> for Box<[T]> Based on https://github.com/rust-lang/rust/pull/68692
2020-05-29Rollup merge of #72701 - pickfire:patch-1, r=Mark-SimulacrumDylan DPC-1/+1
Fix grammar in liballoc raw_vec
2020-05-29Remove flaky test and document the other's flakinessmendess-8/+5
2020-05-29Rollup merge of #72288 - vorner:stabilize-weak-into-raw, r=dtolnayYuki Okushi-24/+8
Stabilization of weak-into-raw Closes #60728. There are also two removals of `#![feature(weak_into_raw)]` in the `src/tools/miri` submodule. How should I synchronize the changes with there? * I can ignore it for now and once this gets merged, update the tool, send a pull request to that one and then reference the changes to rustc. * I could try submitting the changes to miri first, but then the build would fail there, because the attribute would still be needed. I think the first one is the correct one, extrapolating from the contributing guidelines (even though they speak about breaking the tools and this should not break it, as extra feature should not hurt).
2020-05-29Fix grammar in liballoc raw_vecIvan Tham-1/+1
2020-05-27Rollup merge of #72533 - Diggsey:db-fix-arc-ub2, r=dtolnayDylan DPC-9/+26
Resolve UB in Arc/Weak interaction (2) Use raw pointers to avoid making any assertions about the data field. Follow up from #72479, see that PR for more detail on the motivation. @RalfJung I was able to avoid a lot of the changes to `Weak`, by making a helper type (`WeakInner`) - because of auto-deref and because the fields have the same name, the rest of the code continues to compile.
2020-05-25stabilize vec_drain_as_sliceCAD97-2/+8
2020-05-25impl AsRef<[T]> for vec::IntoIter<T>CAD97-0/+7
2020-05-25Fix UB in ArcDiggory Blake-9/+26
Use raw pointers to avoid making any assertions about the data field.
2020-05-23Add testsmendess-0/+36
2020-05-23Override Box::<[T]>::clone_frommendess-0/+8
2020-05-20impl From<[T; N]> for Box<[T]>Ivan Tham-0/+19
Based on https://github.com/rust-lang/rust/pull/68692
2020-05-20Adjust the zero check in `RawVec::grow`.Nicholas Nethercote-4/+3
This was supposed to land as part of #72227. (I wish `git push` would abort when you have uncommited changes.)
2020-05-19Auto merge of #72227 - nnethercote:tiny-vecs-are-dumb, r=Amanieubors-5/+141
Tiny Vecs are dumb. Currently, if you repeatedly push to an empty vector, the capacity growth sequence is 0, 1, 2, 4, 8, 16, etc. This commit changes the relevant code (the "amortized" growth strategy) to skip 1 and 2, instead using 0, 4, 8, 16, etc. (You can still get a capacity of 1 or 2 using the "exact" growth strategy, e.g. via `reserve_exact()`.) This idea (along with the phrase "tiny Vecs are dumb") comes from the "doubling" growth strategy that was removed from `RawVec` in #72013. That strategy was barely ever used -- only when a `VecDeque` was grown, oddly enough -- which is why it was removed in #72013. (Fun fact: until just a few days ago, I thought the "doubling" strategy was used for repeated push case. In other words, this commit makes `Vec`s behave the way I always thought they behaved.) This change reduces the number of allocations done by rustc itself by 10% or more. It speeds up rustc, and will also speed up any other Rust program that uses `Vec`s a lot. In theory, the change could increase memory usage, but in practice it doesn't. It would be an unusual program where very small `Vec`s having a capacity of 4 rather than 1 or 2 would make a difference. You'd need a *lot* of very small `Vec`s, and/or some very small `Vec`s with very large elements. r? @Amanieu
2020-05-19Auto merge of #71447 - cuviper:unsized_cow, r=dtolnaybors-0/+103
impl From<Cow> for Box, Rc, and Arc These forward `Borrowed`/`Owned` values to existing `From` impls. - `Box<T>` is a fundamental type, so it would be a breaking change to add a blanket impl. Therefore, `From<Cow>` is only implemented for `[T]`, `str`, `CStr`, `OsStr`, and `Path`. - For `Rc<T>` and `Arc<T>`, `From<Cow>` is implemented for everything that implements `From` the borrowed and owned types separately.
2020-05-18Tiny Vecs are dumb.Nicholas Nethercote-5/+141
Currently, if you repeatedly push to an empty vector, the capacity growth sequence is 0, 1, 2, 4, 8, 16, etc. This commit changes the relevant code (the "amortized" growth strategy) to skip 1 and 2 in most cases, instead using 0, 4, 8, 16, etc. (You can still get a capacity of 1 or 2 using the "exact" growth strategy, e.g. via `reserve_exact()`.) This idea (along with the phrase "tiny Vecs are dumb") comes from the "doubling" growth strategy that was removed from `RawVec` in #72013. That strategy was barely ever used -- only when a `VecDeque` was grown, oddly enough -- which is why it was removed in #72013. (Fun fact: until just a few days ago, I thought the "doubling" strategy was used for repeated push case. In other words, this commit makes `Vec`s behave the way I always thought they behaved.) This change reduces the number of allocations done by rustc itself by 10% or more. It speeds up rustc, and will also speed up any other Rust program that uses `Vec`s a lot.