summaryrefslogtreecommitdiffstats
path: root/vendor/syn/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/syn/src')
-rw-r--r--vendor/syn/src/custom_punctuation.rs2
-rw-r--r--vendor/syn/src/data.rs38
-rw-r--r--vendor/syn/src/ident.rs10
-rw-r--r--vendor/syn/src/item.rs253
-rw-r--r--vendor/syn/src/lib.rs2
-rw-r--r--vendor/syn/src/lifetime.rs10
-rw-r--r--vendor/syn/src/lit.rs31
-rw-r--r--vendor/syn/src/macros.rs17
-rw-r--r--vendor/syn/src/path.rs13
-rw-r--r--vendor/syn/src/token.rs63
10 files changed, 319 insertions, 120 deletions
diff --git a/vendor/syn/src/custom_punctuation.rs b/vendor/syn/src/custom_punctuation.rs
index dba91c17f..062fe5169 100644
--- a/vendor/syn/src/custom_punctuation.rs
+++ b/vendor/syn/src/custom_punctuation.rs
@@ -114,7 +114,7 @@ macro_rules! custom_punctuation {
macro_rules! impl_parse_for_custom_punctuation {
($ident:ident, $($tt:tt)+) => {
impl $crate::token::CustomToken for $ident {
- fn peek(cursor: $crate::buffer::Cursor) -> bool {
+ fn peek(cursor: $crate::buffer::Cursor) -> $crate::__private::bool {
$crate::__private::peek_punct(cursor, $crate::stringify_punct!($($tt)+))
}
diff --git a/vendor/syn/src/data.rs b/vendor/syn/src/data.rs
index 185f88ba0..431c0857d 100644
--- a/vendor/syn/src/data.rs
+++ b/vendor/syn/src/data.rs
@@ -214,17 +214,37 @@ pub(crate) mod parsing {
/// Parses a named (braced struct) field.
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_named(input: ParseStream) -> Result<Self> {
+ let attrs = input.call(Attribute::parse_outer)?;
+ let vis: Visibility = input.parse()?;
+
+ let unnamed_field = cfg!(feature = "full") && input.peek(Token![_]);
+ let ident = if unnamed_field {
+ input.call(Ident::parse_any)
+ } else {
+ input.parse()
+ }?;
+
+ let colon_token: Token![:] = input.parse()?;
+
+ let ty: Type = if unnamed_field
+ && (input.peek(Token![struct])
+ || input.peek(Token![union]) && input.peek2(token::Brace))
+ {
+ let begin = input.fork();
+ input.call(Ident::parse_any)?;
+ input.parse::<FieldsNamed>()?;
+ Type::Verbatim(verbatim::between(&begin, input))
+ } else {
+ input.parse()?
+ };
+
Ok(Field {
- attrs: input.call(Attribute::parse_outer)?,
- vis: input.parse()?,
+ attrs,
+ vis,
mutability: FieldMutability::None,
- ident: Some(if input.peek(Token![_]) {
- input.call(Ident::parse_any)
- } else {
- input.parse()
- }?),
- colon_token: Some(input.parse()?),
- ty: input.parse()?,
+ ident: Some(ident),
+ colon_token: Some(colon_token),
+ ty,
})
}
diff --git a/vendor/syn/src/ident.rs b/vendor/syn/src/ident.rs
index 41eb72129..d0f4ba08d 100644
--- a/vendor/syn/src/ident.rs
+++ b/vendor/syn/src/ident.rs
@@ -4,10 +4,12 @@ use crate::lookahead;
pub use proc_macro2::Ident;
#[cfg(feature = "parsing")]
-#[doc(hidden)]
-#[allow(non_snake_case)]
-pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
- match marker {}
+pub_if_not_doc! {
+ #[doc(hidden)]
+ #[allow(non_snake_case)]
+ pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
+ match marker {}
+ }
}
macro_rules! ident_from_token {
diff --git a/vendor/syn/src/item.rs b/vendor/syn/src/item.rs
index 50d7e6ef6..ee91f5914 100644
--- a/vendor/syn/src/item.rs
+++ b/vendor/syn/src/item.rs
@@ -985,24 +985,35 @@ pub(crate) mod parsing {
} else {
return Err(lookahead.error());
};
+ let mut generics: Generics = input.parse()?;
let colon_token = input.parse()?;
let ty = input.parse()?;
- if input.peek(Token![;]) {
- input.parse::<Token![;]>()?;
- Ok(Item::Verbatim(verbatim::between(&begin, input)))
+ let value = if let Some(eq_token) = input.parse::<Option<Token![=]>>()? {
+ let expr: Expr = input.parse()?;
+ Some((eq_token, expr))
} else {
- Ok(Item::Const(ItemConst {
- attrs: Vec::new(),
- vis,
- const_token,
- ident,
- generics: Generics::default(),
- colon_token,
- ty,
- eq_token: input.parse()?,
- expr: input.parse()?,
- semi_token: input.parse()?,
- }))
+ None
+ };
+ generics.where_clause = input.parse()?;
+ let semi_token: Token![;] = input.parse()?;
+ match value {
+ Some((eq_token, expr))
+ if generics.lt_token.is_none() && generics.where_clause.is_none() =>
+ {
+ Ok(Item::Const(ItemConst {
+ attrs: Vec::new(),
+ vis,
+ const_token,
+ ident,
+ generics,
+ colon_token,
+ ty,
+ eq_token,
+ expr: Box::new(expr),
+ semi_token,
+ }))
+ }
+ _ => Ok(Item::Verbatim(verbatim::between(&begin, input))),
}
} else if lookahead.peek(Token![unsafe]) {
ahead.parse::<Token![unsafe]>()?;
@@ -1400,24 +1411,34 @@ pub(crate) mod parsing {
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ItemConst {
fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = input.call(Attribute::parse_outer)?;
+ let vis: Visibility = input.parse()?;
+ let const_token: Token![const] = input.parse()?;
+
+ let lookahead = input.lookahead1();
+ let ident = if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
+ input.call(Ident::parse_any)?
+ } else {
+ return Err(lookahead.error());
+ };
+
+ let colon_token: Token![:] = input.parse()?;
+ let ty: Type = input.parse()?;
+ let eq_token: Token![=] = input.parse()?;
+ let expr: Expr = input.parse()?;
+ let semi_token: Token![;] = input.parse()?;
+
Ok(ItemConst {
- attrs: input.call(Attribute::parse_outer)?,
- vis: input.parse()?,
- const_token: input.parse()?,
- ident: {
- let lookahead = input.lookahead1();
- if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
- input.call(Ident::parse_any)?
- } else {
- return Err(lookahead.error());
- }
- },
+ attrs,
+ vis,
+ const_token,
+ ident,
generics: Generics::default(),
- colon_token: input.parse()?,
- ty: input.parse()?,
- eq_token: input.parse()?,
- expr: input.parse()?,
- semi_token: input.parse()?,
+ colon_token,
+ ty: Box::new(ty),
+ eq_token,
+ expr: Box::new(expr),
+ semi_token,
})
}
}
@@ -2224,10 +2245,36 @@ pub(crate) mod parsing {
let mut item = if lookahead.peek(Token![fn]) || peek_signature(&ahead) {
input.parse().map(TraitItem::Fn)
} else if lookahead.peek(Token![const]) {
- ahead.parse::<Token![const]>()?;
+ let const_token: Token![const] = ahead.parse()?;
let lookahead = ahead.lookahead1();
if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
- input.parse().map(TraitItem::Const)
+ input.advance_to(&ahead);
+ let ident = input.call(Ident::parse_any)?;
+ let mut generics: Generics = input.parse()?;
+ let colon_token: Token![:] = input.parse()?;
+ let ty: Type = input.parse()?;
+ let default = if let Some(eq_token) = input.parse::<Option<Token![=]>>()? {
+ let expr: Expr = input.parse()?;
+ Some((eq_token, expr))
+ } else {
+ None
+ };
+ generics.where_clause = input.parse()?;
+ let semi_token: Token![;] = input.parse()?;
+ if generics.lt_token.is_none() && generics.where_clause.is_none() {
+ Ok(TraitItem::Const(TraitItemConst {
+ attrs: Vec::new(),
+ const_token,
+ ident,
+ generics,
+ colon_token,
+ ty,
+ default,
+ semi_token,
+ }))
+ } else {
+ return Ok(TraitItem::Verbatim(verbatim::between(&begin, input)));
+ }
} else if lookahead.peek(Token![async])
|| lookahead.peek(Token![unsafe])
|| lookahead.peek(Token![extern])
@@ -2273,30 +2320,36 @@ pub(crate) mod parsing {
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for TraitItemConst {
fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = input.call(Attribute::parse_outer)?;
+ let const_token: Token![const] = input.parse()?;
+
+ let lookahead = input.lookahead1();
+ let ident = if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
+ input.call(Ident::parse_any)?
+ } else {
+ return Err(lookahead.error());
+ };
+
+ let colon_token: Token![:] = input.parse()?;
+ let ty: Type = input.parse()?;
+ let default = if input.peek(Token![=]) {
+ let eq_token: Token![=] = input.parse()?;
+ let default: Expr = input.parse()?;
+ Some((eq_token, default))
+ } else {
+ None
+ };
+ let semi_token: Token![;] = input.parse()?;
+
Ok(TraitItemConst {
- attrs: input.call(Attribute::parse_outer)?,
- const_token: input.parse()?,
- ident: {
- let lookahead = input.lookahead1();
- if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
- input.call(Ident::parse_any)?
- } else {
- return Err(lookahead.error());
- }
- },
+ attrs,
+ const_token,
+ ident,
generics: Generics::default(),
- colon_token: input.parse()?,
- ty: input.parse()?,
- default: {
- if input.peek(Token![=]) {
- let eq_token: Token![=] = input.parse()?;
- let default: Expr = input.parse()?;
- Some((eq_token, default))
- } else {
- None
- }
- },
- semi_token: input.parse()?,
+ colon_token,
+ ty,
+ default,
+ semi_token,
})
}
}
@@ -2550,26 +2603,37 @@ pub(crate) mod parsing {
} else {
return Err(lookahead.error());
};
+ let mut generics: Generics = input.parse()?;
let colon_token: Token![:] = input.parse()?;
let ty: Type = input.parse()?;
- if let Some(eq_token) = input.parse()? {
- return Ok(ImplItem::Const(ImplItemConst {
- attrs,
- vis,
- defaultness,
- const_token,
- ident,
- generics: Generics::default(),
- colon_token,
- ty,
- eq_token,
- expr: input.parse()?,
- semi_token: input.parse()?,
- }));
+ let value = if let Some(eq_token) = input.parse::<Option<Token![=]>>()? {
+ let expr: Expr = input.parse()?;
+ Some((eq_token, expr))
} else {
- input.parse::<Token![;]>()?;
- return Ok(ImplItem::Verbatim(verbatim::between(&begin, input)));
- }
+ None
+ };
+ generics.where_clause = input.parse()?;
+ let semi_token: Token![;] = input.parse()?;
+ return match value {
+ Some((eq_token, expr))
+ if generics.lt_token.is_none() && generics.where_clause.is_none() =>
+ {
+ Ok(ImplItem::Const(ImplItemConst {
+ attrs,
+ vis,
+ defaultness,
+ const_token,
+ ident,
+ generics,
+ colon_token,
+ ty,
+ eq_token,
+ expr,
+ semi_token,
+ }))
+ }
+ _ => Ok(ImplItem::Verbatim(verbatim::between(&begin, input))),
+ };
} else if lookahead.peek(Token![type]) {
parse_impl_item_type(begin, input)
} else if vis.is_inherited()
@@ -2604,25 +2668,36 @@ pub(crate) mod parsing {
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ImplItemConst {
fn parse(input: ParseStream) -> Result<Self> {
+ let attrs = input.call(Attribute::parse_outer)?;
+ let vis: Visibility = input.parse()?;
+ let defaultness: Option<Token![default]> = input.parse()?;
+ let const_token: Token![const] = input.parse()?;
+
+ let lookahead = input.lookahead1();
+ let ident = if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
+ input.call(Ident::parse_any)?
+ } else {
+ return Err(lookahead.error());
+ };
+
+ let colon_token: Token![:] = input.parse()?;
+ let ty: Type = input.parse()?;
+ let eq_token: Token![=] = input.parse()?;
+ let expr: Expr = input.parse()?;
+ let semi_token: Token![;] = input.parse()?;
+
Ok(ImplItemConst {
- attrs: input.call(Attribute::parse_outer)?,
- vis: input.parse()?,
- defaultness: input.parse()?,
- const_token: input.parse()?,
- ident: {
- let lookahead = input.lookahead1();
- if lookahead.peek(Ident) || lookahead.peek(Token![_]) {
- input.call(Ident::parse_any)?
- } else {
- return Err(lookahead.error());
- }
- },
+ attrs,
+ vis,
+ defaultness,
+ const_token,
+ ident,
generics: Generics::default(),
- colon_token: input.parse()?,
- ty: input.parse()?,
- eq_token: input.parse()?,
- expr: input.parse()?,
- semi_token: input.parse()?,
+ colon_token,
+ ty,
+ eq_token,
+ expr,
+ semi_token,
})
}
}
diff --git a/vendor/syn/src/lib.rs b/vendor/syn/src/lib.rs
index 4adaa8587..a74d4b117 100644
--- a/vendor/syn/src/lib.rs
+++ b/vendor/syn/src/lib.rs
@@ -249,7 +249,7 @@
//! dynamic library libproc_macro from rustc toolchain.
// Syn types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/syn/2.0.29")]
+#![doc(html_root_url = "https://docs.rs/syn/2.0.38")]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![allow(non_camel_case_types)]
#![allow(
diff --git a/vendor/syn/src/lifetime.rs b/vendor/syn/src/lifetime.rs
index 96920ad05..29f4cfdb3 100644
--- a/vendor/syn/src/lifetime.rs
+++ b/vendor/syn/src/lifetime.rs
@@ -113,10 +113,12 @@ impl Hash for Lifetime {
}
#[cfg(feature = "parsing")]
-#[doc(hidden)]
-#[allow(non_snake_case)]
-pub fn Lifetime(marker: lookahead::TokenMarker) -> Lifetime {
- match marker {}
+pub_if_not_doc! {
+ #[doc(hidden)]
+ #[allow(non_snake_case)]
+ pub fn Lifetime(marker: lookahead::TokenMarker) -> Lifetime {
+ match marker {}
+ }
}
#[cfg(feature = "parsing")]
diff --git a/vendor/syn/src/lit.rs b/vendor/syn/src/lit.rs
index 4f36cf50b..f7426ce81 100644
--- a/vendor/syn/src/lit.rs
+++ b/vendor/syn/src/lit.rs
@@ -758,10 +758,12 @@ macro_rules! lit_extra_traits {
}
#[cfg(feature = "parsing")]
- #[doc(hidden)]
- #[allow(non_snake_case)]
- pub fn $ty(marker: lookahead::TokenMarker) -> $ty {
- match marker {}
+ pub_if_not_doc! {
+ #[doc(hidden)]
+ #[allow(non_snake_case)]
+ pub fn $ty(marker: lookahead::TokenMarker) -> $ty {
+ match marker {}
+ }
}
};
}
@@ -774,10 +776,12 @@ lit_extra_traits!(LitInt);
lit_extra_traits!(LitFloat);
#[cfg(feature = "parsing")]
-#[doc(hidden)]
-#[allow(non_snake_case)]
-pub fn LitBool(marker: lookahead::TokenMarker) -> LitBool {
- match marker {}
+pub_if_not_doc! {
+ #[doc(hidden)]
+ #[allow(non_snake_case)]
+ pub fn LitBool(marker: lookahead::TokenMarker) -> LitBool {
+ match marker {}
+ }
}
ast_enum! {
@@ -794,10 +798,12 @@ ast_enum! {
}
#[cfg(feature = "parsing")]
-#[doc(hidden)]
-#[allow(non_snake_case)]
-pub fn Lit(marker: lookahead::TokenMarker) -> Lit {
- match marker {}
+pub_if_not_doc! {
+ #[doc(hidden)]
+ #[allow(non_snake_case)]
+ pub fn Lit(marker: lookahead::TokenMarker) -> Lit {
+ match marker {}
+ }
}
#[cfg(feature = "parsing")]
@@ -1089,6 +1095,7 @@ mod value {
// c"...", cr"...", cr#"..."#
// TODO: add a Lit::CStr variant?
b'c' => return Lit::Verbatim(token),
+ b'(' if repr == "(/*ERROR*/)" => return Lit::Verbatim(token),
_ => {}
}
diff --git a/vendor/syn/src/macros.rs b/vendor/syn/src/macros.rs
index 953841b6f..06ceb542d 100644
--- a/vendor/syn/src/macros.rs
+++ b/vendor/syn/src/macros.rs
@@ -166,3 +166,20 @@ macro_rules! check_keyword_matches {
(enum enum) => {};
(pub pub) => {};
}
+
+// Rustdoc bug: does not respect the doc(hidden) on some items.
+#[cfg(all(doc, feature = "parsing"))]
+macro_rules! pub_if_not_doc {
+ ($(#[$m:meta])* pub $($item:tt)*) => {
+ $(#[$m])*
+ pub(crate) $($item)*
+ };
+}
+
+#[cfg(all(not(doc), feature = "parsing"))]
+macro_rules! pub_if_not_doc {
+ ($(#[$m:meta])* pub $($item:tt)*) => {
+ $(#[$m])*
+ pub $($item)*
+ };
+}
diff --git a/vendor/syn/src/path.rs b/vendor/syn/src/path.rs
index 883f179f5..b9d96e669 100644
--- a/vendor/syn/src/path.rs
+++ b/vendor/syn/src/path.rs
@@ -82,6 +82,19 @@ impl Path {
None
}
}
+
+ /// An error if this path is not a single ident, as defined in `get_ident`.
+ #[cfg(feature = "parsing")]
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ pub fn require_ident(&self) -> Result<&Ident> {
+ self.get_ident().ok_or_else(|| {
+ crate::error::new2(
+ self.segments.first().unwrap().ident.span(),
+ self.segments.last().unwrap().ident.span(),
+ "expected this path to be an identifier",
+ )
+ })
+ }
}
ast_struct! {
diff --git a/vendor/syn/src/token.rs b/vendor/syn/src/token.rs
index c7e0e1f1a..af7f25c42 100644
--- a/vendor/syn/src/token.rs
+++ b/vendor/syn/src/token.rs
@@ -143,6 +143,7 @@ mod private {
/// Support writing `token.span` rather than `token.spans[0]` on tokens that
/// hold a single span.
#[repr(transparent)]
+ #[allow(unknown_lints, repr_transparent_external_private_fields)] // False positive: https://github.com/rust-lang/rust/issues/78586#issuecomment-1722680482
pub struct WithSpan {
pub span: Span,
}
@@ -365,6 +366,7 @@ macro_rules! define_punctuation_structs {
($($token:literal pub struct $name:ident/$len:tt #[doc = $usage:literal])*) => {
$(
#[cfg_attr(not(doc), repr(transparent))]
+ #[allow(unknown_lints, repr_transparent_external_private_fields)] // False positive: https://github.com/rust-lang/rust/issues/78586#issuecomment-1722680482
#[doc = concat!('`', $token, '`')]
///
/// Usage:
@@ -840,6 +842,67 @@ define_delimiters! {
/// A type-macro that expands to the name of the Rust type representation of a
/// given token.
///
+/// As a type, `Token!` is commonly used in the type of struct fields, the type
+/// of a `let` statement, or in turbofish for a `parse` function.
+///
+/// ```
+/// use syn::{Ident, Token};
+/// use syn::parse::{Parse, ParseStream, Result};
+///
+/// // `struct Foo;`
+/// pub struct UnitStruct {
+/// struct_token: Token![struct],
+/// ident: Ident,
+/// semi_token: Token![;],
+/// }
+///
+/// impl Parse for UnitStruct {
+/// fn parse(input: ParseStream) -> Result<Self> {
+/// let struct_token: Token![struct] = input.parse()?;
+/// let ident: Ident = input.parse()?;
+/// let semi_token = input.parse::<Token![;]>()?;
+/// Ok(UnitStruct { struct_token, ident, semi_token })
+/// }
+/// }
+/// ```
+///
+/// As an expression, `Token!` is used for peeking tokens or instantiating
+/// tokens from a span.
+///
+/// ```
+/// # use syn::{Ident, Token};
+/// # use syn::parse::{Parse, ParseStream, Result};
+/// #
+/// # struct UnitStruct {
+/// # struct_token: Token![struct],
+/// # ident: Ident,
+/// # semi_token: Token![;],
+/// # }
+/// #
+/// # impl Parse for UnitStruct {
+/// # fn parse(input: ParseStream) -> Result<Self> {
+/// # unimplemented!()
+/// # }
+/// # }
+/// #
+/// fn make_unit_struct(name: Ident) -> UnitStruct {
+/// let span = name.span();
+/// UnitStruct {
+/// struct_token: Token![struct](span),
+/// ident: name,
+/// semi_token: Token![;](span),
+/// }
+/// }
+///
+/// # fn parse(input: ParseStream) -> Result<()> {
+/// if input.peek(Token![struct]) {
+/// let unit_struct: UnitStruct = input.parse()?;
+/// /* ... */
+/// }
+/// # Ok(())
+/// # }
+/// ```
+///
/// See the [token module] documentation for details and examples.
///
/// [token module]: crate::token