Skip to content

Commit

Permalink
Document what feature everything requires
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 7, 2018
1 parent 614a014 commit 461d98e
Show file tree
Hide file tree
Showing 21 changed files with 586 additions and 4 deletions.
6 changes: 6 additions & 0 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,8 @@ use gen::helper::fold::*;
/// See the [module documentation] for details.
///
/// [module documentation]: index.html
///
/// *This trait is available if Syn is built with the `\"fold\"` feature.*
pub trait Fold {{
{fold_trait}
}}
Expand Down Expand Up @@ -1086,6 +1088,8 @@ use gen::helper::visit::*;
/// See the [module documentation] for details.
///
/// [module documentation]: index.html
///
/// *This trait is available if Syn is built with the `\"visit\"` feature.*
pub trait Visit<'ast> {{
{visit_trait}
}}
Expand Down Expand Up @@ -1122,6 +1126,8 @@ use gen::helper::visit_mut::*;
/// See the [module documentation] for details.
///
/// [module documentation]: index.html
///
/// *This trait is available if Syn is built with the `\"visit-mut\"` feature.*
pub trait VisitMut {{
{visit_mut_trait}
}}
Expand Down
18 changes: 18 additions & 0 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use tt::TokenStreamHelper;
ast_struct! {
/// An attribute like `#[repr(transparent)]`.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// # Syntax
///
/// Rust has six types of attributes.
Expand Down Expand Up @@ -225,6 +228,9 @@ ast_enum! {
/// Distinguishes between attributes that decorate an item and attributes
/// that are contained within an item.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// # Outer attributes
///
/// - `#[repr(transparent)]`
Expand All @@ -246,6 +252,9 @@ ast_enum! {
ast_enum_of_structs! {
/// Content of a compile-time structured attribute.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// ## Word
///
/// A meta word is like the `test` in `#[test]`.
Expand All @@ -267,12 +276,18 @@ ast_enum_of_structs! {
pub enum Meta {
pub Word(Ident),
/// A structured list within an attribute, like `derive(Copy, Clone)`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub List(MetaList {
pub ident: Ident,
pub paren_token: token::Paren,
pub nested: Punctuated<NestedMeta, Token![,]>,
}),
/// A name-value pair within an attribute, like `feature = "nightly"`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub NameValue(MetaNameValue {
pub ident: Ident,
pub eq_token: Token![=],
Expand All @@ -297,6 +312,9 @@ impl Meta {

ast_enum_of_structs! {
/// Element of a compile-time attribute list.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
pub enum NestedMeta {
/// A structured meta item, like the `Copy` in `#[derive(Copy)]` which
/// would be a nested `Meta::Word`.
Expand Down
6 changes: 6 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//!
//! [`Synom`]: ../synom/trait.Synom.html
//!
//! *This module is available if Syn is built with the `"parsing"` feature.*
//!
//! # Example
//!
//! This example shows a basic token parser for parsing a token stream without
Expand Down Expand Up @@ -154,6 +156,8 @@ enum Entry {
/// See the [module documentation] for an example of `TokenBuffer` in action.
///
/// [module documentation]: index.html
///
/// *This type is available if Syn is built with the `"parsing"` feature.*
pub struct TokenBuffer {
// NOTE: Do not derive clone on this - there are raw pointers inside which
// will be messed up. Moving the `TokenBuffer` itself is safe as the actual
Expand Down Expand Up @@ -246,6 +250,8 @@ impl TokenBuffer {
/// See the [module documentation] for an example of a `Cursor` in action.
///
/// [module documentation]: index.html
///
/// *This type is available if Syn is built with the `"parsing"` feature.*
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Cursor<'a> {
/// The current entry which the `Cursor` is pointing at.
Expand Down
27 changes: 27 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use punctuated::Punctuated;

ast_struct! {
/// An enum variant.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
pub struct Variant {
/// Attributes tagged on the variant.
pub attrs: Vec<Attribute>,
Expand All @@ -29,6 +32,9 @@ ast_struct! {
ast_enum_of_structs! {
/// Data stored within an enum variant or struct.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// # Syntax tree enum
///
/// This type is a [syntax tree enum].
Expand All @@ -37,12 +43,18 @@ ast_enum_of_structs! {
pub enum Fields {
/// Named fields of a struct or struct variant such as `Point { x: f64,
/// y: f64 }`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub Named(FieldsNamed {
pub brace_token: token::Brace,
pub named: Punctuated<Field, Token![,]>,
}),

/// Unnamed fields of a tuple struct or tuple variant such as `Some(T)`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub Unnamed(FieldsUnnamed {
pub paren_token: token::Paren,
pub unnamed: Punctuated<Field, Token![,]>,
Expand All @@ -55,6 +67,9 @@ ast_enum_of_structs! {

ast_struct! {
/// A field of a struct or enum variant.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
pub struct Field {
/// Attributes tagged on the field.
pub attrs: Vec<Attribute>,
Expand All @@ -78,18 +93,27 @@ ast_enum_of_structs! {
/// The visibility level of an item: inherited or `pub` or
/// `pub(restricted)`.
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// # Syntax tree enum
///
/// This type is a [syntax tree enum].
///
/// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
pub enum Visibility {
/// A public visibility level: `pub`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub Public(VisPublic {
pub pub_token: Token![pub],
}),

/// A crate-level visibility: `pub(crate)`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub Crate(VisCrate {
pub pub_token: Token![pub],
pub paren_token: token::Paren,
Expand All @@ -98,6 +122,9 @@ ast_enum_of_structs! {

/// A visibility level restricted to some path: `pub(self)` or
/// `pub(super)` or `pub(in some::module)`.
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
pub Restricted(VisRestricted {
pub pub_token: Token![pub],
pub paren_token: token::Paren,
Expand Down
13 changes: 13 additions & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use punctuated::Punctuated;

ast_struct! {
/// Data structure sent to a `proc_macro_derive` macro.
///
/// *This type is available if Syn is built with the `"derive"` feature.*
pub struct DeriveInput {
/// Attributes tagged on the whole struct or enum.
pub attrs: Vec<Attribute>,
Expand All @@ -32,27 +34,38 @@ ast_struct! {
ast_enum_of_structs! {
/// The storage of a struct, enum or union data structure.
///
/// *This type is available if Syn is built with the `"derive"` feature.*
///
/// # Syntax tree enum
///
/// This type is a [syntax tree enum].
///
/// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
pub enum Data {
/// A struct input to a `proc_macro_derive` macro.
///
/// *This type is available if Syn is built with the `"derive"`
/// feature.*
pub Struct(DataStruct {
pub struct_token: Token![struct],
pub fields: Fields,
pub semi_token: Option<Token![;]>,
}),

/// An enum input to a `proc_macro_derive` macro.
///
/// *This type is available if Syn is built with the `"derive"`
/// feature.*
pub Enum(DataEnum {
pub enum_token: Token![enum],
pub brace_token: token::Brace,
pub variants: Punctuated<Variant, Token![,]>,
}),

/// A tagged union input to a `proc_macro_derive` macro.
///
/// *This type is available if Syn is built with the `"derive"`
/// feature.*
pub Union(DataUnion {
pub union_token: Token![union],
pub fields: FieldsNamed,
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::fmt::{self, Display};
/// Refer to the [module documentation] for details about parsing in Syn.
///
/// [module documentation]: index.html
///
/// *This type is available if Syn is built with the `"parsing"` feature.*
pub type PResult<'a, O> = Result<(O, Cursor<'a>), ParseError>;

/// An error with a default error message.
Expand All @@ -29,6 +31,8 @@ pub fn parse_error<O>() -> PResult<'static, O> {
/// Refer to the [module documentation] for details about parsing in Syn.
///
/// [module documentation]: index.html
///
/// *This type is available if Syn is built with the `"parsing"` feature.*
#[derive(Debug)]
pub struct ParseError(Option<String>);

Expand Down
Loading

0 comments on commit 461d98e

Please sign in to comment.