File tree 3 files changed +8
-11
lines changed
3 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -300,7 +300,10 @@ impl<T> LinkedList<T> {
300
300
let tail = self . tail . take ( ) ;
301
301
let len = mem:: replace ( & mut self . len , 0 ) ;
302
302
if let Some ( head) = head {
303
- let tail = tail. unwrap_or_else ( || unsafe { core:: hint:: unreachable_unchecked ( ) } ) ;
303
+ // SAFETY: In a LinkedList, either both the head and tail are None because
304
+ // the list is empty, or both head and tail are Some because the list is populated.
305
+ // Since we have verified the head is Some, we are sure the tail is Some too.
306
+ let tail = unsafe { tail. unwrap_unchecked ( ) } ;
304
307
Some ( ( head, tail, len) )
305
308
} else {
306
309
None
Original file line number Diff line number Diff line change @@ -459,11 +459,8 @@ where
459
459
debug_assert ! ( N <= iter. size_hint( ) . 1 . unwrap_or( usize :: MAX ) ) ;
460
460
debug_assert ! ( N <= iter. size_hint( ) . 0 ) ;
461
461
462
- match collect_into_array ( iter) {
463
- Some ( array) => array,
464
- // SAFETY: covered by the function contract.
465
- None => unsafe { crate :: hint:: unreachable_unchecked ( ) } ,
466
- }
462
+ // SAFETY: covered by the function contract.
463
+ unsafe { collect_into_array ( iter) . unwrap_unchecked ( ) }
467
464
}
468
465
469
466
/// Pulls `N` items from `iter` and returns them as an array. If the iterator
Original file line number Diff line number Diff line change @@ -1198,11 +1198,8 @@ impl<T> Option<T> {
1198
1198
pub fn insert ( & mut self , value : T ) -> & mut T {
1199
1199
* self = Some ( value) ;
1200
1200
1201
- match self {
1202
- Some ( v) => v,
1203
- // SAFETY: the code above just filled the option
1204
- None => unsafe { hint:: unreachable_unchecked ( ) } ,
1205
- }
1201
+ // SAFETY: the code above just filled the option
1202
+ unsafe { self . as_mut ( ) . unwrap_unchecked ( ) }
1206
1203
}
1207
1204
1208
1205
/// Inserts `value` into the option if it is [`None`], then
You can’t perform that action at this time.
0 commit comments