@@ -292,6 +292,7 @@ struct RcBox<T: ?Sized> {
292
292
}
293
293
294
294
/// Calculate layout for `RcBox<T>` using the inner value's layout
295
+ #[ inline]
295
296
fn rcbox_layout_for_value_layout ( layout : Layout ) -> Layout {
296
297
// Calculate layout using the given value layout.
297
298
// Previously, layout was calculated on the expression
@@ -385,6 +386,7 @@ impl<T> Rc<T> {
385
386
///
386
387
/// let five = Rc::new(5);
387
388
/// ```
389
+ #[ inline]
388
390
#[ cfg( not( no_global_oom_handling) ) ]
389
391
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
390
392
pub fn new ( value : T ) -> Rc < T > {
@@ -514,9 +516,10 @@ impl<T> Rc<T> {
514
516
///
515
517
/// assert_eq!(*five, 5)
516
518
/// ```
519
+ #[ inline]
520
+ #[ must_use]
517
521
#[ cfg( not( no_global_oom_handling) ) ]
518
522
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
519
- #[ must_use]
520
523
pub fn new_uninit ( ) -> Rc < mem:: MaybeUninit < T > > {
521
524
unsafe {
522
525
Rc :: from_ptr ( Rc :: allocate_for_layout (
@@ -547,9 +550,10 @@ impl<T> Rc<T> {
547
550
/// ```
548
551
///
549
552
/// [zeroed]: mem::MaybeUninit::zeroed
553
+ #[ inline]
554
+ #[ must_use]
550
555
#[ cfg( not( no_global_oom_handling) ) ]
551
556
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
552
- #[ must_use]
553
557
pub fn new_zeroed ( ) -> Rc < mem:: MaybeUninit < T > > {
554
558
unsafe {
555
559
Rc :: from_ptr ( Rc :: allocate_for_layout (
@@ -571,6 +575,7 @@ impl<T> Rc<T> {
571
575
/// let five = Rc::try_new(5);
572
576
/// # Ok::<(), std::alloc::AllocError>(())
573
577
/// ```
578
+ #[ inline]
574
579
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
575
580
pub fn try_new ( value : T ) -> Result < Rc < T > , AllocError > {
576
581
// There is an implicit weak pointer owned by all the strong
@@ -605,6 +610,7 @@ impl<T> Rc<T> {
605
610
/// assert_eq!(*five, 5);
606
611
/// # Ok::<(), std::alloc::AllocError>(())
607
612
/// ```
613
+ #[ inline]
608
614
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
609
615
// #[unstable(feature = "new_uninit", issue = "63291")]
610
616
pub fn try_new_uninit ( ) -> Result < Rc < mem:: MaybeUninit < T > > , AllocError > {
@@ -638,6 +644,7 @@ impl<T> Rc<T> {
638
644
/// ```
639
645
///
640
646
/// [zeroed]: mem::MaybeUninit::zeroed
647
+ #[ inline]
641
648
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
642
649
//#[unstable(feature = "new_uninit", issue = "63291")]
643
650
pub fn try_new_zeroed ( ) -> Result < Rc < mem:: MaybeUninit < T > > , AllocError > {
@@ -651,9 +658,10 @@ impl<T> Rc<T> {
651
658
}
652
659
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
653
660
/// `value` will be pinned in memory and unable to be moved.
661
+ #[ inline]
662
+ #[ must_use]
654
663
#[ cfg( not( no_global_oom_handling) ) ]
655
664
#[ stable( feature = "pin" , since = "1.33.0" ) ]
656
- #[ must_use]
657
665
pub fn pin ( value : T ) -> Pin < Rc < T > > {
658
666
unsafe { Pin :: new_unchecked ( Rc :: new ( value) ) }
659
667
}
@@ -681,9 +689,9 @@ impl<T, A: Allocator> Rc<T, A> {
681
689
///
682
690
/// let five = Rc::new_in(5, System);
683
691
/// ```
692
+ #[ inline]
684
693
#[ cfg( not( no_global_oom_handling) ) ]
685
694
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
686
- #[ inline]
687
695
pub fn new_in ( value : T , alloc : A ) -> Rc < T , A > {
688
696
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
689
697
// That would make code size bigger.
@@ -716,10 +724,10 @@ impl<T, A: Allocator> Rc<T, A> {
716
724
///
717
725
/// assert_eq!(*five, 5)
718
726
/// ```
727
+ #[ inline]
719
728
#[ cfg( not( no_global_oom_handling) ) ]
720
729
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
721
730
// #[unstable(feature = "new_uninit", issue = "63291")]
722
- #[ inline]
723
731
pub fn new_uninit_in ( alloc : A ) -> Rc < mem:: MaybeUninit < T > , A > {
724
732
unsafe {
725
733
Rc :: from_ptr_in (
@@ -755,10 +763,10 @@ impl<T, A: Allocator> Rc<T, A> {
755
763
/// ```
756
764
///
757
765
/// [zeroed]: mem::MaybeUninit::zeroed
766
+ #[ inline]
758
767
#[ cfg( not( no_global_oom_handling) ) ]
759
768
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
760
769
// #[unstable(feature = "new_uninit", issue = "63291")]
761
- #[ inline]
762
770
pub fn new_zeroed_in ( alloc : A ) -> Rc < mem:: MaybeUninit < T > , A > {
763
771
unsafe {
764
772
Rc :: from_ptr_in (
@@ -785,8 +793,8 @@ impl<T, A: Allocator> Rc<T, A> {
785
793
/// let five = Rc::try_new_in(5, System);
786
794
/// # Ok::<(), std::alloc::AllocError>(())
787
795
/// ```
788
- #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
789
796
#[ inline]
797
+ #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
790
798
pub fn try_new_in ( value : T , alloc : A ) -> Result < Self , AllocError > {
791
799
// There is an implicit weak pointer owned by all the strong
792
800
// pointers, which ensures that the weak destructor never frees
@@ -823,9 +831,9 @@ impl<T, A: Allocator> Rc<T, A> {
823
831
/// assert_eq!(*five, 5);
824
832
/// # Ok::<(), std::alloc::AllocError>(())
825
833
/// ```
834
+ #[ inline]
826
835
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
827
836
// #[unstable(feature = "new_uninit", issue = "63291")]
828
- #[ inline]
829
837
pub fn try_new_uninit_in ( alloc : A ) -> Result < Rc < mem:: MaybeUninit < T > , A > , AllocError > {
830
838
unsafe {
831
839
Ok ( Rc :: from_ptr_in (
@@ -862,9 +870,9 @@ impl<T, A: Allocator> Rc<T, A> {
862
870
/// ```
863
871
///
864
872
/// [zeroed]: mem::MaybeUninit::zeroed
873
+ #[ inline]
865
874
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
866
875
//#[unstable(feature = "new_uninit", issue = "63291")]
867
- #[ inline]
868
876
pub fn try_new_zeroed_in ( alloc : A ) -> Result < Rc < mem:: MaybeUninit < T > , A > , AllocError > {
869
877
unsafe {
870
878
Ok ( Rc :: from_ptr_in (
@@ -880,9 +888,9 @@ impl<T, A: Allocator> Rc<T, A> {
880
888
881
889
/// Constructs a new `Pin<Rc<T>>` in the provided allocator. If `T` does not implement `Unpin`, then
882
890
/// `value` will be pinned in memory and unable to be moved.
891
+ #[ inline]
883
892
#[ cfg( not( no_global_oom_handling) ) ]
884
893
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
885
- #[ inline]
886
894
pub fn pin_in ( value : T , alloc : A ) -> Pin < Self > {
887
895
unsafe { Pin :: new_unchecked ( Rc :: new_in ( value, alloc) ) }
888
896
}
@@ -970,9 +978,10 @@ impl<T> Rc<[T]> {
970
978
///
971
979
/// assert_eq!(*values, [1, 2, 3])
972
980
/// ```
981
+ #[ inline]
982
+ #[ must_use]
973
983
#[ cfg( not( no_global_oom_handling) ) ]
974
984
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
975
- #[ must_use]
976
985
pub fn new_uninit_slice ( len : usize ) -> Rc < [ mem:: MaybeUninit < T > ] > {
977
986
unsafe { Rc :: from_ptr ( Rc :: allocate_for_slice ( len) ) }
978
987
}
@@ -997,9 +1006,10 @@ impl<T> Rc<[T]> {
997
1006
/// ```
998
1007
///
999
1008
/// [zeroed]: mem::MaybeUninit::zeroed
1009
+ #[ inline]
1010
+ #[ must_use]
1000
1011
#[ cfg( not( no_global_oom_handling) ) ]
1001
1012
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1002
- #[ must_use]
1003
1013
pub fn new_zeroed_slice ( len : usize ) -> Rc < [ mem:: MaybeUninit < T > ] > {
1004
1014
unsafe {
1005
1015
Rc :: from_ptr ( Rc :: allocate_for_layout (
@@ -1040,10 +1050,10 @@ impl<T, A: Allocator> Rc<[T], A> {
1040
1050
///
1041
1051
/// assert_eq!(*values, [1, 2, 3])
1042
1052
/// ```
1053
+ #[ inline]
1043
1054
#[ cfg( not( no_global_oom_handling) ) ]
1044
1055
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
1045
1056
// #[unstable(feature = "new_uninit", issue = "63291")]
1046
- #[ inline]
1047
1057
pub fn new_uninit_slice_in ( len : usize , alloc : A ) -> Rc < [ mem:: MaybeUninit < T > ] , A > {
1048
1058
unsafe { Rc :: from_ptr_in ( Rc :: allocate_for_slice_in ( len, & alloc) , alloc) }
1049
1059
}
@@ -1070,10 +1080,10 @@ impl<T, A: Allocator> Rc<[T], A> {
1070
1080
/// ```
1071
1081
///
1072
1082
/// [zeroed]: mem::MaybeUninit::zeroed
1083
+ #[ inline]
1073
1084
#[ cfg( not( no_global_oom_handling) ) ]
1074
1085
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
1075
1086
// #[unstable(feature = "new_uninit", issue = "63291")]
1076
- #[ inline]
1077
1087
pub fn new_zeroed_slice_in ( len : usize , alloc : A ) -> Rc < [ mem:: MaybeUninit < T > ] , A > {
1078
1088
unsafe {
1079
1089
Rc :: from_ptr_in (
@@ -1121,8 +1131,8 @@ impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
1121
1131
///
1122
1132
/// assert_eq!(*five, 5)
1123
1133
/// ```
1124
- #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1125
1134
#[ inline]
1135
+ #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1126
1136
pub unsafe fn assume_init ( self ) -> Rc < T , A >
1127
1137
where
1128
1138
A : Clone ,
@@ -1165,8 +1175,8 @@ impl<T, A: Allocator> Rc<[mem::MaybeUninit<T>], A> {
1165
1175
///
1166
1176
/// assert_eq!(*values, [1, 2, 3])
1167
1177
/// ```
1168
- #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1169
1178
#[ inline]
1179
+ #[ unstable( feature = "new_uninit" , issue = "63291" ) ]
1170
1180
pub unsafe fn assume_init ( self ) -> Rc < [ T ] , A >
1171
1181
where
1172
1182
A : Clone ,
@@ -1303,6 +1313,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1303
1313
/// let x_ptr = Rc::into_raw(x);
1304
1314
/// assert_eq!(unsafe { &*x_ptr }, "hello");
1305
1315
/// ```
1316
+ #[ inline]
1306
1317
#[ stable( feature = "rc_raw" , since = "1.17.0" ) ]
1307
1318
pub fn into_raw ( this : Self ) -> * const T {
1308
1319
let ptr = Self :: as_ptr ( & this) ;
@@ -1326,6 +1337,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1326
1337
/// assert_eq!(x_ptr, Rc::as_ptr(&y));
1327
1338
/// assert_eq!(unsafe { &*x_ptr }, "hello");
1328
1339
/// ```
1340
+ #[ inline]
1329
1341
#[ stable( feature = "weak_into_raw" , since = "1.45.0" ) ]
1330
1342
pub fn as_ptr ( this : & Self ) -> * const T {
1331
1343
let ptr: * mut RcBox < T > = NonNull :: as_ptr ( this. ptr ) ;
@@ -1352,7 +1364,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1352
1364
/// dropped once.
1353
1365
///
1354
1366
/// This function is unsafe because improper use may lead to memory unsafety,
1355
- /// even if the returned `Rc<T>` is never accessed.
1367
+ /// even if the returned `Rc<T>` is never accessed. The pointer must point to
1368
+ /// a region of memory allocated by `alloc`.
1356
1369
///
1357
1370
/// [into_raw]: Rc::into_raw
1358
1371
///
@@ -1377,6 +1390,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1377
1390
///
1378
1391
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
1379
1392
/// ```
1393
+ #[ inline]
1380
1394
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
1381
1395
pub unsafe fn from_raw_in ( ptr : * const T , alloc : A ) -> Self {
1382
1396
let offset = unsafe { data_offset ( ptr) } ;
@@ -1398,6 +1412,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1398
1412
///
1399
1413
/// let weak_five = Rc::downgrade(&five);
1400
1414
/// ```
1415
+ #[ inline]
1401
1416
#[ must_use = "this returns a new `Weak` pointer, \
1402
1417
without modifying the original `Rc`"]
1403
1418
#[ stable( feature = "rc_weak" , since = "1.4.0" ) ]
@@ -1629,8 +1644,6 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1629
1644
unsafe { & mut ( * this. ptr . as_ptr ( ) ) . value }
1630
1645
}
1631
1646
1632
- #[ inline]
1633
- #[ stable( feature = "ptr_eq" , since = "1.17.0" ) ]
1634
1647
/// Returns `true` if the two `Rc`s point to the same allocation in a vein similar to
1635
1648
/// [`ptr::eq`]. This function ignores the metadata of `dyn Trait` pointers.
1636
1649
///
@@ -1646,6 +1659,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1646
1659
/// assert!(Rc::ptr_eq(&five, &same_five));
1647
1660
/// assert!(!Rc::ptr_eq(&five, &other_five));
1648
1661
/// ```
1662
+ #[ inline]
1663
+ #[ stable( feature = "ptr_eq" , since = "1.17.0" ) ]
1649
1664
pub fn ptr_eq ( this : & Self , other : & Self ) -> bool {
1650
1665
this. ptr . as_ptr ( ) as * const ( ) == other. ptr . as_ptr ( ) as * const ( )
1651
1666
}
@@ -1702,8 +1717,8 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {
1702
1717
/// assert!(76 == *data);
1703
1718
/// assert!(weak.upgrade().is_none());
1704
1719
/// ```
1705
- #[ cfg( not( no_global_oom_handling) ) ]
1706
1720
#[ inline]
1721
+ #[ cfg( not( no_global_oom_handling) ) ]
1707
1722
#[ stable( feature = "rc_unique" , since = "1.4.0" ) ]
1708
1723
pub fn make_mut ( this : & mut Self ) -> & mut T {
1709
1724
if Rc :: strong_count ( this) != 1 {
@@ -1851,6 +1866,7 @@ impl<T: ?Sized> Rc<T> {
1851
1866
///
1852
1867
/// The function `mem_to_rcbox` is called with the data pointer
1853
1868
/// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
1869
+ #[ inline]
1854
1870
#[ cfg( not( no_global_oom_handling) ) ]
1855
1871
unsafe fn allocate_for_layout (
1856
1872
value_layout : Layout ,
@@ -2275,7 +2291,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
2275
2291
///
2276
2292
/// assert!(five < Rc::new(6));
2277
2293
/// ```
2278
- #[ inline( always ) ]
2294
+ #[ inline]
2279
2295
fn lt ( & self , other : & Rc < T , A > ) -> bool {
2280
2296
* * self < * * other
2281
2297
}
@@ -2293,7 +2309,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
2293
2309
///
2294
2310
/// assert!(five <= Rc::new(5));
2295
2311
/// ```
2296
- #[ inline( always ) ]
2312
+ #[ inline]
2297
2313
fn le ( & self , other : & Rc < T , A > ) -> bool {
2298
2314
* * self <= * * other
2299
2315
}
@@ -2311,7 +2327,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
2311
2327
///
2312
2328
/// assert!(five > Rc::new(4));
2313
2329
/// ```
2314
- #[ inline( always ) ]
2330
+ #[ inline]
2315
2331
fn gt ( & self , other : & Rc < T , A > ) -> bool {
2316
2332
* * self > * * other
2317
2333
}
@@ -2329,7 +2345,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
2329
2345
///
2330
2346
/// assert!(five >= Rc::new(5));
2331
2347
/// ```
2332
- #[ inline( always ) ]
2348
+ #[ inline]
2333
2349
fn ge ( & self , other : & Rc < T , A > ) -> bool {
2334
2350
* * self >= * * other
2335
2351
}
@@ -2718,9 +2734,9 @@ impl<T> Weak<T> {
2718
2734
/// assert!(empty.upgrade().is_none());
2719
2735
/// ```
2720
2736
#[ inline]
2737
+ #[ must_use]
2721
2738
#[ stable( feature = "downgraded_weak" , since = "1.10.0" ) ]
2722
2739
#[ rustc_const_stable( feature = "const_weak_new" , since = "CURRENT_RUSTC_VERSION" ) ]
2723
- #[ must_use]
2724
2740
pub const fn new ( ) -> Weak < T > {
2725
2741
Weak {
2726
2742
ptr : unsafe { NonNull :: new_unchecked ( ptr:: invalid_mut :: < RcBox < T > > ( usize:: MAX ) ) } ,
@@ -2841,6 +2857,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
2841
2857
/// ```
2842
2858
///
2843
2859
/// [`null`]: ptr::null
2860
+ #[ inline]
2844
2861
#[ must_use]
2845
2862
#[ stable( feature = "rc_as_ptr" , since = "1.45.0" ) ]
2846
2863
pub fn as_ptr ( & self ) -> * const T {
@@ -2885,6 +2902,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
2885
2902
///
2886
2903
/// [`from_raw`]: Weak::from_raw
2887
2904
/// [`as_ptr`]: Weak::as_ptr
2905
+ #[ inline]
2888
2906
#[ must_use = "`self` will be dropped if the result is not used" ]
2889
2907
#[ stable( feature = "weak_into_raw" , since = "1.45.0" ) ]
2890
2908
pub fn into_raw ( self ) -> * const T {
@@ -3018,6 +3036,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
3018
3036
///
3019
3037
/// assert!(weak_five.upgrade().is_none());
3020
3038
/// ```
3039
+ #[ inline]
3021
3040
#[ must_use = "this returns a new `Rc`, \
3022
3041
without modifying the original weak pointer"]
3023
3042
#[ stable( feature = "rc_weak" , since = "1.4.0" ) ]
0 commit comments