extract transmute_lifetime into plumbing module

This commit is contained in:
Niko Matsakis 2024-03-14 05:44:15 -04:00
parent 4142ebca97
commit 0543972429
3 changed files with 10 additions and 16 deletions

View file

@ -1,6 +1,7 @@
use crate::cycle::CycleRecoveryStrategy; use crate::cycle::CycleRecoveryStrategy;
use crate::ingredient::{fmt_index, Ingredient, IngredientRequiresReset}; use crate::ingredient::{fmt_index, Ingredient, IngredientRequiresReset};
use crate::key::DependencyIndex; use crate::key::DependencyIndex;
use crate::plumbing::transmute_lifetime;
use crate::runtime::local_state::QueryOrigin; use crate::runtime::local_state::QueryOrigin;
use crate::runtime::StampedValue; use crate::runtime::StampedValue;
use crate::{AsId, DatabaseKeyIndex, Durability, Id, IngredientIndex, Revision, Runtime}; use crate::{AsId, DatabaseKeyIndex, Durability, Id, IngredientIndex, Revision, Runtime};
@ -104,14 +105,6 @@ where
} }
} }
// Returns `u` but with the lifetime of `t`.
//
// Safe if you know that data at `u` will remain shared
// until the reference `t` expires.
unsafe fn transmute_lifetime<'t, 'u, T, U>(_t: &'t T, u: &'u U) -> &'t U {
std::mem::transmute(u)
}
impl<DB: ?Sized, K, F> Ingredient<DB> for InputFieldIngredient<K, F> impl<DB: ?Sized, K, F> Ingredient<DB> for InputFieldIngredient<K, F>
where where
K: AsId, K: AsId,

View file

@ -8,6 +8,7 @@ use crate::durability::Durability;
use crate::id::AsId; use crate::id::AsId;
use crate::ingredient::{fmt_index, IngredientRequiresReset}; use crate::ingredient::{fmt_index, IngredientRequiresReset};
use crate::key::DependencyIndex; use crate::key::DependencyIndex;
use crate::plumbing::transmute_lifetime;
use crate::runtime::local_state::QueryOrigin; use crate::runtime::local_state::QueryOrigin;
use crate::runtime::Runtime; use crate::runtime::Runtime;
use crate::DatabaseKeyIndex; use crate::DatabaseKeyIndex;
@ -181,14 +182,6 @@ where
} }
} }
// Returns `u` but with the lifetime of `t`.
//
// Safe if you know that data at `u` will remain shared
// until the reference `t` expires.
unsafe fn transmute_lifetime<'t, 'u, T, U>(_t: &'t T, u: &'u U) -> &'t U {
std::mem::transmute(u)
}
impl<DB: ?Sized, Id, Data> Ingredient<DB> for InternedIngredient<Id, Data> impl<DB: ?Sized, Id, Data> Ingredient<DB> for InternedIngredient<Id, Data>
where where
Id: InternedId, Id: InternedId,

View file

@ -26,3 +26,11 @@ pub unsafe fn create_jars_inplace<DB: HasJars>(init: impl FnOnce(*mut DB::Jars))
unsafe { Box::from_raw(place) } unsafe { Box::from_raw(place) }
} }
} }
// Returns `u` but with the lifetime of `t`.
//
// Safe if you know that data at `u` will remain shared
// until the reference `t` expires.
pub(crate) unsafe fn transmute_lifetime<'t, 'u, T, U>(_t: &'t T, u: &'u U) -> &'t U {
std::mem::transmute(u)
}