Skip to content

Commit f2588dc

Browse files
committed
Rely on docs.rs to define --cfg=docsrs by default
1 parent a5098df commit f2588dc

37 files changed

+2515
-2516
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ required-features = ["full", "parsing"]
6868
[package.metadata.docs.rs]
6969
all-features = true
7070
targets = ["x86_64-unknown-linux-gnu"]
71-
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
71+
rustdoc-args = ["--generate-link-to-definition"]
7272

7373
[package.metadata.playground]
7474
features = ["full", "visit", "visit-mut", "fold", "extra-traits"]

build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn main() {
1313

1414
println!("cargo:rustc-cfg=check_cfg");
1515
println!("cargo:rustc-check-cfg=cfg(check_cfg)");
16-
println!("cargo:rustc-check-cfg=cfg(doc_cfg)");
1716
println!("cargo:rustc-check-cfg=cfg(syn_disable_nightly_tests)");
1817
println!("cargo:rustc-check-cfg=cfg(syn_only)");
1918

codegen/src/cfg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub fn features(features: &Features, doc_cfg: impl Into<DocCfg>) -> TokenStream
2424
match (cfg, doc_cfg.into()) {
2525
(Some(cfg), DocCfg::Ordinary) => quote! {
2626
#[#cfg]
27-
#[cfg_attr(doc_cfg, doc(#cfg))]
27+
#[cfg_attr(docsrs, doc(#cfg))]
2828
},
2929
(Some(cfg), DocCfg::Override(overriding_cfg)) => quote! {
3030
#[#cfg]
31-
#[cfg_attr(doc_cfg, doc(cfg(feature = #overriding_cfg)))]
31+
#[cfg_attr(docsrs, doc(cfg(feature = #overriding_cfg)))]
3232
},
3333
(Some(cfg), DocCfg::None) => quote! {
3434
#[#cfg]
3535
},
3636
(None, DocCfg::Override(overriding_cfg)) => quote! {
37-
#[cfg_attr(doc_cfg, doc(cfg(feature = #overriding_cfg)))]
37+
#[cfg_attr(docsrs, doc(cfg(feature = #overriding_cfg)))]
3838
},
3939
(None, DocCfg::Ordinary | DocCfg::None) => TokenStream::new(),
4040
}

src/attr.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ ast_struct! {
169169
/// };
170170
/// assert_eq!(doc, attr);
171171
/// ```
172-
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
172+
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
173173
pub struct Attribute {
174174
pub pound_token: Token![#],
175175
pub style: AttrStyle,
@@ -218,7 +218,7 @@ impl Attribute {
218218
/// # anyhow::Ok(())
219219
/// ```
220220
#[cfg(feature = "parsing")]
221-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
221+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
222222
pub fn parse_args<T: Parse>(&self) -> Result<T> {
223223
self.parse_args_with(T::parse)
224224
}
@@ -241,7 +241,7 @@ impl Attribute {
241241
/// # anyhow::Ok(())
242242
/// ```
243243
#[cfg(feature = "parsing")]
244-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
244+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
245245
pub fn parse_args_with<F: Parser>(&self, parser: F) -> Result<F::Output> {
246246
match &self.meta {
247247
Meta::Path(path) => Err(crate::error::new2(
@@ -387,7 +387,7 @@ impl Attribute {
387387
/// # Ok(())
388388
/// ```
389389
#[cfg(feature = "parsing")]
390-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
390+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
391391
pub fn parse_nested_meta(
392392
&self,
393393
logic: impl FnMut(ParseNestedMeta) -> Result<()>,
@@ -402,7 +402,7 @@ impl Attribute {
402402
/// See
403403
/// [*Parsing from tokens to Attribute*](#parsing-from-tokens-to-attribute).
404404
#[cfg(feature = "parsing")]
405-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
405+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
406406
pub fn parse_outer(input: ParseStream) -> Result<Vec<Self>> {
407407
let mut attrs = Vec::new();
408408
while input.peek(Token![#]) {
@@ -418,7 +418,7 @@ impl Attribute {
418418
/// See
419419
/// [*Parsing from tokens to Attribute*](#parsing-from-tokens-to-attribute).
420420
#[cfg(feature = "parsing")]
421-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
421+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
422422
pub fn parse_inner(input: ParseStream) -> Result<Vec<Self>> {
423423
let mut attrs = Vec::new();
424424
parsing::parse_inner(input, &mut attrs)?;
@@ -441,7 +441,7 @@ ast_enum! {
441441
/// - `#![feature(proc_macro)]`
442442
/// - `//! # Example`
443443
/// - `/*! Please file an issue */`
444-
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
444+
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
445445
pub enum AttrStyle {
446446
Outer,
447447
Inner(Token![!]),
@@ -469,7 +469,7 @@ ast_enum_of_structs! {
469469
/// This type is a [syntax tree enum].
470470
///
471471
/// [syntax tree enum]: crate::expr::Expr#syntax-tree-enums
472-
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))]
472+
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
473473
pub enum Meta {
474474
Path(Path),
475475

@@ -483,7 +483,7 @@ ast_enum_of_structs! {
483483

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

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

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

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

547547
/// Error if this is a `Meta::Path` or `Meta::List`.
548548
#[cfg(feature = "parsing")]
549-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
549+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
550550
pub fn require_name_value(&self) -> Result<&MetaNameValue> {
551551
match self {
552552
Meta::NameValue(meta) => Ok(meta),
@@ -566,22 +566,22 @@ impl Meta {
566566
impl MetaList {
567567
/// See [`Attribute::parse_args`].
568568
#[cfg(feature = "parsing")]
569-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
569+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
570570
pub fn parse_args<T: Parse>(&self) -> Result<T> {
571571
self.parse_args_with(T::parse)
572572
}
573573

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

582582
/// See [`Attribute::parse_nested_meta`].
583583
#[cfg(feature = "parsing")]
584-
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
584+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
585585
pub fn parse_nested_meta(
586586
&self,
587587
logic: impl FnMut(ParseNestedMeta) -> Result<()>,
@@ -664,23 +664,23 @@ pub(crate) mod parsing {
664664
})
665665
}
666666

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

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

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

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

777-
#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
777+
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
778778
impl ToTokens for MetaList {
779779
fn to_tokens(&self, tokens: &mut TokenStream) {
780780
self.path.to_tokens(tokens);
781781
self.delimiter.surround(tokens, self.tokens.clone());
782782
}
783783
}
784784

785-
#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
785+
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
786786
impl ToTokens for MetaNameValue {
787787
fn to_tokens(&self, tokens: &mut TokenStream) {
788788
self.path.to_tokens(tokens);

src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl TokenBuffer {
5656
/// Creates a `TokenBuffer` containing all the tokens from the input
5757
/// `proc_macro::TokenStream`.
5858
#[cfg(feature = "proc-macro")]
59-
#[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))]
59+
#[cfg_attr(docsrs, doc(cfg(feature = "proc-macro")))]
6060
pub fn new(stream: proc_macro::TokenStream) -> Self {
6161
Self::new2(stream.into())
6262
}

src/data.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ty::Type;
88

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

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

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

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

@@ -174,7 +174,7 @@ pub(crate) mod parsing {
174174
use crate::ty::Type;
175175
use crate::verbatim;
176176

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

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

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

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

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

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

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

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

411-
#[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))]
411+
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
412412
impl ToTokens for Field {
413413
fn to_tokens(&self, tokens: &mut TokenStream) {
414414
tokens.append_all(&self.attrs);

0 commit comments

Comments
 (0)