Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply #[doc(cfg(feature = "..."))] banners in docs #734

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ required-features = ["full", "parsing"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "syn_enable_doc_cfg"]

[package.metadata.playground]
all-features = true
Expand Down
33 changes: 33 additions & 0 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ ast_struct! {
/// };
/// assert_eq!(doc, attr);
/// ```
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct Attribute #manual_extra_traits {
pub pound_token: Token![#],
pub style: AttrStyle,
Expand Down Expand Up @@ -192,6 +196,7 @@ impl Attribute {
/// *This function is available if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_meta(&self) -> Result<Meta> {
fn clone_ident_segment(segment: &PathSegment) -> PathSegment {
PathSegment {
Expand Down Expand Up @@ -239,6 +244,7 @@ impl Attribute {
/// *This function is available if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_args<T: Parse>(&self) -> Result<T> {
self.parse_args_with(T::parse)
}
Expand All @@ -248,6 +254,7 @@ impl Attribute {
/// *This function is available if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_args_with<F: Parser>(&self, parser: F) -> Result<F::Output> {
let parser = |input: ParseStream| {
let args = enter_args(self, input)?;
Expand All @@ -261,6 +268,7 @@ impl Attribute {
/// *This function is available if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
let mut attrs = Vec::new();
while input.peek(Token![#]) {
Expand All @@ -274,6 +282,7 @@ impl Attribute {
/// *This function is available if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "parsing")))]
pub fn parse_inner(input: ParseStream) -> Result<Vec<Self>> {
let mut attrs = Vec::new();
while input.peek(Token![#]) && input.peek2(Token![!]) {
Expand Down Expand Up @@ -349,6 +358,10 @@ ast_enum! {
/// - `#![feature(proc_macro)]`
/// - `//! # Example`
/// - `/*! Please file an issue */`
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
#[cfg_attr(feature = "clone-impls", derive(Copy))]
pub enum AttrStyle {
Outer,
Expand Down Expand Up @@ -383,6 +396,10 @@ ast_enum_of_structs! {
//
// TODO: change syntax-tree-enum link to an intra rustdoc link, currently
// blocked on https://github.com/rust-lang/rust/issues/62833
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub enum Meta {
Path(Path),

Expand All @@ -399,6 +416,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct MetaList {
pub path: Path,
pub paren_token: token::Paren,
Expand All @@ -411,6 +432,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct MetaNameValue {
pub path: Path,
pub eq_token: Token![=],
Expand All @@ -437,6 +462,10 @@ ast_enum_of_structs! {
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub enum NestedMeta {
/// A structured meta item, like the `Copy` in `#[derive(Copy)]` which
/// would be a nested `Meta::Path`.
Expand Down Expand Up @@ -482,6 +511,10 @@ ast_enum_of_structs! {
/// # "".parse().unwrap()
/// }
/// ```
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub type AttributeArgs = Vec<NestedMeta>;

pub trait FilterAttrs<'a> {
Expand Down
36 changes: 36 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct Variant {
/// Attributes tagged on the variant.
pub attrs: Vec<Attribute>,
Expand Down Expand Up @@ -35,6 +39,10 @@ ast_enum_of_structs! {
//
// TODO: change syntax-tree-enum link to an intra rustdoc link, currently
// blocked on https://github.com/rust-lang/rust/issues/62833
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub enum Fields {
/// Named fields of a struct or struct variant such as `Point { x: f64,
/// y: f64 }`.
Expand All @@ -54,6 +62,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct FieldsNamed {
pub brace_token: token::Brace,
pub named: Punctuated<Field, Token![,]>,
Expand All @@ -65,6 +77,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct FieldsUnnamed {
pub paren_token: token::Paren,
pub unnamed: Punctuated<Field, Token![,]>,
Expand Down Expand Up @@ -149,6 +165,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct Field {
/// Attributes tagged on the field.
pub attrs: Vec<Attribute>,
Expand Down Expand Up @@ -183,6 +203,10 @@ ast_enum_of_structs! {
//
// TODO: change syntax-tree-enum link to an intra rustdoc link, currently
// blocked on https://github.com/rust-lang/rust/issues/62833
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub enum Visibility {
/// A public visibility level: `pub`.
Public(VisPublic),
Expand All @@ -204,6 +228,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct VisPublic {
pub pub_token: Token![pub],
}
Expand All @@ -214,6 +242,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct VisCrate {
pub crate_token: Token![crate],
}
Expand All @@ -225,6 +257,10 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(
syn_enable_doc_cfg,
doc(cfg(any(feature = "derive", feature = "full")))
)]
pub struct VisRestricted {
pub pub_token: Token![pub],
pub paren_token: token::Paren,
Expand Down
5 changes: 5 additions & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ast_struct! {
/// Data structure sent to a `proc_macro_derive` macro.
///
/// *This type is available if Syn is built with the `"derive"` feature.*
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "derive")))]
pub struct DeriveInput {
/// Attributes tagged on the whole struct or enum.
pub attrs: Vec<Attribute>,
Expand Down Expand Up @@ -36,6 +37,7 @@ ast_enum_of_structs! {
//
// TODO: change syntax-tree-enum link to an intra rustdoc link, currently
// blocked on https://github.com/rust-lang/rust/issues/62833
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "derive")))]
pub enum Data {
/// A struct input to a `proc_macro_derive` macro.
Struct(DataStruct),
Expand All @@ -55,6 +57,7 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"`
/// feature.*
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "derive")))]
pub struct DataStruct {
pub struct_token: Token![struct],
pub fields: Fields,
Expand All @@ -67,6 +70,7 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"`
/// feature.*
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "derive")))]
pub struct DataEnum {
pub enum_token: Token![enum],
pub brace_token: token::Brace,
Expand All @@ -79,6 +83,7 @@ ast_struct! {
///
/// *This type is available if Syn is built with the `"derive"`
/// feature.*
#[cfg_attr(syn_enable_doc_cfg, doc(cfg(feature = "derive")))]
pub struct DataUnion {
pub union_token: Token![union],
pub fields: FieldsNamed,
Expand Down
Loading