@@ -48,13 +48,13 @@ pub use crate::gc::{stats, GcStats};
48
48
/// A garbage-collected pointer type over an immutable value.
49
49
///
50
50
/// See the [module level documentation](./) for more details.
51
- pub struct Gc < T : Trace + ?Sized + ' static > {
51
+ pub struct Gc < T : ?Sized + ' static > {
52
52
ptr_root : Cell < NonNull < GcBox < T > > > ,
53
53
marker : PhantomData < Rc < T > > ,
54
54
}
55
55
56
56
#[ cfg( feature = "nightly" ) ]
57
- impl < T : Trace + ?Sized + Unsize < U > , U : Trace + ?Sized > CoerceUnsized < Gc < U > > for Gc < T > { }
57
+ impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Gc < U > > for Gc < T > { }
58
58
59
59
impl < T : Trace > Gc < T > {
60
60
/// Constructs a new `Gc<T>` with the given value.
@@ -99,23 +99,23 @@ impl<T: Trace + ?Sized> Gc<T> {
99
99
}
100
100
}
101
101
102
- impl < T : Trace + ?Sized > Gc < T > {
102
+ impl < T : ?Sized > Gc < T > {
103
103
/// Returns `true` if the two `Gc`s point to the same allocation.
104
104
pub fn ptr_eq ( this : & Gc < T > , other : & Gc < T > ) -> bool {
105
105
GcBox :: ptr_eq ( this. inner ( ) , other. inner ( ) )
106
106
}
107
107
}
108
108
109
109
/// Returns the given pointer with its root bit cleared.
110
- unsafe fn clear_root_bit < T : ?Sized + Trace > ( ptr : NonNull < GcBox < T > > ) -> NonNull < GcBox < T > > {
110
+ unsafe fn clear_root_bit < T : ?Sized > ( ptr : NonNull < GcBox < T > > ) -> NonNull < GcBox < T > > {
111
111
let ptr = ptr. as_ptr ( ) ;
112
112
let data = ptr. cast :: < u8 > ( ) ;
113
113
let addr = data as isize ;
114
114
let ptr = set_data_ptr ( ptr, data. wrapping_offset ( ( addr & !1 ) - addr) ) ;
115
115
NonNull :: new_unchecked ( ptr)
116
116
}
117
117
118
- impl < T : Trace + ?Sized > Gc < T > {
118
+ impl < T : ?Sized > Gc < T > {
119
119
fn rooted ( & self ) -> bool {
120
120
self . ptr_root . get ( ) . as_ptr ( ) . cast :: < u8 > ( ) as usize & 1 != 0
121
121
}
@@ -151,7 +151,7 @@ impl<T: Trace + ?Sized> Gc<T> {
151
151
}
152
152
}
153
153
154
- impl < T : Trace + ?Sized > Gc < T > {
154
+ impl < T : ?Sized > Gc < T > {
155
155
/// Consumes the `Gc`, returning the wrapped pointer.
156
156
///
157
157
/// To avoid a memory leak, the pointer must be converted back into a `Gc`
@@ -225,7 +225,7 @@ impl<T: Trace + ?Sized> Gc<T> {
225
225
}
226
226
}
227
227
228
- impl < T : Trace + ?Sized > Finalize for Gc < T > { }
228
+ impl < T : ?Sized > Finalize for Gc < T > { }
229
229
230
230
unsafe impl < T : Trace + ?Sized > Trace for Gc < T > {
231
231
#[ inline]
@@ -263,7 +263,7 @@ unsafe impl<T: Trace + ?Sized> Trace for Gc<T> {
263
263
}
264
264
}
265
265
266
- impl < T : Trace + ?Sized > Clone for Gc < T > {
266
+ impl < T : ?Sized > Clone for Gc < T > {
267
267
#[ inline]
268
268
fn clone ( & self ) -> Self {
269
269
unsafe {
@@ -278,7 +278,7 @@ impl<T: Trace + ?Sized> Clone for Gc<T> {
278
278
}
279
279
}
280
280
281
- impl < T : Trace + ?Sized > Deref for Gc < T > {
281
+ impl < T : ?Sized > Deref for Gc < T > {
282
282
type Target = T ;
283
283
284
284
#[ inline]
@@ -287,7 +287,7 @@ impl<T: Trace + ?Sized> Deref for Gc<T> {
287
287
}
288
288
}
289
289
290
- impl < T : Trace + ?Sized > Drop for Gc < T > {
290
+ impl < T : ?Sized > Drop for Gc < T > {
291
291
#[ inline]
292
292
fn drop ( & mut self ) {
293
293
// If this pointer was a root, we should unroot it.
@@ -306,16 +306,16 @@ impl<T: Trace + Default> Default for Gc<T> {
306
306
}
307
307
}
308
308
309
- impl < T : Trace + ?Sized + PartialEq > PartialEq for Gc < T > {
309
+ impl < T : ?Sized + PartialEq > PartialEq for Gc < T > {
310
310
#[ inline( always) ]
311
311
fn eq ( & self , other : & Self ) -> bool {
312
312
* * self == * * other
313
313
}
314
314
}
315
315
316
- impl < T : Trace + ?Sized + Eq > Eq for Gc < T > { }
316
+ impl < T : ?Sized + Eq > Eq for Gc < T > { }
317
317
318
- impl < T : Trace + ?Sized + PartialOrd > PartialOrd for Gc < T > {
318
+ impl < T : ?Sized + PartialOrd > PartialOrd for Gc < T > {
319
319
#[ inline( always) ]
320
320
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
321
321
( * * self ) . partial_cmp ( & * * other)
@@ -342,32 +342,32 @@ impl<T: Trace + ?Sized + PartialOrd> PartialOrd for Gc<T> {
342
342
}
343
343
}
344
344
345
- impl < T : Trace + ?Sized + Ord > Ord for Gc < T > {
345
+ impl < T : ?Sized + Ord > Ord for Gc < T > {
346
346
#[ inline]
347
347
fn cmp ( & self , other : & Self ) -> Ordering {
348
348
( * * self ) . cmp ( & * * other)
349
349
}
350
350
}
351
351
352
- impl < T : Trace + ?Sized + Hash > Hash for Gc < T > {
352
+ impl < T : ?Sized + Hash > Hash for Gc < T > {
353
353
fn hash < H : Hasher > ( & self , state : & mut H ) {
354
354
( * * self ) . hash ( state) ;
355
355
}
356
356
}
357
357
358
- impl < T : Trace + ?Sized + Display > Display for Gc < T > {
358
+ impl < T : ?Sized + Display > Display for Gc < T > {
359
359
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
360
360
Display :: fmt ( & * * self , f)
361
361
}
362
362
}
363
363
364
- impl < T : Trace + ?Sized + Debug > Debug for Gc < T > {
364
+ impl < T : ?Sized + Debug > Debug for Gc < T > {
365
365
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
366
366
Debug :: fmt ( & * * self , f)
367
367
}
368
368
}
369
369
370
- impl < T : Trace + ?Sized > fmt:: Pointer for Gc < T > {
370
+ impl < T : ?Sized > fmt:: Pointer for Gc < T > {
371
371
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
372
372
fmt:: Pointer :: fmt ( & self . inner ( ) , f)
373
373
}
@@ -392,13 +392,13 @@ impl<
392
392
}
393
393
}
394
394
395
- impl < T : Trace + ?Sized > std:: borrow:: Borrow < T > for Gc < T > {
395
+ impl < T : ?Sized > std:: borrow:: Borrow < T > for Gc < T > {
396
396
fn borrow ( & self ) -> & T {
397
397
self
398
398
}
399
399
}
400
400
401
- impl < T : Trace + ?Sized > std:: convert:: AsRef < T > for Gc < T > {
401
+ impl < T : ?Sized > std:: convert:: AsRef < T > for Gc < T > {
402
402
fn as_ref ( & self ) -> & T {
403
403
self
404
404
}
@@ -491,7 +491,7 @@ pub struct GcCell<T: ?Sized + 'static> {
491
491
cell : UnsafeCell < T > ,
492
492
}
493
493
494
- impl < T : Trace > GcCell < T > {
494
+ impl < T > GcCell < T > {
495
495
/// Creates a new `GcCell` containing `value`.
496
496
#[ inline]
497
497
pub fn new ( value : T ) -> Self {
@@ -508,7 +508,7 @@ impl<T: Trace> GcCell<T> {
508
508
}
509
509
}
510
510
511
- impl < T : Trace + ?Sized > GcCell < T > {
511
+ impl < T : ?Sized > GcCell < T > {
512
512
/// Immutably borrows the wrapped value.
513
513
///
514
514
/// The borrow lasts until the returned `GcCellRef` exits scope.
@@ -524,7 +524,9 @@ impl<T: Trace + ?Sized> GcCell<T> {
524
524
Err ( e) => panic ! ( "{}" , e) ,
525
525
}
526
526
}
527
+ }
527
528
529
+ impl < T : Trace + ?Sized > GcCell < T > {
528
530
/// Mutably borrows the wrapped value.
529
531
///
530
532
/// The borrow lasts until the returned `GcCellRefMut` exits scope.
@@ -540,7 +542,9 @@ impl<T: Trace + ?Sized> GcCell<T> {
540
542
Err ( e) => panic ! ( "{}" , e) ,
541
543
}
542
544
}
545
+ }
543
546
547
+ impl < T : ?Sized > GcCell < T > {
544
548
/// Immutably borrows the wrapped value, returning an error if the value is currently mutably
545
549
/// borrowed.
546
550
///
@@ -583,7 +587,9 @@ impl<T: Trace + ?Sized> GcCell<T> {
583
587
} )
584
588
}
585
589
}
590
+ }
586
591
592
+ impl < T : Trace + ?Sized > GcCell < T > {
587
593
/// Mutably borrows the wrapped value, returning an error if the value is currently borrowed.
588
594
///
589
595
/// The borrow lasts until the returned `GcCellRefMut` exits scope.
@@ -646,7 +652,7 @@ impl std::fmt::Display for BorrowMutError {
646
652
}
647
653
}
648
654
649
- impl < T : Trace + ?Sized > Finalize for GcCell < T > { }
655
+ impl < T : ?Sized > Finalize for GcCell < T > { }
650
656
651
657
unsafe impl < T : Trace + ?Sized > Trace for GcCell < T > {
652
658
#[ inline]
@@ -926,30 +932,30 @@ impl<'a, T: Trace + ?Sized, U: Display + ?Sized> Display for GcCellRefMut<'a, T,
926
932
927
933
unsafe impl < T : ?Sized + Send > Send for GcCell < T > { }
928
934
929
- impl < T : Trace + Clone > Clone for GcCell < T > {
935
+ impl < T : Clone > Clone for GcCell < T > {
930
936
#[ inline]
931
937
fn clone ( & self ) -> Self {
932
938
Self :: new ( self . borrow ( ) . clone ( ) )
933
939
}
934
940
}
935
941
936
- impl < T : Trace + Default > Default for GcCell < T > {
942
+ impl < T : Default > Default for GcCell < T > {
937
943
#[ inline]
938
944
fn default ( ) -> Self {
939
945
Self :: new ( Default :: default ( ) )
940
946
}
941
947
}
942
948
943
- impl < T : Trace + ?Sized + PartialEq > PartialEq for GcCell < T > {
949
+ impl < T : ?Sized + PartialEq > PartialEq for GcCell < T > {
944
950
#[ inline( always) ]
945
951
fn eq ( & self , other : & Self ) -> bool {
946
952
* self . borrow ( ) == * other. borrow ( )
947
953
}
948
954
}
949
955
950
- impl < T : Trace + ?Sized + Eq > Eq for GcCell < T > { }
956
+ impl < T : ?Sized + Eq > Eq for GcCell < T > { }
951
957
952
- impl < T : Trace + ?Sized + PartialOrd > PartialOrd for GcCell < T > {
958
+ impl < T : ?Sized + PartialOrd > PartialOrd for GcCell < T > {
953
959
#[ inline( always) ]
954
960
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
955
961
( * self . borrow ( ) ) . partial_cmp ( & * other. borrow ( ) )
@@ -976,14 +982,14 @@ impl<T: Trace + ?Sized + PartialOrd> PartialOrd for GcCell<T> {
976
982
}
977
983
}
978
984
979
- impl < T : Trace + ?Sized + Ord > Ord for GcCell < T > {
985
+ impl < T : ?Sized + Ord > Ord for GcCell < T > {
980
986
#[ inline]
981
987
fn cmp ( & self , other : & GcCell < T > ) -> Ordering {
982
988
( * self . borrow ( ) ) . cmp ( & * other. borrow ( ) )
983
989
}
984
990
}
985
991
986
- impl < T : Trace + ?Sized + Debug > Debug for GcCell < T > {
992
+ impl < T : ?Sized + Debug > Debug for GcCell < T > {
987
993
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
988
994
match self . flags . get ( ) . borrowed ( ) {
989
995
BorrowState :: Unused | BorrowState :: Reading => f
0 commit comments