Skip to content

Commit 53e4b83

Browse files
committed
Try dropchk for AsyncProj
1 parent 139adce commit 53e4b83

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![feature(sync_unsafe_cell)]
2929
#![feature(never_type)]
3030
#![feature(layout_for_ptr)]
31+
#![feature(dropck_eyepatch)]
3132
#![feature(cfg_version)]
3233
#![cfg_attr(not(version("1.76.0")), feature(c_str_literals))]
3334
#![cfg_attr(not(version("1.76.0")), feature(ptr_from_ref))]

src/utils/async.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a, 'stream, T: BorrowMut<C::Completed>, C: Completion<T>> Async<'a, 'strea
327327
(
328328
this.stream,
329329
std::ptr::read(&this.value),
330-
(std::ptr::read(&this.status)),
330+
std::ptr::read(&this.status),
331331
)
332332
}
333333
}
@@ -481,6 +481,13 @@ pub struct AsyncProj<'a, 'stream, T: 'a> {
481481
use_callback: Option<Box<dyn FnMut() -> CudaResult<()> + 'a>>,
482482
}
483483

484+
#[cfg(feature = "host")]
485+
unsafe impl<#[may_dangle] 'a, 'stream, T: 'a> Drop for AsyncProj<'a, 'stream, T> {
486+
fn drop(&mut self) {
487+
// no-op
488+
}
489+
}
490+
484491
#[cfg(feature = "host")]
485492
impl<'a, 'stream, T: 'a> AsyncProj<'a, 'stream, T> {
486493
#[must_use]
@@ -511,7 +518,8 @@ impl<'a, 'stream, T: 'a> AsyncProj<'a, 'stream, T> {
511518
/// computation out of smaller ones that have all been submitted to the
512519
/// same [`Stream`].
513520
pub(crate) unsafe fn unwrap_unchecked(self) -> T {
514-
self.value
521+
let (value, _use_callback) = self.unwrap_unchecked_with_use();
522+
value
515523
}
516524

517525
#[allow(clippy::type_complexity)]
@@ -527,7 +535,16 @@ impl<'a, 'stream, T: 'a> AsyncProj<'a, 'stream, T> {
527535
pub(crate) unsafe fn unwrap_unchecked_with_use(
528536
self,
529537
) -> (T, Option<Box<dyn FnMut() -> CudaResult<()> + 'a>>) {
530-
(self.value, self.use_callback)
538+
let this = std::mem::ManuallyDrop::new(self);
539+
540+
// Safety: we destructure self into its droppable components,
541+
// value and use_callback, without dropping self itself
542+
unsafe {
543+
(
544+
std::ptr::read(&this.value),
545+
std::ptr::read(&this.use_callback),
546+
)
547+
}
531548
}
532549
}
533550

0 commit comments

Comments
 (0)