summaryrefslogtreecommitdiffstats
path: root/vendor/syn/src/data.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/syn/src/data.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn/src/data.rs')
-rw-r--r--vendor/syn/src/data.rs211
1 files changed, 7 insertions, 204 deletions
diff --git a/vendor/syn/src/data.rs b/vendor/syn/src/data.rs
index 3b466618f..185f88ba0 100644
--- a/vendor/syn/src/data.rs
+++ b/vendor/syn/src/data.rs
@@ -3,12 +3,8 @@ use crate::punctuated::Punctuated;
ast_struct! {
/// An enum variant.
- ///
- /// *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 Variant {
- /// Attributes tagged on the variant.
pub attrs: Vec<Attribute>,
/// Name of the variant.
@@ -25,9 +21,6 @@ ast_struct! {
ast_enum_of_structs! {
/// Data stored within an enum variant or struct.
///
- /// *This type is available only if Syn is built with the `"derive"` or `"full"`
- /// feature.*
- ///
/// # Syntax tree enum
///
/// This type is a [syntax tree enum].
@@ -50,9 +43,6 @@ ast_enum_of_structs! {
ast_struct! {
/// Named fields of a struct or struct variant such as `Point { x: f64,
/// y: f64 }`.
- ///
- /// *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 FieldsNamed {
pub brace_token: token::Brace,
@@ -62,9 +52,6 @@ ast_struct! {
ast_struct! {
/// Unnamed fields of a tuple struct or tuple variant such as `Some(T)`.
- ///
- /// *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 FieldsUnnamed {
pub paren_token: token::Paren,
@@ -147,17 +134,14 @@ impl<'a> IntoIterator for &'a mut Fields {
ast_struct! {
/// A field of a struct or enum variant.
- ///
- /// *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 Field {
- /// Attributes tagged on the field.
pub attrs: Vec<Attribute>,
- /// Visibility of the field.
pub vis: Visibility,
+ pub mutability: FieldMutability,
+
/// Name of the field, if any.
///
/// Fields of tuple structs have no names.
@@ -165,82 +149,14 @@ ast_struct! {
pub colon_token: Option<Token![:]>,
- /// Type of the field.
pub ty: Type,
}
}
-ast_enum_of_structs! {
- /// The visibility level of an item: inherited or `pub` or
- /// `pub(restricted)`.
- ///
- /// *This type is available only if Syn is built with the `"derive"` or `"full"`
- /// feature.*
- ///
- /// # Syntax tree enum
- ///
- /// This type is a [syntax tree enum].
- ///
- /// [syntax tree enum]: Expr#syntax-tree-enums
- #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
- pub enum Visibility {
- /// A public visibility level: `pub`.
- Public(VisPublic),
-
- /// A crate-level visibility: `crate`.
- Crate(VisCrate),
-
- /// A visibility level restricted to some path: `pub(self)` or
- /// `pub(super)` or `pub(crate)` or `pub(in some::module)`.
- Restricted(VisRestricted),
-
- /// An inherited visibility, which usually means private.
- Inherited,
- }
-}
-
-ast_struct! {
- /// A public visibility level: `pub`.
- ///
- /// *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 VisPublic {
- pub pub_token: Token![pub],
- }
-}
-
-ast_struct! {
- /// A crate-level visibility: `crate`.
- ///
- /// *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 VisCrate {
- pub crate_token: Token![crate],
- }
-}
-
-ast_struct! {
- /// A visibility level restricted to some path: `pub(self)` or
- /// `pub(super)` or `pub(crate)` or `pub(in some::module)`.
- ///
- /// *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 VisRestricted {
- pub pub_token: Token![pub],
- pub paren_token: token::Paren,
- pub in_token: Option<Token![in]>,
- pub path: Box<Path>,
- }
-}
-
#[cfg(feature = "parsing")]
-pub mod parsing {
+pub(crate) mod parsing {
use super::*;
use crate::ext::IdentExt;
- use crate::parse::discouraged::Speculative;
use crate::parse::{Parse, ParseStream, Result};
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
@@ -278,7 +194,7 @@ pub mod parsing {
let content;
Ok(FieldsNamed {
brace_token: braced!(content in input),
- named: content.parse_terminated(Field::parse_named)?,
+ named: content.parse_terminated(Field::parse_named, Token![,])?,
})
}
}
@@ -289,7 +205,7 @@ pub mod parsing {
let content;
Ok(FieldsUnnamed {
paren_token: parenthesized!(content in input),
- unnamed: content.parse_terminated(Field::parse_unnamed)?,
+ unnamed: content.parse_terminated(Field::parse_unnamed, Token![,])?,
})
}
}
@@ -301,6 +217,7 @@ pub mod parsing {
Ok(Field {
attrs: input.call(Attribute::parse_outer)?,
vis: input.parse()?,
+ mutability: FieldMutability::None,
ident: Some(if input.peek(Token![_]) {
input.call(Ident::parse_any)
} else {
@@ -317,100 +234,13 @@ pub mod parsing {
Ok(Field {
attrs: input.call(Attribute::parse_outer)?,
vis: input.parse()?,
+ mutability: FieldMutability::None,
ident: None,
colon_token: None,
ty: input.parse()?,
})
}
}
-
- #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
- impl Parse for Visibility {
- fn parse(input: ParseStream) -> Result<Self> {
- // Recognize an empty None-delimited group, as produced by a $:vis
- // matcher that matched no tokens.
- if input.peek(token::Group) {
- let ahead = input.fork();
- let group = crate::group::parse_group(&ahead)?;
- if group.content.is_empty() {
- input.advance_to(&ahead);
- return Ok(Visibility::Inherited);
- }
- }
-
- if input.peek(Token![pub]) {
- Self::parse_pub(input)
- } else if input.peek(Token![crate]) {
- Self::parse_crate(input)
- } else {
- Ok(Visibility::Inherited)
- }
- }
- }
-
- impl Visibility {
- fn parse_pub(input: ParseStream) -> Result<Self> {
- let pub_token = input.parse::<Token![pub]>()?;
-
- if input.peek(token::Paren) {
- let ahead = input.fork();
-
- let content;
- let paren_token = parenthesized!(content in ahead);
- if content.peek(Token![crate])
- || content.peek(Token![self])
- || content.peek(Token![super])
- {
- let path = content.call(Ident::parse_any)?;
-
- // Ensure there are no additional tokens within `content`.
- // Without explicitly checking, we may misinterpret a tuple
- // field as a restricted visibility, causing a parse error.
- // e.g. `pub (crate::A, crate::B)` (Issue #720).
- if content.is_empty() {
- input.advance_to(&ahead);
- return Ok(Visibility::Restricted(VisRestricted {
- pub_token,
- paren_token,
- in_token: None,
- path: Box::new(Path::from(path)),
- }));
- }
- } else if content.peek(Token![in]) {
- let in_token: Token![in] = content.parse()?;
- let path = content.call(Path::parse_mod_style)?;
-
- input.advance_to(&ahead);
- return Ok(Visibility::Restricted(VisRestricted {
- pub_token,
- paren_token,
- in_token: Some(in_token),
- path: Box::new(path),
- }));
- }
- }
-
- Ok(Visibility::Public(VisPublic { pub_token }))
- }
-
- fn parse_crate(input: ParseStream) -> Result<Self> {
- if input.peek2(Token![::]) {
- Ok(Visibility::Inherited)
- } else {
- Ok(Visibility::Crate(VisCrate {
- crate_token: input.parse()?,
- }))
- }
- }
-
- #[cfg(feature = "full")]
- pub(crate) fn is_some(&self) -> bool {
- match self {
- Visibility::Inherited => false,
- _ => true,
- }
- }
- }
}
#[cfg(feature = "printing")]
@@ -463,31 +293,4 @@ mod printing {
self.ty.to_tokens(tokens);
}
}
-
- #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
- impl ToTokens for VisPublic {
- fn to_tokens(&self, tokens: &mut TokenStream) {
- self.pub_token.to_tokens(tokens);
- }
- }
-
- #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
- impl ToTokens for VisCrate {
- fn to_tokens(&self, tokens: &mut TokenStream) {
- self.crate_token.to_tokens(tokens);
- }
- }
-
- #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
- impl ToTokens for VisRestricted {
- fn to_tokens(&self, tokens: &mut TokenStream) {
- self.pub_token.to_tokens(tokens);
- self.paren_token.surround(tokens, |tokens| {
- // TODO: If we have a path which is not "self" or "super" or
- // "crate", automatically add the "in" token.
- self.in_token.to_tokens(tokens);
- self.path.to_tokens(tokens);
- });
- }
- }
}