diff options
author | Haibo Huang <hhb@google.com> | 2021-01-05 21:38:44 -0800 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2021-01-05 21:38:44 -0800 |
commit | ec2e2eba63691e5ae47d0e5297b10cccbc19aaf8 (patch) | |
tree | 861d6d4133ab9f5602215a5ef85f255e246a76b9 /src/generics.rs | |
parent | 863ce594072477729421f4affc458294c29cb782 (diff) | |
download | syn-ec2e2eba63691e5ae47d0e5297b10cccbc19aaf8.tar.gz |
Upgrade rust/crates/syn to 1.0.58
Test: make
Change-Id: Ie9cd9adfad50922610eabc0714e0f0eb76b9ff39
Diffstat (limited to 'src/generics.rs')
-rw-r--r-- | src/generics.rs | 89 |
1 files changed, 76 insertions, 13 deletions
diff --git a/src/generics.rs b/src/generics.rs index db6de9d2..a78af22e 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -11,6 +11,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct Generics { pub lt_token: Option<Token![<]>, pub params: Punctuated<GenericParam, Token![,]>, @@ -30,7 +31,8 @@ ast_enum_of_structs! { /// /// This type is a [syntax tree enum]. /// - /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums + /// [syntax tree enum]: Expr#syntax-tree-enums + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum GenericParam { /// A generic type parameter: `T: Into<String>`. Type(TypeParam), @@ -48,6 +50,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct TypeParam { pub attrs: Vec<Attribute>, pub ident: Ident, @@ -63,6 +66,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct LifetimeDef { pub attrs: Vec<Attribute>, pub lifetime: Lifetime, @@ -76,6 +80,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct ConstParam { pub attrs: Vec<Attribute>, pub const_token: Token![const], @@ -294,6 +299,10 @@ impl<'a> Iterator for ConstParamsMut<'a> { /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature and the `"printing"` feature.* #[cfg(feature = "printing")] +#[cfg_attr( + doc_cfg, + doc(cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))) +)] pub struct ImplGenerics<'a>(&'a Generics); /// Returned by `Generics::split_for_impl`. @@ -301,6 +310,10 @@ pub struct ImplGenerics<'a>(&'a Generics); /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature and the `"printing"` feature.* #[cfg(feature = "printing")] +#[cfg_attr( + doc_cfg, + doc(cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))) +)] pub struct TypeGenerics<'a>(&'a Generics); /// Returned by `TypeGenerics::as_turbofish`. @@ -308,6 +321,10 @@ pub struct TypeGenerics<'a>(&'a Generics); /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature and the `"printing"` feature.* #[cfg(feature = "printing")] +#[cfg_attr( + doc_cfg, + doc(cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))) +)] pub struct Turbofish<'a>(&'a Generics); #[cfg(feature = "printing")] @@ -333,6 +350,10 @@ impl Generics { /// /// *This method is available only if Syn is built with the `"derive"` or /// `"full"` feature and the `"printing"` feature.* + #[cfg_attr( + doc_cfg, + doc(cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))) + )] pub fn split_for_impl(&self) -> (ImplGenerics, TypeGenerics, Option<&WhereClause>) { ( ImplGenerics(self), @@ -346,6 +367,7 @@ impl Generics { macro_rules! generics_wrapper_impls { ($ty:ident) => { #[cfg(feature = "clone-impls")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "clone-impls")))] impl<'a> Clone for $ty<'a> { fn clone(&self) -> Self { $ty(self.0) @@ -353,6 +375,7 @@ macro_rules! generics_wrapper_impls { } #[cfg(feature = "extra-traits")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl<'a> Debug for $ty<'a> { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter @@ -363,9 +386,11 @@ macro_rules! generics_wrapper_impls { } #[cfg(feature = "extra-traits")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl<'a> Eq for $ty<'a> {} #[cfg(feature = "extra-traits")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl<'a> PartialEq for $ty<'a> { fn eq(&self, other: &Self) -> bool { self.0 == other.0 @@ -373,6 +398,7 @@ macro_rules! generics_wrapper_impls { } #[cfg(feature = "extra-traits")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] impl<'a> Hash for $ty<'a> { fn hash<H: Hasher>(&self, state: &mut H) { self.0.hash(state); @@ -404,6 +430,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct BoundLifetimes { pub for_token: Token![for], pub lt_token: Token![<], @@ -452,6 +479,7 @@ ast_enum_of_structs! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum TypeParamBound { Trait(TraitBound), Lifetime(Lifetime), @@ -463,6 +491,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct TraitBound { pub paren_token: Option<token::Paren>, pub modifier: TraitBoundModifier, @@ -479,6 +508,7 @@ ast_enum! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum TraitBoundModifier { None, Maybe(Token![?]), @@ -491,6 +521,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or `"full"` /// feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct WhereClause { pub where_token: Token![where], pub predicates: Punctuated<WherePredicate, Token![,]>, @@ -507,7 +538,8 @@ ast_enum_of_structs! { /// /// This type is a [syntax tree enum]. /// - /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums + /// [syntax tree enum]: Expr#syntax-tree-enums + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub enum WherePredicate { /// A type predicate in a `where` clause: `for<'c> Foo<'c>: Trait<'c>`. Type(PredicateType), @@ -525,6 +557,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct PredicateType { /// Any lifetimes from a `for` binding pub lifetimes: Option<BoundLifetimes>, @@ -541,6 +574,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct PredicateLifetime { pub lifetime: Lifetime, pub colon_token: Token![:], @@ -553,6 +587,7 @@ ast_struct! { /// /// *This type is available only if Syn is built with the `"derive"` or /// `"full"` feature.* + #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] pub struct PredicateEq { pub lhs_ty: Type, pub eq_token: Token![=], @@ -565,6 +600,7 @@ pub mod parsing { use super::*; use crate::parse::{Parse, ParseStream, Result}; + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Generics { fn parse(input: ParseStream) -> Result<Self> { if !input.peek(Token![<]) { @@ -574,7 +610,6 @@ pub mod parsing { let lt_token: Token![<] = input.parse()?; let mut params = Punctuated::new(); - let mut allow_lifetime_param = true; loop { if input.peek(Token![>]) { break; @@ -582,19 +617,17 @@ pub mod parsing { let attrs = input.call(Attribute::parse_outer)?; let lookahead = input.lookahead1(); - if allow_lifetime_param && lookahead.peek(Lifetime) { + if lookahead.peek(Lifetime) { params.push_value(GenericParam::Lifetime(LifetimeDef { attrs, ..input.parse()? })); } else if lookahead.peek(Ident) { - allow_lifetime_param = false; params.push_value(GenericParam::Type(TypeParam { attrs, ..input.parse()? })); } else if lookahead.peek(Token![const]) { - allow_lifetime_param = false; params.push_value(GenericParam::Const(ConstParam { attrs, ..input.parse()? @@ -621,6 +654,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for GenericParam { fn parse(input: ParseStream) -> Result<Self> { let attrs = input.call(Attribute::parse_outer)?; @@ -647,6 +681,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for LifetimeDef { fn parse(input: ParseStream) -> Result<Self> { let has_colon; @@ -684,6 +719,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for BoundLifetimes { fn parse(input: ParseStream) -> Result<Self> { Ok(BoundLifetimes { @@ -705,6 +741,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Option<BoundLifetimes> { fn parse(input: ParseStream) -> Result<Self> { if input.peek(Token![for]) { @@ -715,6 +752,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for TypeParam { fn parse(input: ParseStream) -> Result<Self> { let attrs = input.call(Attribute::parse_outer)?; @@ -768,6 +806,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for TypeParamBound { fn parse(input: ParseStream) -> Result<Self> { if input.peek(Lifetime) { @@ -786,6 +825,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for TraitBound { fn parse(input: ParseStream) -> Result<Self> { let modifier: TraitBoundModifier = input.parse()?; @@ -806,6 +846,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for TraitBoundModifier { fn parse(input: ParseStream) -> Result<Self> { if input.peek(Token![?]) { @@ -816,6 +857,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for ConstParam { fn parse(input: ParseStream) -> Result<Self> { let mut default = None; @@ -839,6 +881,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for WhereClause { fn parse(input: ParseStream) -> Result<Self> { Ok(WhereClause { @@ -869,6 +912,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Option<WhereClause> { fn parse(input: ParseStream) -> Result<Self> { if input.peek(Token![where]) { @@ -879,6 +923,7 @@ pub mod parsing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for WherePredicate { fn parse(input: ParseStream) -> Result<Self> { if input.peek(Lifetime) && input.peek2(Token![:]) { @@ -951,6 +996,7 @@ mod printing { use proc_macro2::TokenTree; use quote::{ToTokens, TokenStreamExt}; + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for Generics { fn to_tokens(&self, tokens: &mut TokenStream) { if self.params.is_empty() { @@ -1100,6 +1146,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for BoundLifetimes { fn to_tokens(&self, tokens: &mut TokenStream) { self.for_token.to_tokens(tokens); @@ -1109,6 +1156,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for LifetimeDef { fn to_tokens(&self, tokens: &mut TokenStream) { tokens.append_all(self.attrs.outer()); @@ -1120,6 +1168,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for TypeParam { fn to_tokens(&self, tokens: &mut TokenStream) { tokens.append_all(self.attrs.outer()); @@ -1133,14 +1182,21 @@ mod printing { { if self.eq_token.is_none() { if let Type::Verbatim(default) = default { - let mut iter = default.clone().into_iter(); - match (iter.next(), iter.next()) { - (Some(TokenTree::Punct(ref q)), Some(TokenTree::Ident(ref c))) - if q.as_char() == '?' && c == "const" => - { - return default.to_tokens(tokens); + let mut iter = default.clone().into_iter().peekable(); + while let Some(token) = iter.next() { + if let TokenTree::Punct(q) = token { + if q.as_char() == '?' { + if let Some(TokenTree::Ident(c)) = iter.peek() { + if c == "const" { + if self.bounds.is_empty() { + TokensOrDefault(&self.colon_token) + .to_tokens(tokens); + } + return default.to_tokens(tokens); + } + } + } } - _ => {} } } } @@ -1151,6 +1207,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for TraitBound { fn to_tokens(&self, tokens: &mut TokenStream) { let to_tokens = |tokens: &mut TokenStream| { @@ -1165,6 +1222,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for TraitBoundModifier { fn to_tokens(&self, tokens: &mut TokenStream) { match self { @@ -1174,6 +1232,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for ConstParam { fn to_tokens(&self, tokens: &mut TokenStream) { tokens.append_all(self.attrs.outer()); @@ -1188,6 +1247,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for WhereClause { fn to_tokens(&self, tokens: &mut TokenStream) { if !self.predicates.is_empty() { @@ -1197,6 +1257,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for PredicateType { fn to_tokens(&self, tokens: &mut TokenStream) { self.lifetimes.to_tokens(tokens); @@ -1206,6 +1267,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for PredicateLifetime { fn to_tokens(&self, tokens: &mut TokenStream) { self.lifetime.to_tokens(tokens); @@ -1214,6 +1276,7 @@ mod printing { } } + #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] impl ToTokens for PredicateEq { fn to_tokens(&self, tokens: &mut TokenStream) { self.lhs_ty.to_tokens(tokens); |