File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -3381,7 +3381,8 @@ impl<T> [T] {
3381
3381
#[ inline]
3382
3382
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
3383
3383
pub fn take_last < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
3384
- self . take ( ( self . len ( ) - 1 ) ..) . map ( |res| & res[ 0 ] )
3384
+ let i = self . len ( ) . checked_sub ( 1 ) ?;
3385
+ self . take ( i..) . map ( |res| & res[ 0 ] )
3385
3386
}
3386
3387
3387
3388
/// Returns a mutable reference to the last element of the slice,
@@ -3404,7 +3405,8 @@ impl<T> [T] {
3404
3405
#[ inline]
3405
3406
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
3406
3407
pub fn take_last_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
3407
- self . take_mut ( ( self . len ( ) - 1 ) ..) . map ( |res| & mut res[ 0 ] )
3408
+ let i = self . len ( ) . checked_sub ( 1 ) ?;
3409
+ self . take_mut ( i..) . map ( |res| & mut res[ 0 ] )
3408
3410
}
3409
3411
}
3410
3412
You can’t perform that action at this time.
0 commit comments