File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
crates/cust/src/memory/device Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,7 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
314
314
/// whole number of elements. Such as `3` x [`u16`] -> `1.5` x [`u32`].
315
315
/// - If either type is a ZST (but not both).
316
316
#[ cfg_attr( docsrs, doc( cfg( feature = "bytemuck" ) ) ) ]
317
- pub fn try_cast < B : Pod + DeviceCopy > ( self ) -> Result < DeviceBuffer < B > , PodCastError > {
317
+ pub fn try_cast < B : Pod + DeviceCopy > ( mut self ) -> Result < DeviceBuffer < B > , PodCastError > {
318
318
if align_of :: < B > ( ) > align_of :: < A > ( ) && ( self . buf . as_raw ( ) as usize ) % align_of :: < B > ( ) != 0
319
319
{
320
320
Err ( PodCastError :: TargetAlignmentGreaterAndInputNotAligned )
@@ -325,10 +325,12 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
325
325
Err ( PodCastError :: SizeMismatch )
326
326
} else if ( size_of :: < A > ( ) * self . len ) % size_of :: < B > ( ) == 0 {
327
327
let new_len = ( size_of :: < A > ( ) * self . len ) / size_of :: < B > ( ) ;
328
- Ok ( DeviceBuffer {
328
+ let ret = Ok ( DeviceBuffer {
329
329
buf : self . buf . cast ( ) ,
330
330
len : new_len,
331
- } )
331
+ } ) ;
332
+ unsafe { std:: mem:: forget ( self ) ; }
333
+ ret
332
334
} else {
333
335
Err ( PodCastError :: OutputSliceWouldHaveSlop )
334
336
}
You can’t perform that action at this time.
0 commit comments