Use a function to create QueryStackDeferred
to ensure context is Copy
This commit is contained in:
parent
6319bb38cc
commit
6ca2af6434
2 changed files with 48 additions and 36 deletions
|
@ -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) } }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue