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> {
314314 /// whole number of elements. Such as `3` x [`u16`] -> `1.5` x [`u32`].
315315 /// - If either type is a ZST (but not both).
316316 #[ 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 > {
318318 if align_of :: < B > ( ) > align_of :: < A > ( ) && ( self . buf . as_raw ( ) as usize ) % align_of :: < B > ( ) != 0
319319 {
320320 Err ( PodCastError :: TargetAlignmentGreaterAndInputNotAligned )
@@ -325,10 +325,12 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
325325 Err ( PodCastError :: SizeMismatch )
326326 } else if ( size_of :: < A > ( ) * self . len ) % size_of :: < B > ( ) == 0 {
327327 let new_len = ( size_of :: < A > ( ) * self . len ) / size_of :: < B > ( ) ;
328- Ok ( DeviceBuffer {
328+ let ret = Ok ( DeviceBuffer {
329329 buf : self . buf . cast ( ) ,
330330 len : new_len,
331- } )
331+ } ) ;
332+ unsafe { std:: mem:: forget ( self ) ; }
333+ ret
332334 } else {
333335 Err ( PodCastError :: OutputSliceWouldHaveSlop )
334336 }
You can’t perform that action at this time.
0 commit comments