/// Data structure sent to a `proc_macro_derive` macro.
///
/// *This type is available only if Syn is built with the `"derive"` feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
pub struct DeriveInput {
/// Attributes tagged on the whole struct or enum.
pub attrs: Vec<Attribute>,
///
/// This type is a [syntax tree enum].
///
- /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
- //
- // TODO: change syntax-tree-enum link to an intra rustdoc link, currently
- // blocked on https://github.com/rust-lang/rust/issues/62833
+ /// [syntax tree enum]: Expr#syntax-tree-enums
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
pub enum Data {
/// A struct input to a `proc_macro_derive` macro.
Struct(DataStruct),
///
/// *This type is available only if Syn is built with the `"derive"`
/// feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
pub struct DataStruct {
pub struct_token: Token![struct],
pub fields: Fields,
///
/// *This type is available only if Syn is built with the `"derive"`
/// feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
pub struct DataEnum {
pub enum_token: Token![enum],
pub brace_token: token::Brace,
///
/// *This type is available only if Syn is built with the `"derive"`
/// feature.*
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
pub struct DataUnion {
pub union_token: Token![union],
pub fields: FieldsNamed,
use super::*;
use crate::parse::{Parse, ParseStream, Result};
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for DeriveInput {
fn parse(input: ParseStream) -> Result<Self> {
- let attrs = input.call(Attribute::parse_outer)?;
+ let mut attrs = input.call(Attribute::parse_outer)?;
let vis = input.parse::<Visibility>()?;
let lookahead = input.lookahead1();
let struct_token = input.parse::<Token![struct]>()?;
let ident = input.parse::<Ident>()?;
let generics = input.parse::<Generics>()?;
- let (where_clause, fields, semi) = data_struct(input)?;
+ let (where_clause, fields, semi) = data_struct(input, &mut attrs)?;
Ok(DeriveInput {
attrs,
vis,
let enum_token = input.parse::<Token![enum]>()?;
let ident = input.parse::<Ident>()?;
let generics = input.parse::<Generics>()?;
- let (where_clause, brace, variants) = data_enum(input)?;
+ let (where_clause, brace, variants) = data_enum(input, &mut attrs)?;
Ok(DeriveInput {
attrs,
vis,
let union_token = input.parse::<Token![union]>()?;
let ident = input.parse::<Ident>()?;
let generics = input.parse::<Generics>()?;
- let (where_clause, fields) = data_union(input)?;
+ let (where_clause, fields) = data_union(input, &mut attrs)?;
Ok(DeriveInput {
attrs,
vis,
pub fn data_struct(
input: ParseStream,
+ attrs: &mut Vec<Attribute>,
) -> Result<(Option<WhereClause>, Fields, Option<Token![;]>)> {
let mut lookahead = input.lookahead1();
let mut where_clause = None;
Err(lookahead.error())
}
} else if lookahead.peek(token::Brace) {
- let fields = input.parse()?;
+ let fields = data::parsing::parse_braced(input, attrs)?;
Ok((where_clause, Fields::Named(fields), None))
} else if lookahead.peek(Token![;]) {
let semi = input.parse()?;
pub fn data_enum(
input: ParseStream,
+ attrs: &mut Vec<Attribute>,
) -> Result<(
Option<WhereClause>,
token::Brace,
let content;
let brace = braced!(content in input);
+ attr::parsing::parse_inner(&content, attrs)?;
let variants = content.parse_terminated(Variant::parse)?;
Ok((where_clause, brace, variants))
}
- pub fn data_union(input: ParseStream) -> Result<(Option<WhereClause>, FieldsNamed)> {
+ pub fn data_union(
+ input: ParseStream,
+ attrs: &mut Vec<Attribute>,
+ ) -> Result<(Option<WhereClause>, FieldsNamed)> {
let where_clause = input.parse()?;
- let fields = input.parse()?;
+ let fields = data::parsing::parse_braced(input, attrs)?;
Ok((where_clause, fields))
}
}
use proc_macro2::TokenStream;
use quote::ToTokens;
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
impl ToTokens for DeriveInput {
fn to_tokens(&self, tokens: &mut TokenStream) {
for attr in self.attrs.outer() {