1
Fork 0

Use a function to create QueryStackDeferred to ensure context is Copy

This commit is contained in:
John Kåre Alsaker 2025-03-26 13:04:06 +01:00
parent 6319bb38cc
commit 6ca2af6434
2 changed files with 48 additions and 36 deletions

View file

@ -108,10 +108,14 @@ pub struct QueryStackDeferred<'tcx> {
}
impl<'tcx> QueryStackDeferred<'tcx> {
/// SAFETY: `extract` may not access 'tcx in its destructor.
pub unsafe fn new(
extract: Arc<dyn Fn() -> QueryStackFrameExtra + DynSync + DynSend + 'tcx>,
pub fn new<C: Copy + DynSync + DynSend + 'tcx>(
context: C,
extract: fn(C) -> QueryStackFrameExtra,
) -> Self {
let extract: Arc<dyn Fn() -> QueryStackFrameExtra + DynSync + DynSend + 'tcx> =
Arc::new(move || extract(context));
// SAFETY: The `extract` closure does not access 'tcx in its destructor as the only
// captured variable is `context` which is Copy and cannot have a destructor.
Self { _dummy: PhantomData, extract: unsafe { transmute(extract) } }
}