diff --git a/compiler/rustc_data_structures/src/flat_map_in_place.rs b/compiler/rustc_data_structures/src/flat_map_in_place.rs index d1fdd999d36ae..9064428202a8b 100644 --- a/compiler/rustc_data_structures/src/flat_map_in_place.rs +++ b/compiler/rustc_data_structures/src/flat_map_in_place.rs @@ -67,8 +67,13 @@ impl FlatMapInPlace 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; @@ -78,7 +83,7 @@ pub trait FlatMapInPlaceVec { fn insert(&mut self, idx: usize, elem: Self::Elem); } -impl FlatMapInPlaceVec for Vec { +unsafe impl FlatMapInPlaceVec for Vec { type Elem = T; fn len(&self) -> usize { @@ -104,7 +109,7 @@ impl FlatMapInPlaceVec for Vec { } } -impl FlatMapInPlaceVec for ThinVec { +unsafe impl FlatMapInPlaceVec for ThinVec { type Elem = T; fn len(&self) -> usize { @@ -130,7 +135,7 @@ impl FlatMapInPlaceVec for ThinVec { } } -impl FlatMapInPlaceVec for SmallVec<[T; N]> { +unsafe impl FlatMapInPlaceVec for SmallVec<[T; N]> { type Elem = T; fn len(&self) -> usize {