Skip to content

Commit

Permalink
Rely on docs.rs to define --cfg=docsrs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 19, 2024
1 parent a5098df commit f2588dc
Show file tree
Hide file tree
Showing 37 changed files with 2,515 additions and 2,516 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ required-features = ["full", "parsing"]
[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
rustdoc-args = ["--generate-link-to-definition"]

[package.metadata.playground]
features = ["full", "visit", "visit-mut", "fold", "extra-traits"]
Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn main() {

println!("cargo:rustc-cfg=check_cfg");
println!("cargo:rustc-check-cfg=cfg(check_cfg)");
println!("cargo:rustc-check-cfg=cfg(doc_cfg)");
println!("cargo:rustc-check-cfg=cfg(syn_disable_nightly_tests)");
println!("cargo:rustc-check-cfg=cfg(syn_only)");

Expand Down
6 changes: 3 additions & 3 deletions codegen/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ pub fn features(features: &Features, doc_cfg: impl Into<DocCfg>) -> TokenStream
match (cfg, doc_cfg.into()) {
(Some(cfg), DocCfg::Ordinary) => quote! {
#[#cfg]
#[cfg_attr(doc_cfg, doc(#cfg))]
#[cfg_attr(docsrs, doc(#cfg))]
},
(Some(cfg), DocCfg::Override(overriding_cfg)) => quote! {
#[#cfg]
#[cfg_attr(doc_cfg, doc(cfg(feature = #overriding_cfg)))]
#[cfg_attr(docsrs, doc(cfg(feature = #overriding_cfg)))]
},
(Some(cfg), DocCfg::None) => quote! {
#[#cfg]
},
(None, DocCfg::Override(overriding_cfg)) => quote! {
#[cfg_attr(doc_cfg, doc(cfg(feature = #overriding_cfg)))]
#[cfg_attr(docsrs, doc(cfg(feature = #overriding_cfg)))]
},
(None, DocCfg::Ordinary | DocCfg::None) => TokenStream::new(),
}
Expand Down
44 changes: 22 additions & 22 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ ast_struct! {
/// };
/// assert_eq!(doc, attr);
/// ```
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct Attribute {
pub pound_token: Token![#],
pub style: AttrStyle,
Expand Down Expand Up @@ -218,7 +218,7 @@ impl Attribute {
/// # anyhow::Ok(())
/// ```
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(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)
}
Expand All @@ -241,7 +241,7 @@ impl Attribute {
/// # anyhow::Ok(())
/// ```
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_args_with<F: Parser>(&self, parser: F) -> Result<F::Output> {
match &self.meta {
Meta::Path(path) => Err(crate::error::new2(
Expand Down Expand Up @@ -387,7 +387,7 @@ impl Attribute {
/// # Ok(())
/// ```
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_nested_meta(
&self,
logic: impl FnMut(ParseNestedMeta) -> Result<()>,
Expand All @@ -402,7 +402,7 @@ impl Attribute {
/// See
/// [*Parsing from tokens to Attribute*](#parsing-from-tokens-to-attribute).
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(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![#]) {
Expand All @@ -418,7 +418,7 @@ impl Attribute {
/// See
/// [*Parsing from tokens to Attribute*](#parsing-from-tokens-to-attribute).
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_inner(input: ParseStream) -> Result<Vec<Self>> {
let mut attrs = Vec::new();
parsing::parse_inner(input, &mut attrs)?;
Expand All @@ -441,7 +441,7 @@ ast_enum! {
/// - `#![feature(proc_macro)]`
/// - `//! # Example`
/// - `/*! Please file an issue */`
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub enum AttrStyle {
Outer,
Inner(Token![!]),
Expand Down Expand Up @@ -469,7 +469,7 @@ ast_enum_of_structs! {
/// This type is a [syntax tree enum].
///
/// [syntax tree enum]: crate::expr::Expr#syntax-tree-enums
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub enum Meta {
Path(Path),

Expand All @@ -483,7 +483,7 @@ ast_enum_of_structs! {

ast_struct! {
/// A structured list within an attribute, like `derive(Copy, Clone)`.
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct MetaList {
pub path: Path,
pub delimiter: MacroDelimiter,
Expand All @@ -493,7 +493,7 @@ ast_struct! {

ast_struct! {
/// A name-value pair within an attribute, like `feature = "nightly"`.
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct MetaNameValue {
pub path: Path,
pub eq_token: Token![=],
Expand All @@ -516,7 +516,7 @@ impl Meta {

/// Error if this is a `Meta::List` or `Meta::NameValue`.
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn require_path_only(&self) -> Result<&Path> {
let error_span = match self {
Meta::Path(path) => return Ok(path),
Expand All @@ -528,7 +528,7 @@ impl Meta {

/// Error if this is a `Meta::Path` or `Meta::NameValue`.
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn require_list(&self) -> Result<&MetaList> {
match self {
Meta::List(meta) => Ok(meta),
Expand All @@ -546,7 +546,7 @@ impl Meta {

/// Error if this is a `Meta::Path` or `Meta::List`.
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn require_name_value(&self) -> Result<&MetaNameValue> {
match self {
Meta::NameValue(meta) => Ok(meta),
Expand All @@ -566,22 +566,22 @@ impl Meta {
impl MetaList {
/// See [`Attribute::parse_args`].
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(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)
}

/// See [`Attribute::parse_args_with`].
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_args_with<F: Parser>(&self, parser: F) -> Result<F::Output> {
let scope = self.delimiter.span().close();
crate::parse::parse_scoped(parser, scope, self.tokens.clone())
}

/// See [`Attribute::parse_nested_meta`].
#[cfg(feature = "parsing")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_nested_meta(
&self,
logic: impl FnMut(ParseNestedMeta) -> Result<()>,
Expand Down Expand Up @@ -664,23 +664,23 @@ pub(crate) mod parsing {
})
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for Meta {
fn parse(input: ParseStream) -> Result<Self> {
let path = input.call(Path::parse_mod_style)?;
parse_meta_after_path(path, input)
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for MetaList {
fn parse(input: ParseStream) -> Result<Self> {
let path = input.call(Path::parse_mod_style)?;
parse_meta_list_after_path(path, input)
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for MetaNameValue {
fn parse(input: ParseStream) -> Result<Self> {
let path = input.call(Path::parse_mod_style)?;
Expand Down Expand Up @@ -761,7 +761,7 @@ mod printing {
use proc_macro2::TokenStream;
use quote::ToTokens;

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for Attribute {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.pound_token.to_tokens(tokens);
Expand All @@ -774,15 +774,15 @@ mod printing {
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for MetaList {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.path.to_tokens(tokens);
self.delimiter.surround(tokens, self.tokens.clone());
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for MetaNameValue {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.path.to_tokens(tokens);
Expand Down
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl TokenBuffer {
/// Creates a `TokenBuffer` containing all the tokens from the input
/// `proc_macro::TokenStream`.
#[cfg(feature = "proc-macro")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))]
#[cfg_attr(docsrs, doc(cfg(feature = "proc-macro")))]
pub fn new(stream: proc_macro::TokenStream) -> Self {
Self::new2(stream.into())
}
Expand Down
28 changes: 14 additions & 14 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::ty::Type;

ast_struct! {
/// An enum variant.
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct Variant {
pub attrs: Vec<Attribute>,

Expand All @@ -31,7 +31,7 @@ ast_enum_of_structs! {
/// This type is a [syntax tree enum].
///
/// [syntax tree enum]: crate::expr::Expr#syntax-tree-enums
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub enum Fields {
/// Named fields of a struct or struct variant such as `Point { x: f64,
/// y: f64 }`.
Expand All @@ -48,7 +48,7 @@ ast_enum_of_structs! {
ast_struct! {
/// Named fields of a struct or struct variant such as `Point { x: f64,
/// y: f64 }`.
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct FieldsNamed {
pub brace_token: token::Brace,
pub named: Punctuated<Field, Token![,]>,
Expand All @@ -57,7 +57,7 @@ ast_struct! {

ast_struct! {
/// Unnamed fields of a tuple struct or tuple variant such as `Some(T)`.
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct FieldsUnnamed {
pub paren_token: token::Paren,
pub unnamed: Punctuated<Field, Token![,]>,
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a> IntoIterator for &'a mut Fields {

ast_struct! {
/// A field of a struct or enum variant.
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
pub struct Field {
pub attrs: Vec<Attribute>,

Expand Down Expand Up @@ -174,7 +174,7 @@ pub(crate) mod parsing {
use crate::ty::Type;
use crate::verbatim;

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for Variant {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
Expand Down Expand Up @@ -295,7 +295,7 @@ pub(crate) mod parsing {
Err(input.error("unsupported expression"))
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for FieldsNamed {
fn parse(input: ParseStream) -> Result<Self> {
let content;
Expand All @@ -306,7 +306,7 @@ pub(crate) mod parsing {
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
impl Parse for FieldsUnnamed {
fn parse(input: ParseStream) -> Result<Self> {
let content;
Expand All @@ -319,7 +319,7 @@ pub(crate) mod parsing {

impl Field {
/// Parses a named (braced struct) field.
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_named(input: ParseStream) -> Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
let vis: Visibility = input.parse()?;
Expand Down Expand Up @@ -356,7 +356,7 @@ pub(crate) mod parsing {
}

/// Parses an unnamed (tuple struct) field.
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
pub fn parse_unnamed(input: ParseStream) -> Result<Self> {
Ok(Field {
attrs: input.call(Attribute::parse_outer)?,
Expand All @@ -377,7 +377,7 @@ mod printing {
use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for Variant {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append_all(&self.attrs);
Expand All @@ -390,7 +390,7 @@ mod printing {
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for FieldsNamed {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.brace_token.surround(tokens, |tokens| {
Expand All @@ -399,7 +399,7 @@ mod printing {
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for FieldsUnnamed {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.paren_token.surround(tokens, |tokens| {
Expand All @@ -408,7 +408,7 @@ mod printing {
}
}

#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
impl ToTokens for Field {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.append_all(&self.attrs);
Expand Down
Loading

0 comments on commit f2588dc

Please sign in to comment.