Remove unnecessary lifetimes from Arena.

This commit is contained in:
Nicholas Nethercote 2024-09-12 09:14:46 +10:00
parent 0b59bba6ec
commit 65863c5e75

View File

@ -614,34 +614,34 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
pub trait ArenaAllocatable<'tcx, C = rustc_arena::IsNotCopy>: Sized { pub trait ArenaAllocatable<'tcx, C = rustc_arena::IsNotCopy>: Sized {
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self; fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self;
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
fn allocate_from_iter<'a>( fn allocate_from_iter(
arena: &'a Arena<'tcx>, arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>, iter: impl ::std::iter::IntoIterator<Item = Self>,
) -> &'a mut [Self]; ) -> &'tcx mut [Self];
} }
// Any type that impls `Copy` can be arena-allocated in the `DroplessArena`. // Any type that impls `Copy` can be arena-allocated in the `DroplessArena`.
impl<'tcx, T: Copy> ArenaAllocatable<'tcx, rustc_arena::IsCopy> for T { impl<'tcx, T: Copy> ArenaAllocatable<'tcx, rustc_arena::IsCopy> for T {
#[inline] #[inline]
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self { fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
arena.dropless.alloc(self) arena.dropless.alloc(self)
} }
#[inline] #[inline]
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
fn allocate_from_iter<'a>( fn allocate_from_iter(
arena: &'a Arena<'tcx>, arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>, iter: impl ::std::iter::IntoIterator<Item = Self>,
) -> &'a mut [Self] { ) -> &'tcx mut [Self] {
arena.dropless.alloc_from_iter(iter) arena.dropless.alloc_from_iter(iter)
} }
} }
$( $(
impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for $ty { impl<'tcx> ArenaAllocatable<'tcx, rustc_arena::IsNotCopy> for $ty {
#[inline] #[inline]
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self { fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut Self {
if !::std::mem::needs_drop::<Self>() { if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc(self) arena.dropless.alloc(self)
} else { } else {
@ -651,10 +651,10 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
#[inline] #[inline]
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
fn allocate_from_iter<'a>( fn allocate_from_iter(
arena: &'a Arena<'tcx>, arena: &'tcx Arena<'tcx>,
iter: impl ::std::iter::IntoIterator<Item = Self>, iter: impl ::std::iter::IntoIterator<Item = Self>,
) -> &'a mut [Self] { ) -> &'tcx mut [Self] {
if !::std::mem::needs_drop::<Self>() { if !::std::mem::needs_drop::<Self>() {
arena.dropless.alloc_from_iter(iter) arena.dropless.alloc_from_iter(iter)
} else { } else {
@ -667,7 +667,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
impl<'tcx> Arena<'tcx> { impl<'tcx> Arena<'tcx> {
#[inline] #[inline]
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&self, value: T) -> &mut T { pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&'tcx self, value: T) -> &mut T {
value.allocate_on(self) value.allocate_on(self)
} }
@ -691,7 +691,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
pub fn alloc_from_iter<T: ArenaAllocatable<'tcx, C>, C>( pub fn alloc_from_iter<T: ArenaAllocatable<'tcx, C>, C>(
&self, &'tcx self,
iter: impl ::std::iter::IntoIterator<Item = T>, iter: impl ::std::iter::IntoIterator<Item = T>,
) -> &mut [T] { ) -> &mut [T] {
T::allocate_from_iter(self, iter) T::allocate_from_iter(self, iter)