mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Allow clippy::from_mut_ref
This pattern is fine for arena allocators.
This commit is contained in:
parent
f00366d191
commit
968be98756
@ -22,6 +22,7 @@
|
|||||||
#![feature(strict_provenance)]
|
#![feature(strict_provenance)]
|
||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
#![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine.
|
||||||
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
@ -568,7 +569,9 @@ 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)]
|
||||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self;
|
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self;
|
||||||
|
#[allow(clippy::mut_from_ref)]
|
||||||
fn allocate_from_iter<'a>(
|
fn allocate_from_iter<'a>(
|
||||||
arena: &'a Arena<'tcx>,
|
arena: &'a Arena<'tcx>,
|
||||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||||
@ -578,10 +581,12 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||||||
// 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)]
|
||||||
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self {
|
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self {
|
||||||
arena.dropless.alloc(self)
|
arena.dropless.alloc(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(clippy::mut_from_ref)]
|
||||||
fn allocate_from_iter<'a>(
|
fn allocate_from_iter<'a>(
|
||||||
arena: &'a Arena<'tcx>,
|
arena: &'a Arena<'tcx>,
|
||||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||||
@ -601,6 +606,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(clippy::mut_from_ref)]
|
||||||
fn allocate_from_iter<'a>(
|
fn allocate_from_iter<'a>(
|
||||||
arena: &'a Arena<'tcx>,
|
arena: &'a Arena<'tcx>,
|
||||||
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
iter: impl ::std::iter::IntoIterator<Item = Self>,
|
||||||
@ -616,12 +622,14 @@ 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)]
|
||||||
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&self, value: T) -> &mut T {
|
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&self, value: T) -> &mut T {
|
||||||
value.allocate_on(self)
|
value.allocate_on(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any type that impls `Copy` can have slices be arena-allocated in the `DroplessArena`.
|
// Any type that impls `Copy` can have slices be arena-allocated in the `DroplessArena`.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(clippy::mut_from_ref)]
|
||||||
pub fn alloc_slice<T: ::std::marker::Copy>(&self, value: &[T]) -> &mut [T] {
|
pub fn alloc_slice<T: ::std::marker::Copy>(&self, value: &[T]) -> &mut [T] {
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
return &mut [];
|
return &mut [];
|
||||||
@ -629,6 +637,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
|
|||||||
self.dropless.alloc_slice(value)
|
self.dropless.alloc_slice(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::mut_from_ref)]
|
||||||
pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, C>, C>(
|
pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, C>, C>(
|
||||||
&'a self,
|
&'a self,
|
||||||
iter: impl ::std::iter::IntoIterator<Item = T>,
|
iter: impl ::std::iter::IntoIterator<Item = T>,
|
||||||
|
Loading…
Reference in New Issue
Block a user