File tree 2 files changed +21
-1
lines changed 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ impl Bytes {
401
401
) ;
402
402
403
403
if end == begin {
404
- return Bytes :: new ( ) ;
404
+ return Bytes :: new_empty_with_ptr ( self . ptr . wrapping_add ( begin ) ) ;
405
405
}
406
406
407
407
let mut ret = self . clone ( ) ;
Original file line number Diff line number Diff line change @@ -1421,6 +1421,26 @@ fn try_reclaim_arc() {
1421
1421
assert_eq ! ( true , buf. try_reclaim( 6 ) ) ;
1422
1422
}
1423
1423
1424
+ #[ test]
1425
+ fn slice_empty_addr ( ) {
1426
+ let buf = Bytes :: from ( vec ! [ 0 ; 1024 ] ) ;
1427
+
1428
+ let ptr_start = buf. as_ptr ( ) ;
1429
+ let ptr_end = ptr_start. wrapping_add ( 1024 ) ;
1430
+
1431
+ let empty_end = buf. slice ( 1024 ..) ;
1432
+ assert_eq ! ( empty_end. len( ) , 0 ) ;
1433
+ assert_eq ! ( empty_end. as_ptr( ) , ptr_end) ;
1434
+
1435
+ let empty_start = buf. slice ( ..0 ) ;
1436
+ assert_eq ! ( empty_start. len( ) , 0 ) ;
1437
+ assert_eq ! ( empty_start. as_ptr( ) , ptr_start) ;
1438
+
1439
+ // Is miri happy about the provenance?
1440
+ let _ = & empty_end[ ..] ;
1441
+ let _ = & empty_start[ ..] ;
1442
+ }
1443
+
1424
1444
#[ test]
1425
1445
fn split_off_empty_addr ( ) {
1426
1446
let mut buf = Bytes :: from ( vec ! [ 0 ; 1024 ] ) ;
You can’t perform that action at this time.
0 commit comments