aboutsummaryrefslogtreecommitdiff
path: root/src/path.rs
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2021-01-05 21:38:44 -0800
committerHaibo Huang <hhb@google.com>2021-01-05 21:38:44 -0800
commitec2e2eba63691e5ae47d0e5297b10cccbc19aaf8 (patch)
tree861d6d4133ab9f5602215a5ef85f255e246a76b9 /src/path.rs
parent863ce594072477729421f4affc458294c29cb782 (diff)
downloadsyn-ec2e2eba63691e5ae47d0e5297b10cccbc19aaf8.tar.gz
Upgrade rust/crates/syn to 1.0.58
Test: make Change-Id: Ie9cd9adfad50922610eabc0714e0f0eb76b9ff39
Diffstat (limited to 'src/path.rs')
-rw-r--r--src/path.rs68
1 files changed, 54 insertions, 14 deletions
diff --git a/src/path.rs b/src/path.rs
index 217a72e3..601891e1 100644
--- a/src/path.rs
+++ b/src/path.rs
@@ -6,6 +6,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 Path {
pub leading_colon: Option<Token![::]>,
pub segments: Punctuated<PathSegment, Token![::]>,
@@ -31,6 +32,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 PathSegment {
pub ident: Ident,
pub arguments: PathArguments,
@@ -62,6 +64,7 @@ ast_enum! {
/// ## Parenthesized
///
/// The `(A, B) -> C` in `Fn(A, B) -> C`.
+ #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
pub enum PathArguments {
None,
/// The `<'a, T>` in `std::slice::iter<'a, T>`.
@@ -100,6 +103,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 GenericArgument {
/// A lifetime argument.
Lifetime(Lifetime),
@@ -124,6 +128,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 AngleBracketedGenericArguments {
pub colon2_token: Option<Token![::]>,
pub lt_token: Token![<],
@@ -137,6 +142,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 Binding {
pub ident: Ident,
pub eq_token: Token![=],
@@ -149,6 +155,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 Constraint {
pub ident: Ident,
pub colon_token: Token![:],
@@ -162,6 +169,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 ParenthesizedGenericArguments {
pub paren_token: token::Paren,
/// `(A, B)`
@@ -191,6 +199,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 QSelf {
pub lt_token: Token![<],
pub ty: Box<Type>,
@@ -209,12 +218,14 @@ pub mod parsing {
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Path {
fn parse(input: ParseStream) -> Result<Self> {
Self::parse_helper(input, false)
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for GenericArgument {
fn parse(input: ParseStream) -> Result<Self> {
if input.peek(Lifetime) && !input.peek2(Token![+]) {
@@ -230,12 +241,15 @@ pub mod parsing {
if input.peek(Ident) && input.peek2(Token![:]) && !input.peek2(Token![::]) {
return Ok(GenericArgument::Constraint(input.parse()?));
}
+ }
- if input.peek(Lit) {
- let lit = input.parse()?;
- return Ok(GenericArgument::Const(Expr::Lit(lit)));
- }
+ if input.peek(Lit) {
+ let lit = input.parse()?;
+ return Ok(GenericArgument::Const(Expr::Lit(lit)));
+ }
+ #[cfg(feature = "full")]
+ {
if input.peek(token::Brace) {
let block = input.call(expr::parsing::expr_block)?;
return Ok(GenericArgument::Const(Expr::Block(block)));
@@ -246,6 +260,7 @@ pub mod parsing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for AngleBracketedGenericArguments {
fn parse(input: ParseStream) -> Result<Self> {
Ok(AngleBracketedGenericArguments {
@@ -272,6 +287,7 @@ pub mod parsing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ParenthesizedGenericArguments {
fn parse(input: ParseStream) -> Result<Self> {
let content;
@@ -283,6 +299,7 @@ pub mod parsing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for PathSegment {
fn parse(input: ParseStream) -> Result<Self> {
Self::parse_helper(input, false)
@@ -315,6 +332,7 @@ pub mod parsing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Binding {
fn parse(input: ParseStream) -> Result<Self> {
Ok(Binding {
@@ -326,6 +344,7 @@ pub mod parsing {
}
#[cfg(feature = "full")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Constraint {
fn parse(input: ParseStream) -> Result<Self> {
Ok(Constraint {
@@ -385,6 +404,7 @@ pub mod parsing {
/// }
/// }
/// ```
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_mod_style(input: ParseStream) -> Result<Self> {
Ok(Path {
leading_colon: input.parse()?,
@@ -448,6 +468,7 @@ pub mod parsing {
/// }
/// }
/// ```
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub fn is_ident<I: ?Sized>(&self, ident: &I) -> bool
where
Ident: PartialEq<I>,
@@ -469,6 +490,7 @@ pub mod parsing {
///
/// *This function is available only if Syn is built with the `"parsing"`
/// feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub fn get_ident(&self) -> Option<&Ident> {
if self.leading_colon.is_none()
&& self.segments.len() == 1
@@ -480,22 +502,32 @@ pub mod parsing {
}
}
- fn parse_helper(input: ParseStream, expr_style: bool) -> Result<Self> {
- Ok(Path {
+ pub(crate) fn parse_helper(input: ParseStream, expr_style: bool) -> Result<Self> {
+ let mut path = Path {
leading_colon: input.parse()?,
segments: {
let mut segments = Punctuated::new();
let value = PathSegment::parse_helper(input, expr_style)?;
segments.push_value(value);
- while input.peek(Token![::]) {
- let punct: Token![::] = input.parse()?;
- segments.push_punct(punct);
- let value = PathSegment::parse_helper(input, expr_style)?;
- segments.push_value(value);
- }
segments
},
- })
+ };
+ Path::parse_rest(input, &mut path, expr_style)?;
+ Ok(path)
+ }
+
+ pub(crate) fn parse_rest(
+ input: ParseStream,
+ path: &mut Self,
+ expr_style: bool,
+ ) -> Result<()> {
+ while input.peek(Token![::]) {
+ let punct: Token![::] = input.parse()?;
+ path.segments.push_punct(punct);
+ let value = PathSegment::parse_helper(input, expr_style)?;
+ path.segments.push_value(value);
+ }
+ Ok(())
}
}
@@ -560,6 +592,7 @@ mod printing {
use quote::ToTokens;
use std::cmp;
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Path {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.leading_colon.to_tokens(tokens);
@@ -567,6 +600,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for PathSegment {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.ident.to_tokens(tokens);
@@ -574,6 +608,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for PathArguments {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
@@ -588,6 +623,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for GenericArgument {
#[allow(clippy::match_same_arms)]
fn to_tokens(&self, tokens: &mut TokenStream) {
@@ -615,6 +651,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for AngleBracketedGenericArguments {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.colon2_token.to_tokens(tokens);
@@ -657,9 +694,9 @@ mod printing {
GenericArgument::Binding(_) | GenericArgument::Constraint(_) => {
if !trailing_or_empty {
<Token![,]>::default().to_tokens(tokens);
- trailing_or_empty = true;
}
param.to_tokens(tokens);
+ trailing_or_empty = param.punct().is_some();
}
GenericArgument::Lifetime(_)
| GenericArgument::Type(_)
@@ -671,6 +708,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Binding {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.ident.to_tokens(tokens);
@@ -679,6 +717,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for Constraint {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.ident.to_tokens(tokens);
@@ -687,6 +726,7 @@ mod printing {
}
}
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for ParenthesizedGenericArguments {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.paren_token.surround(tokens, |tokens| {