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

Use doc_cfg feature on docs.rs #837

Closed
wants to merge 1 commit 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 @@ -64,6 +64,7 @@ required-features = ["full", "parsing"]
[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
features = ["full", "visit", "visit-mut", "fold", "extra-traits"]
Expand Down
46 changes: 11 additions & 35 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ use std::hash::{Hash, Hasher};
ast_struct! {
/// An attribute like `#[repr(transparent)]`.
///
/// *This type is available only if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// <br>
///
/// # Syntax
///
/// Rust has six types of attributes.
Expand Down Expand Up @@ -148,6 +143,7 @@ ast_struct! {
/// };
/// assert_eq!(doc, attr);
/// ```
#[cfg_attr(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct Attribute #manual_extra_traits {
pub pound_token: Token![#],
pub style: AttrStyle,
Expand Down Expand Up @@ -188,10 +184,8 @@ impl Hash for Attribute {
impl Attribute {
/// Parses the content of the attribute, consisting of the path and tokens,
/// as a [`Meta`] if possible.
///
/// *This function is available only if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_meta(&self) -> Result<Meta> {
fn clone_ident_segment(segment: &PathSegment) -> PathSegment {
PathSegment {
Expand Down Expand Up @@ -235,19 +229,15 @@ impl Attribute {
/// #[my_attr(value < 5)]
/// ^^^^^^^^^ what gets parsed
/// ```
///
/// *This function is available only if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_args<T: Parse>(&self) -> Result<T> {
self.parse_args_with(T::parse)
}

/// Parse the arguments to the attribute using the given parser.
///
/// *This function is available only if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(docsrs, 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 @@ -257,10 +247,8 @@ impl Attribute {
}

/// Parses zero or more outer attributes from the stream.
///
/// *This function is available only if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
let mut attrs = Vec::new();
while input.peek(Token![#]) && !input.peek(token::Group) {
Expand All @@ -270,10 +258,8 @@ impl Attribute {
}

/// Parses zero or more inner attributes from the stream.
///
/// *This function is available only if Syn is built with the `"parsing"`
/// feature.*
#[cfg(feature = "parsing")]
#[cfg_attr(docsrs, 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![!]) && !input.peek(token::Group) {
Expand Down Expand Up @@ -339,9 +325,6 @@ ast_enum! {
/// Distinguishes between attributes that decorate an item and attributes
/// that are contained within an item.
///
/// *This type is available only if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// # Outer attributes
///
/// - `#[repr(transparent)]`
Expand All @@ -354,6 +337,7 @@ ast_enum! {
/// - `//! # Example`
/// - `/*! Please file an issue */`
#[cfg_attr(feature = "clone-impls", derive(Copy))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub enum AttrStyle {
Outer,
Inner(Token![!]),
Expand All @@ -363,9 +347,6 @@ ast_enum! {
ast_enum_of_structs! {
/// Content of a compile-time structured attribute.
///
/// *This type is available only if Syn is built with the `"derive"` or `"full"`
/// feature.*
///
/// ## Path
///
/// A meta path is like the `test` in `#[test]`.
Expand All @@ -387,6 +368,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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub enum Meta {
Path(Path),

Expand All @@ -400,9 +382,7 @@ ast_enum_of_structs! {

ast_struct! {
/// A structured list within an attribute, like `derive(Copy, Clone)`.
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct MetaList {
pub path: Path,
pub paren_token: token::Paren,
Expand All @@ -412,9 +392,7 @@ ast_struct! {

ast_struct! {
/// A name-value pair within an attribute, like `feature = "nightly"`.
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct MetaNameValue {
pub path: Path,
pub eq_token: Token![=],
Expand All @@ -438,9 +416,7 @@ impl Meta {

ast_enum_of_structs! {
/// Element of a compile-time attribute list.
///
/// *This type is available only if Syn is built with the `"derive"` or `"full"`
/// feature.*
#[cfg_attr(docsrs, 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
14 changes: 5 additions & 9 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A stably addressed token buffer supporting efficient traversal based on a
//! cheaply copyable cursor.
//!
//! *This module is available only if Syn is built with the `"parsing"` feature.*

#![cfg_attr(docsrs, doc(cfg(feature = "parsing")))]

// This module is heavily commented as it contains most of the unsafe code in
// Syn, and caution should be used when editing it. The public-facing interface
Expand Down Expand Up @@ -35,8 +35,7 @@ enum Entry {
/// A buffer that can be efficiently traversed multiple times, unlike
/// `TokenStream` which requires a deep copy in order to traverse more than
/// once.
///
/// *This type is available only if Syn is built with the `"parsing"` feature.*
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
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 @@ -97,13 +96,11 @@ impl TokenBuffer {

/// Creates a `TokenBuffer` containing all the tokens from the input
/// `TokenStream`.
///
/// *This method is available only if Syn is built with both the `"parsing"` and
/// `"proc-macro"` features.*
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "parsing", feature = "proc-macro"))))]
pub fn new(stream: pm::TokenStream) -> TokenBuffer {
Self::new2(stream.into())
}
Expand Down Expand Up @@ -132,9 +129,8 @@ impl TokenBuffer {
///
/// Two cursors are equal if they have the same location in the same input
/// stream, and have the same scope.
///
/// *This type is available only if Syn is built with the `"parsing"` feature.*
#[derive(Copy, Clone, Eq, PartialEq)]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub struct Cursor<'a> {
// The current entry which the `Cursor` is pointing at.
ptr: *const Entry,
Expand Down
36 changes: 9 additions & 27 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ 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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct Variant {
/// Attributes tagged on the variant.
pub attrs: Vec<Attribute>,
Expand All @@ -24,9 +22,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].
Expand All @@ -35,6 +30,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(docsrs, 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 @@ -51,9 +47,7 @@ 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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct FieldsNamed {
pub brace_token: token::Brace,
pub named: Punctuated<Field, Token![,]>,
Expand All @@ -62,9 +56,7 @@ 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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct FieldsUnnamed {
pub paren_token: token::Paren,
pub unnamed: Punctuated<Field, Token![,]>,
Expand Down Expand Up @@ -146,9 +138,7 @@ 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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct Field {
/// Attributes tagged on the field.
pub attrs: Vec<Attribute>,
Expand All @@ -172,9 +162,6 @@ 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].
Expand All @@ -183,6 +170,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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub enum Visibility {
/// A public visibility level: `pub`.
Public(VisPublic),
Expand All @@ -201,19 +189,15 @@ ast_enum_of_structs! {

ast_struct! {
/// A public visibility level: `pub`.
///
/// *This type is available only if Syn is built with the `"derive"` or
/// `"full"` feature.*
#[cfg_attr(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct VisCrate {
pub crate_token: Token![crate],
}
Expand All @@ -222,9 +206,7 @@ ast_struct! {
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(docsrs, doc(cfg(any(feature = "derive", feature = "full"))))]
pub struct VisRestricted {
pub pub_token: Token![pub],
pub paren_token: token::Paren,
Expand Down
18 changes: 5 additions & 13 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::punctuated::Punctuated;

ast_struct! {
/// Data structure sent to a `proc_macro_derive` macro.
///
/// *This type is available only if Syn is built with the `"derive"` feature.*
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub struct DeriveInput {
/// Attributes tagged on the whole struct or enum.
pub attrs: Vec<Attribute>,
Expand All @@ -26,8 +25,6 @@ ast_struct! {
ast_enum_of_structs! {
/// The storage of a struct, enum or union data structure.
///
/// *This type is available only if Syn is built with the `"derive"` feature.*
///
/// # Syntax tree enum
///
/// This type is a [syntax tree enum].
Expand All @@ -36,6 +33,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(docsrs, doc(cfg(feature = "derive")))]
pub enum Data {
/// A struct input to a `proc_macro_derive` macro.
Struct(DataStruct),
Expand All @@ -52,9 +50,7 @@ ast_enum_of_structs! {

ast_struct! {
/// A struct input to a `proc_macro_derive` macro.
///
/// *This type is available only if Syn is built with the `"derive"`
/// feature.*
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub struct DataStruct {
pub struct_token: Token![struct],
pub fields: Fields,
Expand All @@ -64,9 +60,7 @@ ast_struct! {

ast_struct! {
/// An enum input to a `proc_macro_derive` macro.
///
/// *This type is available only if Syn is built with the `"derive"`
/// feature.*
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub struct DataEnum {
pub enum_token: Token![enum],
pub brace_token: token::Brace,
Expand All @@ -76,9 +70,7 @@ ast_struct! {

ast_struct! {
/// An untagged union input to a `proc_macro_derive` macro.
///
/// *This type is available only if Syn is built with the `"derive"`
/// feature.*
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub struct DataUnion {
pub union_token: Token![union],
pub fields: FieldsNamed,
Expand Down
Loading