Skip to content
Merged
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
15 changes: 10 additions & 5 deletions compiler/rustc_data_structures/src/flat_map_in_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ impl<V: FlatMapInPlaceVec> FlatMapInPlace<V::Elem> for V {
}
}

// A vec-like type must implement these operations to support `flat_map_in_place`.
pub trait FlatMapInPlaceVec {
/// A vec-like type must implement these operations to support `flat_map_in_place`.
///
/// # Safety
///
/// The memory safety of the unsafe block in `flat_map_in_place` relies on impls of this trait
/// implementing all the operations correctly.
pub unsafe trait FlatMapInPlaceVec {
type Elem;

fn len(&self) -> usize;
Expand All @@ -78,7 +83,7 @@ pub trait FlatMapInPlaceVec {
fn insert(&mut self, idx: usize, elem: Self::Elem);
}

impl<T> FlatMapInPlaceVec for Vec<T> {
unsafe impl<T> FlatMapInPlaceVec for Vec<T> {
type Elem = T;

fn len(&self) -> usize {
Expand All @@ -104,7 +109,7 @@ impl<T> FlatMapInPlaceVec for Vec<T> {
}
}

impl<T> FlatMapInPlaceVec for ThinVec<T> {
unsafe impl<T> FlatMapInPlaceVec for ThinVec<T> {
type Elem = T;

fn len(&self) -> usize {
Expand All @@ -130,7 +135,7 @@ impl<T> FlatMapInPlaceVec for ThinVec<T> {
}
}

impl<T, const N: usize> FlatMapInPlaceVec for SmallVec<[T; N]> {
unsafe impl<T, const N: usize> FlatMapInPlaceVec for SmallVec<[T; N]> {
type Elem = T;

fn len(&self) -> usize {
Expand Down
Loading