| Age | Commit message (Collapse) | Author | Lines |
|
|
|
Remove trait LengthAtMost32
This is a continuation of https://github.com/rust-lang/rust/pull/74026 preserving the original burrbull's commit.
I talked to @burrbull, he suggested me to finish his PR.
|
|
|
|
|
|
|
|
|
|
Add liballoc doc panic detail according to RawVec
|
|
Add liballoc impl SpecFromElem for i8
Speedup vec![1_i8; N] for non-zero element.
Before
test do_bench_from_elem_i8 ... bench: 130 ns/iter (+/- 7) = 61 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 4) = 66 MB/s
After
test do_bench_from_elem_i8 ... bench: 123 ns/iter (+/- 7) = 65 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 5) = 66 MB/s
No speed difference if element is already zero.
```rust
#[bench]
fn do_bench_from_elem_i8(b: &mut Bencher) {
b.bytes = 8 as u64;
b.iter(|| {
let dst = ve::vec![10_i8; 100];
assert_eq!(dst.len(), 100);
assert!(dst.iter().all(|x| *x == 10));
})
}
```
As suggested by @cuviper
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/SpecForElem.20for.20other.20integers
r? @cuviper
CC @joshtriplett
Edit: Wow, I just realized both reviewers are Josh.
|
|
|
|
Liballoc minor hash import tweak
|
|
impl PartialEq<Vec<B>> for &[A], &mut [A]
https://github.com/rust-lang/rfcs/issues/2917
|
|
|
|
|
|
|
|
|
|
Speedup vec![1_i8; N] for non-zero element.
Before
test do_bench_from_elem_i8 ... bench: 130 ns/iter (+/- 7) = 61 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 4) = 66 MB/s
After
test do_bench_from_elem_i8 ... bench: 123 ns/iter (+/- 7) = 65 MB/s
test do_bench_from_elem_u8 ... bench: 121 ns/iter (+/- 5) = 66 MB/s
No speed difference if element is already zero.
#[bench]
fn do_bench_from_elem_i8(b: &mut Bencher) {
b.bytes = 8 as u64;
b.iter(|| {
let dst = ve::vec![10_i8; 100];
assert_eq!(dst.len(), 100);
assert!(dst.iter().all(|x| *x == 10));
})
}
As suggested by @cuviper
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/SpecForElem.20for.20other.20integers
|
|
`#[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?
|
|
|
|
|
|
|
|
|
|
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.)
|
|
- 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.
|
|
Liballoc impl
Mainly code rearrangements
|
|
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.)
|
|
|
|
Show assertion on len too to show them how adding new items will affect both the
length and capacity, before and after.
|
|
|
|
The other blocks depends on Deref to make it easier for readers when
reimplementing or reading the implementations.
|
|
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.
|
|
|
|
|
|
Use min_specialization in liballoc
- Remove a type parameter from `[A]RcFromIter`.
- Remove an implementation of `[A]RcFromIter` that didn't actually
specialize anything.
- Remove unused implementation of `IsZero` for `Option<&mut T>`.
- Change specializations of `[A]RcEqIdent` to use a marker trait version
of `Eq`.
- Remove `BTreeClone`. I couldn't find a way to make this work with
`min_specialization`.
- Add `rustc_unsafe_specialization_marker` to `Copy` and `TrustedLen`.
After this only libcore is the only standard library crate using `feature(specialization)`.
cc #31844
|
|
Vec drop and truncate: drop using raw slice *mut [T]
By creating a *mut [T] directly (without going through &mut [T]), avoid
questions of validity of the contents of the slice.
Consider the following risky code:
```rust
unsafe {
let mut v = Vec::<bool>::with_capacity(16);
v.set_len(16);
}
```
The intention is that with this change, we avoid one of the soundness
questions about the above snippet, because Vec::drop no longer
produces a mutable slice of the vector's contents.
r? @RalfJung
|
|
Update Vec drop with a comment to explain why we want to use a raw
slice, and extend this pattern to also include the Vec's IntoIter.
|
|
- Remove a type parameter from `[A]RcFromIter`.
- Remove an implementation of `[A]RcFromIter` that didn't actually
specialize anything.
- Remove unused implementation of `IsZero` for `Option<&mut T>`.
- Change specializations of `[A]RcEqIdent` to use a marker trait version
of `Eq`.
- Remove `BTreeClone`. I couldn't find a way to make this work with
`min_specialization`.
- Add `rustc_unsafe_specialization_marker` to `Copy` and `TrustedLen`.
|
|
clippy::{filter_next,single_char_pattern,unit_arg,identity_conversion,nonminimal_bool}
|
|
By creating a *mut [T] directly (without going through &mut [T]), avoid
questions of validity of the contents of the slice.
Consider the following risky code:
```rust
unsafe {
let mut v = Vec::<bool>::with_capacity(16);
v.set_len(16);
}
```
The intention is that with this change, the above snippet will be
sound because Vec::drop does no longer produces a mutable slice of
the vector's contents.
|
|
|
|
Fix some aliasing issues in Vec
`Vec::extend` and `Vec::truncate` invalidated references into the vector even without reallocation, because they (implicitly) created a mutable reference covering the *entire* initialized part of the vector.
Fixes https://github.com/rust-lang/rust/issues/70301
I verified the fix by adding some new tests here that I ran in Miri.
|
|
|
|
This commit changes some usage of mem::forget into mem::ManuallyDrop
in some Vec, VecDeque, BTreeMap and Box methods.
Before the commit, the generated IR for some of the methods was
longer, and even after optimization, some unwinding artifacts were
still present.
|
|
Overhaul of the `AllocRef` trait to match allocator-wg's latest consens; Take 2
GitHub won't let me reopen #69889 so I make a new PR.
In addition to #69889 this fixes the unsoundness of `RawVec::into_box` when using allocators supporting overallocating. Also it uses `MemoryBlock` in `AllocRef` to unify `_in_place` methods by passing `&mut MemoryBlock`. Additionally, `RawVec` now checks for `size_of::<T>()` again and ignore every ZST. The internal capacity of `RawVec` isn't used by ZSTs anymore, as `into_box` now requires a length to be specified.
r? @Amanieu
fixes rust-lang/wg-allocators#38
fixes rust-lang/wg-allocators#41
fixes rust-lang/wg-allocators#44
fixes rust-lang/wg-allocators#51
|
|
|
|
also add smoke test to detect relocation even in rustc runs
|
|
|
|
|
|
|
|
impl From<[T; N]> for Vec<T>
Closes https://github.com/rust-lang/rust/issues/67963
|
|
|