Fix empty borrow location warnings (#4593)
* Fix empty borrow location warnings * add error tests for rc variants * fix clippy
This commit is contained in:
1 parent
525c00ddac
commit
f95d8e4682
3 files changed
+146
-34
No files matched your search
@@ -19,6 +19,9 @@ use crate::{
|
||||
type RwLockStorageEntryRef = RwLockReadGuard<'static, StorageEntry<RwLockStorageEntryData>>;
|
||||
type RwLockStorageEntryMut = RwLockWriteGuard<'static, StorageEntry<RwLockStorageEntryData>>;
|
||||
|
||||
type AnyRef = MappedRwLockReadGuard<'static, Box<dyn Any + Send + Sync + 'static>>;
|
||||
type AnyRefMut = MappedRwLockWriteGuard<'static, Box<dyn Any + Send + Sync + 'static>>;
|
||||
|
||||
pub(crate) enum RwLockStorageEntryData {
|
||||
Reference(GenerationalPointer<SyncStorage>),
|
||||
Rc(RcStorageEntry<Box<dyn Any + Send + Sync>>),
|
||||
@@ -59,13 +62,16 @@ pub struct SyncStorage {
|
||||
impl SyncStorage {
|
||||
pub(crate) fn read(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> BorrowResult<MappedRwLockReadGuard<'static, Box<dyn Any + Send + Sync + 'static>>> {
|
||||
Self::get_split_ref(pointer).map(|(_, guard)| {
|
||||
RwLockReadGuard::map(guard, |data| match &data.data {
|
||||
RwLockStorageEntryData::Data(data) => data,
|
||||
RwLockStorageEntryData::Rc(data) => &data.data,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
) -> BorrowResult<(AnyRef, GenerationalPointer<Self>)> {
|
||||
Self::get_split_ref(pointer).map(|(resolved, guard)| {
|
||||
(
|
||||
RwLockReadGuard::map(guard, |data| match &data.data {
|
||||
RwLockStorageEntryData::Data(data) => data,
|
||||
RwLockStorageEntryData::Rc(data) => &data.data,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
resolved,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -99,14 +105,16 @@ impl SyncStorage {
|
||||
|
||||
pub(crate) fn write(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> BorrowMutResult<MappedRwLockWriteGuard<'static, Box<dyn Any + Send + Sync + 'static>>>
|
||||
{
|
||||
Self::get_split_mut(pointer).map(|(_, guard)| {
|
||||
RwLockWriteGuard::map(guard, |data| match &mut data.data {
|
||||
RwLockStorageEntryData::Data(data) => data,
|
||||
RwLockStorageEntryData::Rc(data) => &mut data.data,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
) -> BorrowMutResult<(AnyRefMut, GenerationalPointer<Self>)> {
|
||||
Self::get_split_mut(pointer).map(|(resolved, guard)| {
|
||||
(
|
||||
RwLockWriteGuard::map(guard, |data| match &mut data.data {
|
||||
RwLockStorageEntryData::Data(data) => data,
|
||||
RwLockStorageEntryData::Rc(data) => &mut data.data,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
resolved,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -277,7 +285,7 @@ impl<T: Sync + Send + 'static> Storage<T> for SyncStorage {
|
||||
fn try_read(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> Result<Self::Ref<'static, T>, error::BorrowError> {
|
||||
let read = Self::read(pointer)?;
|
||||
let (read, pointer) = Self::read(pointer)?;
|
||||
|
||||
let read = MappedRwLockReadGuard::try_map(read, |any| {
|
||||
// Then try to downcast
|
||||
@@ -298,7 +306,7 @@ impl<T: Sync + Send + 'static> Storage<T> for SyncStorage {
|
||||
fn try_write(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> Result<Self::Mut<'static, T>, error::BorrowMutError> {
|
||||
let write = Self::write(pointer)?;
|
||||
let (write, pointer) = Self::write(pointer)?;
|
||||
|
||||
let write = MappedRwLockWriteGuard::try_map(write, |any| {
|
||||
// Then try to downcast
|
||||
|
||||
@@ -13,8 +13,9 @@ use std::{
|
||||
};
|
||||
|
||||
type RefCellStorageEntryRef = Ref<'static, StorageEntry<RefCellStorageEntryData>>;
|
||||
|
||||
type RefCellStorageEntryMut = RefMut<'static, StorageEntry<RefCellStorageEntryData>>;
|
||||
type AnyRef = Ref<'static, Box<dyn Any>>;
|
||||
type AnyRefMut = RefMut<'static, Box<dyn Any>>;
|
||||
|
||||
thread_local! {
|
||||
static UNSYNC_RUNTIME: RefCell<Vec<&'static UnsyncStorage>> = const { RefCell::new(Vec::new()) };
|
||||
@@ -54,13 +55,16 @@ pub struct UnsyncStorage {
|
||||
impl UnsyncStorage {
|
||||
pub(crate) fn read(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> BorrowResult<Ref<'static, Box<dyn Any>>> {
|
||||
Self::get_split_ref(pointer).map(|(_, guard)| {
|
||||
Ref::map(guard, |data| match &data.data {
|
||||
RefCellStorageEntryData::Data(data) => data,
|
||||
RefCellStorageEntryData::Rc(data) => &data.data,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
) -> BorrowResult<(AnyRef, GenerationalPointer<Self>)> {
|
||||
Self::get_split_ref(pointer).map(|(resolved, guard)| {
|
||||
(
|
||||
Ref::map(guard, |data| match &data.data {
|
||||
RefCellStorageEntryData::Data(data) => data,
|
||||
RefCellStorageEntryData::Rc(data) => &data.data,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
resolved,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,13 +102,16 @@ impl UnsyncStorage {
|
||||
|
||||
pub(crate) fn write(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> BorrowMutResult<RefMut<'static, Box<dyn Any>>> {
|
||||
Self::get_split_mut(pointer).map(|(_, guard)| {
|
||||
RefMut::map(guard, |data| match &mut data.data {
|
||||
RefCellStorageEntryData::Data(data) => data,
|
||||
RefCellStorageEntryData::Rc(data) => &mut data.data,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
) -> BorrowMutResult<(AnyRefMut, GenerationalPointer<Self>)> {
|
||||
Self::get_split_mut(pointer).map(|(resolved, guard)| {
|
||||
(
|
||||
RefMut::map(guard, |data| match &mut data.data {
|
||||
RefCellStorageEntryData::Data(data) => data,
|
||||
RefCellStorageEntryData::Rc(data) => &mut data.data,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
resolved,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -274,7 +281,7 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
|
||||
fn try_read(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> Result<Self::Ref<'static, T>, error::BorrowError> {
|
||||
let read = Self::read(pointer)?;
|
||||
let (read, pointer) = Self::read(pointer)?;
|
||||
|
||||
let ref_ = Ref::filter_map(read, |any| {
|
||||
// Then try to downcast
|
||||
@@ -295,7 +302,7 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
|
||||
fn try_write(
|
||||
pointer: GenerationalPointer<Self>,
|
||||
) -> Result<Self::Mut<'static, T>, error::BorrowMutError> {
|
||||
let write = Self::write(pointer)?;
|
||||
let (write, pointer) = Self::write(pointer)?;
|
||||
|
||||
let ref_mut = RefMut::filter_map(write, |any| {
|
||||
// Then try to downcast
|
||||
|
||||
Reference in new issue
Block a user