@@ -6,14 +6,15 @@ use bit_set::BitSet;
66use quote:: { quote, ToTokens } ;
77use syn:: token:: Comma ;
88
9+ use crate :: generics:: ReflectGenerics ;
910use crate :: {
1011 utility, REFLECT_ATTRIBUTE_NAME , REFLECT_VALUE_ATTRIBUTE_NAME , TYPE_NAME_ATTRIBUTE_NAME ,
1112 TYPE_PATH_ATTRIBUTE_NAME ,
1213} ;
1314use syn:: punctuated:: Punctuated ;
1415use syn:: spanned:: Spanned ;
1516use syn:: {
16- parse_str, Data , DeriveInput , Field , Fields , GenericParam , Generics , Ident , LitStr , Meta , Path ,
17+ parse_str, Data , DeriveInput , Field , Fields , GenericParam , Ident , LitStr , Meta , Path ,
1718 PathSegment , Type , TypeParam , Variant ,
1819} ;
1920
@@ -250,7 +251,7 @@ impl<'a> ReflectDerive<'a> {
250251 let type_path = ReflectTypePath :: Internal {
251252 ident : & input. ident ,
252253 custom_path,
253- generics : & input. generics ,
254+ generics : ReflectGenerics :: new ( & input. generics ) ? ,
254255 } ;
255256
256257 let meta = ReflectMeta :: new ( type_path, traits) ;
@@ -467,8 +468,8 @@ impl<'a> ReflectStruct<'a> {
467468 & self . fields
468469 }
469470
470- pub fn where_clause_options ( & self ) -> WhereClauseOptions {
471- WhereClauseOptions :: new ( self . meta ( ) , self . active_fields ( ) , self . ignored_fields ( ) )
471+ pub fn where_clause_options ( & self ) -> Result < WhereClauseOptions , syn :: Error > {
472+ WhereClauseOptions :: new ( self . meta ( ) )
472473 }
473474}
474475
@@ -491,22 +492,8 @@ impl<'a> ReflectEnum<'a> {
491492 & self . variants
492493 }
493494
494- /// Get an iterator of fields which are exposed to the reflection API
495- pub fn active_fields ( & self ) -> impl Iterator < Item = & StructField < ' a > > {
496- self . variants ( )
497- . iter ( )
498- . flat_map ( |variant| variant. active_fields ( ) )
499- }
500-
501- /// Get an iterator of fields which are ignored by the reflection API
502- pub fn ignored_fields ( & self ) -> impl Iterator < Item = & StructField < ' a > > {
503- self . variants ( )
504- . iter ( )
505- . flat_map ( |variant| variant. ignored_fields ( ) )
506- }
507-
508- pub fn where_clause_options ( & self ) -> WhereClauseOptions {
509- WhereClauseOptions :: new ( self . meta ( ) , self . active_fields ( ) , self . ignored_fields ( ) )
495+ pub fn where_clause_options ( & self ) -> Result < WhereClauseOptions , syn:: Error > {
496+ WhereClauseOptions :: new ( self . meta ( ) )
510497 }
511498}
512499
@@ -581,7 +568,7 @@ pub(crate) enum ReflectTypePath<'a> {
581568 External {
582569 path : & ' a Path ,
583570 custom_path : Option < Path > ,
584- generics : & ' a Generics ,
571+ generics : ReflectGenerics ,
585572 } ,
586573 /// The name of a type relative to its scope.
587574 ///
@@ -594,7 +581,7 @@ pub(crate) enum ReflectTypePath<'a> {
594581 Internal {
595582 ident : & ' a Ident ,
596583 custom_path : Option < Path > ,
597- generics : & ' a Generics ,
584+ generics : ReflectGenerics ,
598585 } ,
599586 /// Any [`syn::Type`] with only a defined `type_path` and `short_type_path`.
600587 #[ allow( dead_code) ]
@@ -644,17 +631,10 @@ impl<'a> ReflectTypePath<'a> {
644631 ///
645632 /// [primitive]: ReflectTypePath::Primitive
646633 /// [anonymous]: ReflectTypePath::Anonymous
647- pub fn generics ( & self ) -> & ' a Generics {
648- // Use a constant because we need to return a reference of at least 'a.
649- const EMPTY_GENERICS : & Generics = & Generics {
650- gt_token : None ,
651- lt_token : None ,
652- where_clause : None ,
653- params : Punctuated :: new ( ) ,
654- } ;
634+ pub fn generics ( & self ) -> & ReflectGenerics {
655635 match self {
656636 Self :: Internal { generics, .. } | Self :: External { generics, .. } => generics,
657- _ => EMPTY_GENERICS ,
637+ _ => ReflectGenerics :: EMPTY ,
658638 }
659639 }
660640
@@ -666,9 +646,8 @@ impl<'a> ReflectTypePath<'a> {
666646 // (which all have to be 'static anyway).
667647 !self
668648 . generics ( )
669- . params
670- . iter ( )
671- . all ( |param| matches ! ( param, GenericParam :: Lifetime ( _) ) )
649+ . params ( )
650+ . all ( |( param, _) | matches ! ( param, GenericParam :: Lifetime ( _) ) )
672651 }
673652
674653 /// Returns the path interpreted as a [`Path`].
@@ -736,10 +715,10 @@ impl<'a> ReflectTypePath<'a> {
736715 ///
737716 /// The `ty_generic_fn` param maps [`TypeParam`]s to [`StringExpr`]s.
738717 fn reduce_generics (
739- generics : & Generics ,
718+ generics : & ReflectGenerics ,
740719 mut ty_generic_fn : impl FnMut ( & TypeParam ) -> StringExpr ,
741720 ) -> StringExpr {
742- let mut params = generics. params . iter ( ) . filter_map ( |param| match param {
721+ let mut params = generics. params ( ) . filter_map ( |( param, _ ) | match param {
743722 GenericParam :: Type ( type_param) => Some ( ty_generic_fn ( type_param) ) ,
744723 GenericParam :: Const ( const_param) => {
745724 let ident = & const_param. ident ;
0 commit comments