File tree 1 file changed +4
-2
lines changed
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -3271,7 +3271,8 @@ impl<T> [T] {
3271
3271
#[ inline]
3272
3272
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
3273
3273
pub fn take_last < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
3274
- self . take ( ( self . len ( ) - 1 ) ..) . map ( |res| & res[ 0 ] )
3274
+ let i = self . len ( ) . checked_sub ( 1 ) ?;
3275
+ self . take ( i..) . map ( |res| & res[ 0 ] )
3275
3276
}
3276
3277
3277
3278
/// Returns a mutable reference to the last element of the slice,
@@ -3294,7 +3295,8 @@ impl<T> [T] {
3294
3295
#[ inline]
3295
3296
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
3296
3297
pub fn take_last_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
3297
- self . take_mut ( ( self . len ( ) - 1 ) ..) . map ( |res| & mut res[ 0 ] )
3298
+ let i = self . len ( ) . checked_sub ( 1 ) ?;
3299
+ self . take_mut ( i..) . map ( |res| & mut res[ 0 ] )
3298
3300
}
3299
3301
}
3300
3302
You can’t perform that action at this time.
0 commit comments