@@ -204,29 +204,29 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment>
204204 /// The addition must not overflow.
205205 pub ( crate ) unsafe fn unchecked_add_zero ( & self , count : usize ) -> Self {
206206 match NonZero :: new ( count) {
207- None => self . clone ( ) ,
207+ None => * self ,
208208 // SAFETY: the caller ensures that the addition does not overflow
209209 Some ( non_zero_count) => unsafe { self . unchecked_add ( non_zero_count) } ,
210210 }
211211 }
212212
213213 pub fn checked_add_zero ( & self , count : usize ) -> Result < Self , ( ) > {
214214 match NonZero :: new ( count) {
215- None => Ok ( self . clone ( ) ) ,
215+ None => Ok ( * self ) ,
216216 Some ( non_zero_count) => self . checked_add ( non_zero_count) ,
217217 }
218218 }
219219
220220 pub fn checked_sub_zero ( & self , count : usize ) -> Result < Self , ( ) > {
221221 match NonZero :: new ( count) {
222- None => Ok ( self . clone ( ) ) ,
222+ None => Ok ( * self ) ,
223223 Some ( non_zero_count) => self . checked_add ( non_zero_count) ,
224224 }
225225 }
226226
227227 pub fn checked_offset_zero ( & self , count : isize ) -> Result < Self , ( ) > {
228228 match NonZero :: new ( count) {
229- None => Ok ( self . clone ( ) ) ,
229+ None => Ok ( * self ) ,
230230 Some ( non_zero_count) => self . checked_offset ( non_zero_count) ,
231231 }
232232 }
@@ -323,10 +323,7 @@ impl<const IS_VIRTUAL: bool, T: Alignment> ImmutablePointer<IS_VIRTUAL, T> {
323323 ///
324324 /// The caller must ensure that `pointer` is of right type.
325325 pub ( crate ) unsafe fn new_raw ( pointer : * const T ) -> Result < Self , Error > {
326- let pointer = match ImmutablePtr :: new ( pointer) {
327- Err ( error) => return Err ( error) ,
328- Ok ( pointer) => pointer,
329- } ;
326+ let pointer = ImmutablePtr :: new ( pointer) ?;
330327
331328 // SAFETY: The caller ensures that `pointer` is of the right type
332329 let pointer = unsafe { Self :: new ( pointer) } ;
@@ -337,7 +334,7 @@ impl<const IS_VIRTUAL: bool, T: Alignment> ImmutablePointer<IS_VIRTUAL, T> {
337334 /// # Safety
338335 ///
339336 /// The caller must ensure that `reference` is of right type.
340- pub unsafe fn new_from_ref < ' a > ( reference : & ' a T ) -> Self {
337+ pub unsafe fn new_from_ref ( reference : & T ) -> Self {
341338 let immutable_pointer = ImmutablePtr :: new_from_ref ( reference) ;
342339 // SAFETY: The caller ensures that `reference` is of the right type
343340 unsafe { Self :: new ( immutable_pointer) }
@@ -382,10 +379,7 @@ impl<const IS_VIRTUAL: bool, T: Alignment> MutablePointer<IS_VIRTUAL, T> {
382379 ///
383380 /// The caller must ensure that `pointer` is of right type.
384381 pub unsafe fn new_raw ( pointer : * mut T ) -> Result < Self , Error > {
385- let pointer = match MutablePtr :: new ( pointer) {
386- Err ( error) => return Err ( error) ,
387- Ok ( pointer) => pointer,
388- } ;
382+ let pointer = MutablePtr :: new ( pointer) ?;
389383
390384 // SAFETY: The caller ensures that `pointer` is of the right type
391385 let pointer = unsafe { Self :: new ( pointer) } ;
@@ -448,7 +442,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> PartialOrd
448442 for Pointer < IS_VIRTUAL , IS_MUTABLE , T >
449443{
450444 fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
451- self . as_inner ( ) . partial_cmp ( other. as_inner ( ) )
445+ Some ( self . cmp ( other) )
452446 }
453447}
454448
@@ -460,8 +454,8 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Ord
460454 }
461455}
462456
463- impl < ' a , const IS_VIRTUAL : bool , const IS_MUTABLE : bool , T : Alignment > Sub
464- for & ' a Pointer < IS_VIRTUAL , IS_MUTABLE , T >
457+ impl < const IS_VIRTUAL : bool , const IS_MUTABLE : bool , T : Alignment > Sub
458+ for & Pointer < IS_VIRTUAL , IS_MUTABLE , T >
465459{
466460 type Output = isize ;
467461
@@ -482,9 +476,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Clone
482476 for Pointer < IS_VIRTUAL , IS_MUTABLE , T >
483477{
484478 fn clone ( & self ) -> Self {
485- let inner = self . as_inner ( ) ;
486- // SAFETY: `inner` comes from `self`
487- unsafe { Self :: new ( inner. clone ( ) ) }
479+ * self
488480 }
489481}
490482
@@ -520,10 +512,10 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment>
520512 unsafe { & * core:: ptr:: from_ref ( self ) . cast ( ) }
521513 }
522514
523- pub ( crate ) fn to_immutable ( & self ) -> ValidImmutableVirtualPointer < IS_USER , T > {
515+ pub ( crate ) fn to_immutable ( self ) -> ValidImmutableVirtualPointer < IS_USER , T > {
524516 // SAFETY: `ValidVirtualPointer` is marked #[repr(transparent)], so it has the same memory
525517 // representation for both immutable and mutable counter parts.
526- unsafe { * core:: ptr:: from_ref ( self ) . cast ( ) }
518+ unsafe { * core:: ptr:: from_ref ( & self ) . cast ( ) }
527519 }
528520
529521 pub fn to_nullable ( self ) -> ValidNullableVirtualPointer < IS_USER , IS_MUTABLE , T > {
@@ -578,7 +570,7 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment>
578570 /// The addition must not overflow.
579571 pub ( crate ) unsafe fn unchecked_add_zero ( & self , count : usize ) -> Self {
580572 match NonZero :: new ( count) {
581- None => self . clone ( ) ,
573+ None => * self ,
582574 // SAFETY: the caller ensures that the addition does not overflow
583575 Some ( non_zero_count) => unsafe { self . unchecked_add ( non_zero_count) } ,
584576 }
@@ -667,7 +659,7 @@ impl<const IS_USER: bool, T: Alignment> ValidImmutableVirtualPointer<IS_USER, T>
667659 ///
668660 /// 1. User virtual reference if IS_USER == true
669661 /// 2. Kernel virtual reference if IS_USER == false
670- pub unsafe fn new_from_ref < ' a > ( reference : & ' a T ) -> Self {
662+ pub unsafe fn new_from_ref ( reference : & T ) -> Self {
671663 let virtual_pointer = ImmutableVirtualPointer :: new_from_ref ( reference) ;
672664 // SAFETY: The caller ensures that `reference` is of the right type
673665 unsafe { Self :: new ( virtual_pointer) }
@@ -816,8 +808,8 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment> Ord
816808 }
817809}
818810
819- impl < ' a , const IS_USER : bool , const IS_MUTABLE : bool , T : Alignment > Sub
820- for & ' a ValidVirtualPointer < IS_USER , IS_MUTABLE , T >
811+ impl < const IS_USER : bool , const IS_MUTABLE : bool , T : Alignment > Sub
812+ for & ValidVirtualPointer < IS_USER , IS_MUTABLE , T >
821813{
822814 type Output = isize ;
823815
@@ -838,9 +830,7 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment> Clone
838830 for ValidVirtualPointer < IS_USER , IS_MUTABLE , T >
839831{
840832 fn clone ( & self ) -> Self {
841- let inner = self . as_virtual_pointer ( ) ;
842- // SAFETY: `inner` comes from `self`
843- unsafe { Self :: new ( inner. clone ( ) ) }
833+ * self
844834 }
845835}
846836
@@ -938,10 +928,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Clone
938928 for NullablePointer < IS_VIRTUAL , IS_MUTABLE , T >
939929{
940930 fn clone ( & self ) -> Self {
941- match self {
942- NullablePointer :: Null => NullablePointer :: Null ,
943- NullablePointer :: NonNull ( pointer) => NullablePointer :: NonNull ( pointer. clone ( ) ) ,
944- }
931+ * self
945932 }
946933}
947934
0 commit comments