@@ -9,8 +9,8 @@ use proc_macro2::TokenStream;
99use quote:: { quote, ToTokens , TokenStreamExt } ;
1010use syn:: parse:: { Parse , ParseStream , Result } ;
1111use syn:: punctuated:: { Pair , Punctuated } ;
12- use syn:: { parenthesized , token} ;
13- use syn:: { Attribute , ConstParam , LifetimeDef , PredicateLifetime , TraitBound } ;
12+ use syn:: token;
13+ use syn:: { Attribute , ConstParam , LifetimeParam , PredicateLifetime } ;
1414use syn:: { BoundLifetimes , Ident , Lifetime , Token , Type } ;
1515
1616/// Lifetimes and type parameters attached an item
@@ -50,7 +50,7 @@ pub enum GenericParam {
5050 /// Type parameter
5151 Type ( TypeParam ) ,
5252 /// Lifetime parameter
53- Lifetime ( LifetimeDef ) ,
53+ Lifetime ( LifetimeParam ) ,
5454 /// `const` parameter
5555 Const ( ConstParam ) ,
5656}
@@ -77,16 +77,13 @@ pub struct TypeParam {
7777
7878/// A trait or lifetime used as a bound on a type parameter.
7979///
80- /// This is a custom variant of [`syn::TypeParamBound`]
81- /// which supports `trait` as a parameter bound.
80+ /// This is a superset of [`syn::TypeParamBound`].
8281#[ derive( Debug ) ]
8382pub enum TypeParamBound {
84- /// A named trait used as a bound
85- Trait ( TraitBound ) ,
8683 /// `trait` used as a bound (substituted for the trait name by [`ToTokensSubst`])
8784 TraitSubst ( Token ! [ trait ] ) ,
88- /// A lifetime bound
89- Lifetime ( Lifetime ) ,
85+ /// Everything else
86+ Other ( syn :: TypeParamBound ) ,
9087}
9188
9289/// A `where` clause in a definition: `where T: Deserialize<'de>, D: 'static`.
@@ -152,7 +149,7 @@ mod parsing {
152149 let attrs = input. call ( Attribute :: parse_outer) ?;
153150 let lookahead = input. lookahead1 ( ) ;
154151 if lookahead. peek ( Lifetime ) {
155- params. push_value ( GenericParam :: Lifetime ( LifetimeDef {
152+ params. push_value ( GenericParam :: Lifetime ( LifetimeParam {
156153 attrs,
157154 ..input. parse ( ) ?
158155 } ) ) ;
@@ -239,23 +236,11 @@ mod parsing {
239236
240237 impl Parse for TypeParamBound {
241238 fn parse ( input : ParseStream ) -> Result < Self > {
242- if input. peek ( Lifetime ) {
243- return input. parse ( ) . map ( TypeParamBound :: Lifetime ) ;
244- }
245-
246239 if input. peek ( Token ! [ trait ] ) {
247- return input. parse ( ) . map ( TypeParamBound :: TraitSubst ) ;
248- }
249-
250- if input. peek ( token:: Paren ) {
251- let content;
252- let paren_token = parenthesized ! ( content in input) ;
253- let mut bound: TraitBound = content. parse ( ) ?;
254- bound. paren_token = Some ( paren_token) ;
255- return Ok ( TypeParamBound :: Trait ( bound) ) ;
240+ input. parse ( ) . map ( TypeParamBound :: TraitSubst )
241+ } else {
242+ syn:: TypeParamBound :: parse ( input) . map ( TypeParamBound :: Other )
256243 }
257-
258- input. parse ( ) . map ( TypeParamBound :: Trait )
259244 }
260245 }
261246
@@ -470,19 +455,15 @@ mod printing_subst {
470455 impl ToTokensSubst for TypeParamBound {
471456 fn to_tokens_subst ( & self , tokens : & mut TokenStream , subst : & TokenStream ) {
472457 match self {
473- TypeParamBound :: Trait ( t) => t. to_tokens ( tokens) ,
474458 TypeParamBound :: TraitSubst ( _) => tokens. append_all ( quote ! { #subst } ) ,
475- TypeParamBound :: Lifetime ( lt ) => lt . to_tokens ( tokens) ,
459+ TypeParamBound :: Other ( bound ) => bound . to_tokens ( tokens) ,
476460 }
477461 }
478462 }
479463}
480464
481465fn map_type_param_bound ( bound : & syn:: TypeParamBound ) -> TypeParamBound {
482- match bound {
483- syn:: TypeParamBound :: Trait ( bound) => TypeParamBound :: Trait ( bound. clone ( ) ) ,
484- syn:: TypeParamBound :: Lifetime ( bound) => TypeParamBound :: Lifetime ( bound. clone ( ) ) ,
485- }
466+ TypeParamBound :: Other ( bound. clone ( ) )
486467}
487468
488469fn map_generic_param ( param : & syn:: GenericParam ) -> GenericParam {
0 commit comments