Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,11 @@ impl<T, A: Allocator> Vec<T, A> {
// * We only construct `&mut` references to `self.buf` through `&mut self` methods; borrow-
// check ensures that it is not possible to mutably alias `self.buf` within the
// returned lifetime.
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
unsafe {
// normally this would use `slice::from_raw_parts`, but it's
// hot enough that avoiding the UB check is worth it
&*core::intrinsics::aggregate_raw_ptr::<*const [T], _, _>(self.as_ptr(), self.len)
}
}

/// Extracts a mutable slice of the entire vector.
Expand Down Expand Up @@ -1681,7 +1685,11 @@ impl<T, A: Allocator> Vec<T, A> {
// * We only construct references to `self.buf` through `&self` and `&mut self` methods;
// borrow-check ensures that it is not possible to construct a reference to `self.buf`
// within the returned lifetime.
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
unsafe {
// normally this would use `slice::from_raw_parts_mut`, but it's
// hot enough that avoiding the UB check is worth it
&mut *core::intrinsics::aggregate_raw_ptr::<*mut [T], _, _>(self.as_mut_ptr(), self.len)
}
}

/// Returns a raw pointer to the vector's buffer, or a dangling raw pointer
Expand Down
13 changes: 5 additions & 8 deletions library/core/src/slice/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ impl<T, U> const PartialEq<[U]> for [T]
where
T: [const] PartialEq<U>,
{
// It's not worth trying to inline the loops underneath here *in MIR*,
// and preventing it encourages more useful inlining upstream,
// such as in `<str as PartialEq>::eq`.
// The codegen backend can still inline it later if needed.
#[rustc_no_mir_inline]
fn eq(&self, other: &[U]) -> bool {
SlicePartialEq::equal(self, other)
}

fn ne(&self, other: &[U]) -> bool {
SlicePartialEq::not_equal(self, other)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -99,10 +100,6 @@ impl<T: PartialOrd> PartialOrd for [T] {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const trait SlicePartialEq<B> {
fn equal(&self, other: &[B]) -> bool;

fn not_equal(&self, other: &[B]) -> bool {
!self.equal(other)
}
}

// Generic slice equality
Expand Down
Loading
Loading