diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-03-26 13:04:06 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-03-26 13:09:36 +0100 |
| commit | 6ca2af6434ec40ae91207628722fe6e731f6f358 (patch) | |
| tree | cc99d09c2841408677e613cea1f544cae37869f7 /compiler/rustc_query_system/src | |
| parent | 6319bb38ccb316b193e35720c9df953e5ab01c22 (diff) | |
| download | rust-6ca2af6434ec40ae91207628722fe6e731f6f358.tar.gz rust-6ca2af6434ec40ae91207628722fe6e731f6f358.zip | |
Use a function to create `QueryStackDeferred` to ensure context is Copy
Diffstat (limited to 'compiler/rustc_query_system/src')
| -rw-r--r-- | compiler/rustc_query_system/src/query/mod.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index d9ee6532831..ef21af7dafb 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -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) } } } |
