@@ -504,17 +504,11 @@ fn impl_derive_trace(input: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStre
504
504
} else {
505
505
impl_rebrand ( input, info) ?
506
506
} ;
507
- let erase_impl = if info. config . nop_trace {
508
- impl_erase_nop ( input, info) ?
509
- } else {
510
- impl_erase ( input, info) ?
511
- } ;
512
507
let gc_safe_impl = impl_gc_safe ( input, info) ?;
513
508
let extra_impls = impl_extras ( input, info) ?;
514
509
Ok ( quote ! {
515
510
#trace_impl
516
511
#rebrand_impl
517
- #erase_impl
518
512
#gc_safe_impl
519
513
#extra_impls
520
514
} )
@@ -665,172 +659,6 @@ fn impl_extras(target: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStream, E
665
659
} )
666
660
}
667
661
668
-
669
- fn impl_erase_nop ( target : & DeriveInput , info : & GcTypeInfo ) -> Result < TokenStream , Error > {
670
- let zerogc_crate = zerogc_crate ( ) ;
671
- let name = & target. ident ;
672
- let mut generics: Generics = target. generics . clone ( ) ;
673
- for param in & mut generics. params {
674
- match param {
675
- GenericParam :: Type ( ref mut type_param) => {
676
- // Require all params are NullTrace
677
- type_param. bounds . push ( parse_quote ! ( #zerogc_crate:: NullTrace ) ) ;
678
- } ,
679
- GenericParam :: Lifetime ( ref mut l) => {
680
- if l. lifetime == info. config . gc_lifetime ( ) {
681
- assert ! ( !info. config. ignored_lifetimes. contains( & l. lifetime) ) ;
682
- return Err ( Error :: new (
683
- l. lifetime . span ( ) ,
684
- "Unexpected GC lifetime: Expected #[zerogc(nop_trace)] during #[derive(GcErase)]"
685
- ) )
686
- } else if info. config . ignored_lifetimes . contains ( & l. lifetime ) {
687
- // Explicitly ignored is okay, as long as it outlives the `'min`
688
- l. bounds . push ( parse_quote ! ( ' min) ) ;
689
- } else {
690
- return Err ( Error :: new (
691
- l. span ( ) ,
692
- "Lifetime must be explicitly ignored"
693
- ) )
694
- }
695
- } ,
696
- GenericParam :: Const ( _) => { }
697
- }
698
- }
699
- let mut impl_generics = generics. clone ( ) ;
700
- impl_generics. params . push ( GenericParam :: Lifetime ( parse_quote ! ( ' min) ) ) ;
701
- let collector_id = match info. config . collector_id {
702
- Some ( ref id) => id. clone ( ) ,
703
- None => {
704
- impl_generics. params . push ( GenericParam :: Type ( parse_quote ! ( Id : #zerogc_crate:: CollectorId ) ) ) ;
705
- parse_quote ! ( Id )
706
- }
707
- } ;
708
- // Require that `Self: NullTrace`
709
- impl_generics. make_where_clause ( ) . predicates . push ( WherePredicate :: Type ( PredicateType {
710
- lifetimes : None ,
711
- bounded_ty : parse_quote ! ( Self ) ,
712
- bounds : parse_quote ! ( #zerogc_crate:: NullTrace ) ,
713
- colon_token : Default :: default ( )
714
- } ) ) ;
715
- let ( _, ty_generics, _) = generics. split_for_impl ( ) ;
716
- let ( impl_generics, _, where_clause) = impl_generics. split_for_impl ( ) ;
717
- Ok ( quote ! {
718
- unsafe impl #impl_generics #zerogc_crate:: GcErase <' min, #collector_id>
719
- for #name #ty_generics #where_clause {
720
- // We can pass-through because we are NullTrace
721
- type Erased = Self ;
722
- }
723
- } )
724
- }
725
- fn impl_erase ( target : & DeriveInput , info : & GcTypeInfo ) -> Result < TokenStream , Error > {
726
- let zerogc_crate = zerogc_crate ( ) ;
727
- let name = & target. ident ;
728
- let mut generics: Generics = target. generics . clone ( ) ;
729
- let mut rewritten_params = Vec :: new ( ) ;
730
- let mut rewritten_restrictions = Vec :: new ( ) ;
731
- let collector_id = match info. config . collector_id {
732
- Some ( ref id) => id. clone ( ) ,
733
- None => parse_quote ! ( Id )
734
- } ;
735
- for param in & mut generics. params {
736
- let rewritten_param: GenericArgument ;
737
- fn unsupported_lifetime_param ( lt : & Lifetime ) -> Error {
738
- Error :: new (
739
- lt. span ( ) ,
740
- "Unless Self: NullTrace, derive(GcErase) is currently unable to handle lifetimes"
741
- )
742
- }
743
- match param {
744
- GenericParam :: Type ( ref mut type_param) => {
745
- let param_name = & type_param. ident ;
746
- if info. is_ignored_param ( & * type_param) {
747
- let param_name = & type_param. ident ;
748
- rewritten_params. push ( parse_quote ! ( #param_name) ) ;
749
- continue
750
- }
751
- fn rewrite_bound ( bound : & TypeParamBound , info : & GcTypeInfo ) -> Result < TypeParamBound , Error > {
752
- match bound {
753
- TypeParamBound :: Trait ( ref t) => Ok ( TypeParamBound :: Trait ( t. clone ( ) ) ) ,
754
- TypeParamBound :: Lifetime ( ref lt) if * lt == info. config . gc_lifetime ( ) => {
755
- Ok ( parse_quote ! ( ' new_gc) )
756
- } ,
757
- TypeParamBound :: Lifetime ( ref lt) => {
758
- Err ( unsupported_lifetime_param ( lt) )
759
- }
760
- }
761
- }
762
- let original_bounds = type_param. bounds . iter ( )
763
- . map ( |bound| rewrite_bound ( bound, info) )
764
- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
765
- type_param. bounds . push ( parse_quote ! ( #zerogc_crate:: GcErase <' min, #collector_id>) ) ;
766
- type_param. bounds . push ( parse_quote ! ( ' min) ) ;
767
- let rewritten_type: Type = parse_quote ! ( <#param_name as #zerogc_crate:: GcErase <' min, #collector_id>>:: Erased ) ;
768
- rewritten_restrictions. push ( WherePredicate :: Type ( PredicateType {
769
- lifetimes : None ,
770
- bounded_ty : rewritten_type. clone ( ) ,
771
- colon_token : Default :: default ( ) ,
772
- bounds : original_bounds. into_iter ( ) . collect ( )
773
- } ) ) ;
774
- rewritten_param = GenericArgument :: Type ( rewritten_type) ;
775
- } ,
776
- GenericParam :: Lifetime ( ref l) => {
777
- if l. lifetime == info. config . gc_lifetime ( ) {
778
- rewritten_param = parse_quote ! ( ' min) ;
779
- assert ! ( !info. config. ignored_lifetimes. contains( & l. lifetime) ) ;
780
- } else {
781
- return Err ( unsupported_lifetime_param ( & l. lifetime ) )
782
- }
783
- } ,
784
- GenericParam :: Const ( ref param) => {
785
- let name = & param. ident ;
786
- rewritten_param = GenericArgument :: Const ( parse_quote ! ( #name) ) ;
787
- }
788
- }
789
- rewritten_params. push ( rewritten_param) ;
790
- }
791
- let mut field_types = Vec :: new ( ) ;
792
- match target. data {
793
- Data :: Struct ( ref s) => {
794
- for f in & s. fields {
795
- field_types. push ( f. ty . clone ( ) ) ;
796
- }
797
- } ,
798
- Data :: Enum ( ref e) => {
799
- for variant in & e. variants {
800
- for f in & variant. fields {
801
- field_types. push ( f. ty . clone ( ) ) ;
802
- }
803
- }
804
- } ,
805
- Data :: Union ( _) => {
806
- return Err ( Error :: new ( target. ident . span ( ) , "Unable to derive(GcErase) for unions" ) )
807
- }
808
- }
809
- let mut impl_generics = generics. clone ( ) ;
810
- impl_generics. params . push ( GenericParam :: Lifetime ( parse_quote ! ( ' min) ) ) ;
811
- if info. config . collector_id . is_none ( ) {
812
- impl_generics. params . push ( GenericParam :: Type ( parse_quote ! ( Id : #zerogc_crate:: CollectorId ) ) ) ;
813
- }
814
- impl_generics. make_where_clause ( ) . predicates . extend ( rewritten_restrictions) ;
815
- let ( _, ty_generics, _) = generics. split_for_impl ( ) ;
816
- let ( impl_generics, _, where_clause) = impl_generics. split_for_impl ( ) ;
817
- let assert_erase = field_types. iter ( ) . map ( |field_type| {
818
- let span = field_type. span ( ) ;
819
- quote_spanned ! ( span => <#field_type as #zerogc_crate:: GcErase <' min, #collector_id>>:: assert_erase( ) ; )
820
- } ) . collect :: < Vec < _ > > ( ) ;
821
- Ok ( quote ! {
822
- unsafe impl #impl_generics #zerogc_crate:: GcErase <' min, #collector_id>
823
- for #name #ty_generics #where_clause {
824
- type Erased = #name:: <#( #rewritten_params) , * >;
825
-
826
- fn assert_erase( ) {
827
- #( #assert_erase) *
828
- }
829
- }
830
- } )
831
- }
832
-
833
-
834
662
fn impl_rebrand_nop ( target : & DeriveInput , info : & GcTypeInfo ) -> Result < TokenStream , Error > {
835
663
let zerogc_crate = zerogc_crate ( ) ;
836
664
let name = & target. ident ;
@@ -966,7 +794,7 @@ fn impl_rebrand(target: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStream,
966
794
}
967
795
} ,
968
796
Data :: Union ( _) => {
969
- return Err ( Error :: new ( target. ident . span ( ) , "Unable to derive(GcErase ) for unions" ) )
797
+ return Err ( Error :: new ( target. ident . span ( ) , "Unable to derive(GcRebrand ) for unions" ) )
970
798
}
971
799
}
972
800
let mut impl_generics = generics. clone ( ) ;
0 commit comments