Skip to content

Commit 4d09d44

Browse files
Update to new API, allowing to remove check_doc_cfg.rs file from librustdoc
1 parent cdc7b43 commit 4d09d44

File tree

12 files changed

+56
-127
lines changed

12 files changed

+56
-127
lines changed

compiler/rustc_attr_parsing/src/attributes/cfg_old.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, Nod
22
use rustc_ast_pretty::pprust;
33
use rustc_feature::{Features, GatedCfg, find_gated_cfg};
44
use rustc_hir::RustcVersion;
5-
use rustc_hir::lints::AttributeLintKind;
65
use rustc_session::Session;
76
use rustc_session::lint::{BuiltinLintDiag, Lint};
87
use rustc_session::parse::feature_err;

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl DocParser {
294294
cx.expected_identifier(sub_item.path().span());
295295
continue;
296296
};
297-
if let Ok(CfgEntry::NameValue { name, name_span, value, .. }) =
297+
if let Ok(CfgEntry::NameValue { name, value, .. }) =
298298
super::cfg::parse_name_value(
299299
name,
300300
sub_item.path().span(),
@@ -303,7 +303,14 @@ impl DocParser {
303303
cx,
304304
)
305305
{
306-
cfg_hide_show.values.push(CfgInfo { name, name_span, value })
306+
cfg_hide_show.values.push(CfgInfo {
307+
name,
308+
name_span: sub_item.path().span(),
309+
// If `value` is `Some`, `a.name_value()` will always return
310+
// `Some` as well.
311+
value: value
312+
.map(|v| (v, a.name_value().unwrap().value_span)),
313+
})
307314
}
308315
}
309316
_ => {

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,7 @@ impl CfgEntry {
218218
(
219219
Self::NameValue { name: name1, value: value1, .. },
220220
Self::NameValue { name: name2, value: value2, .. },
221-
) => {
222-
name1 == name2
223-
&& match (value1, value2) {
224-
(Some((a, _)), Some((b, _))) => a == b,
225-
(None, None) => true,
226-
_ => false,
227-
}
228-
}
221+
) => name1 == name2 && value1 == value2,
229222
(Self::Version(a, _), Self::Version(b, _)) => a == b,
230223
_ => false,
231224
}
@@ -257,7 +250,7 @@ impl fmt::Display for CfgEntry {
257250
match value {
258251
// We use `as_str` and debug display to have characters escaped and `"`
259252
// characters surrounding the string.
260-
Some((value, _)) => write!(f, "{name} = {:?}", value.as_str()),
253+
Some(value) => write!(f, "{name} = {:?}", value.as_str()),
261254
None => write!(f, "{name}"),
262255
}
263256
}

library/std/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fn main() {
1313
println!("cargo:rustc-cfg=netbsd10");
1414
}
1515

16+
// Needed for `#![doc(auto_cfg(hide(no_global_oom_handling)))]` attribute.
17+
println!("cargo::rustc-check-cfg=cfg(no_global_oom_handling)");
18+
1619
println!("cargo:rustc-check-cfg=cfg(restricted_std)");
1720
if target_os == "linux"
1821
|| target_os == "android"

src/librustdoc/clean/cfg.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,7 @@ impl Cfg {
140140
if exclude.contains(&NameValueCfg::new(name)) {
141141
Ok(None)
142142
} else {
143-
Ok(Some(Cfg(CfgEntry::NameValue {
144-
name,
145-
value: None,
146-
name_span: DUMMY_SP,
147-
span: DUMMY_SP,
148-
})))
143+
Ok(Some(Cfg(CfgEntry::NameValue { name, value: None, span: DUMMY_SP })))
149144
}
150145
}
151146
MetaItemKind::NameValue(ref lit) => match lit.kind {
@@ -155,8 +150,7 @@ impl Cfg {
155150
} else {
156151
Ok(Some(Cfg(CfgEntry::NameValue {
157152
name,
158-
value: Some((value, DUMMY_SP)),
159-
name_span: DUMMY_SP,
153+
value: Some(value),
160154
span: DUMMY_SP,
161155
})))
162156
}
@@ -226,9 +220,7 @@ impl Cfg {
226220
CfgEntry::Any(sub_cfgs, _) => {
227221
sub_cfgs.iter().any(|sub_cfg| cfg_matches(sub_cfg, psess))
228222
}
229-
CfgEntry::NameValue { name, value, .. } => {
230-
psess.config.contains(&(*name, value.clone().map(|(s, _)| s)))
231-
}
223+
CfgEntry::NameValue { name, value, .. } => psess.config.contains(&(*name, *value)),
232224
CfgEntry::Version(..) => {
233225
// FIXME: should be handled.
234226
false
@@ -497,7 +489,7 @@ impl Display<'_> {
497489
sub_cfgs
498490
.iter()
499491
.map(|sub_cfg| {
500-
if let CfgEntry::NameValue { value: Some((feat, _)), .. } = sub_cfg
492+
if let CfgEntry::NameValue { value: Some(feat), .. } = sub_cfg
501493
&& short_longhand
502494
{
503495
Either::Left(self.code_wrappers().wrap(feat))
@@ -557,7 +549,7 @@ impl fmt::Display for Display<'_> {
557549
(sym::unix, None) => "Unix",
558550
(sym::windows, None) => "Windows",
559551
(sym::debug_assertions, None) => "debug-assertions enabled",
560-
(sym::target_os, Some((os, _))) => match os.as_str() {
552+
(sym::target_os, Some(os)) => match os.as_str() {
561553
"android" => "Android",
562554
"cygwin" => "Cygwin",
563555
"dragonfly" => "DragonFly BSD",
@@ -582,7 +574,7 @@ impl fmt::Display for Display<'_> {
582574
"visionos" => "visionOS",
583575
_ => "",
584576
},
585-
(sym::target_arch, Some((arch, _))) => match arch.as_str() {
577+
(sym::target_arch, Some(arch)) => match arch.as_str() {
586578
"aarch64" => "AArch64",
587579
"arm" => "ARM",
588580
"loongarch32" => "LoongArch LA32",
@@ -605,14 +597,14 @@ impl fmt::Display for Display<'_> {
605597
"x86_64" => "x86-64",
606598
_ => "",
607599
},
608-
(sym::target_vendor, Some((vendor, _))) => match vendor.as_str() {
600+
(sym::target_vendor, Some(vendor)) => match vendor.as_str() {
609601
"apple" => "Apple",
610602
"pc" => "PC",
611603
"sun" => "Sun",
612604
"fortanix" => "Fortanix",
613605
_ => "",
614606
},
615-
(sym::target_env, Some((env, _))) => match env.as_str() {
607+
(sym::target_env, Some(env)) => match env.as_str() {
616608
"gnu" => "GNU",
617609
"msvc" => "MSVC",
618610
"musl" => "musl",
@@ -621,20 +613,20 @@ impl fmt::Display for Display<'_> {
621613
"sgx" => "SGX",
622614
_ => "",
623615
},
624-
(sym::target_endian, Some((endian, _))) => {
616+
(sym::target_endian, Some(endian)) => {
625617
return write!(fmt, "{endian}-endian");
626618
}
627-
(sym::target_pointer_width, Some((bits, _))) => {
619+
(sym::target_pointer_width, Some(bits)) => {
628620
return write!(fmt, "{bits}-bit");
629621
}
630-
(sym::target_feature, Some((feat, _))) => match self.1 {
622+
(sym::target_feature, Some(feat)) => match self.1 {
631623
Format::LongHtml => {
632624
return write!(fmt, "target feature <code>{feat}</code>");
633625
}
634626
Format::LongPlain => return write!(fmt, "target feature `{feat}`"),
635627
Format::ShortHtml => return write!(fmt, "<code>{feat}</code>"),
636628
},
637-
(sym::feature, Some((feat, _))) => match self.1 {
629+
(sym::feature, Some(feat)) => match self.1 {
638630
Format::LongHtml => {
639631
return write!(fmt, "crate feature <code>{feat}</code>");
640632
}
@@ -647,9 +639,7 @@ impl fmt::Display for Display<'_> {
647639
fmt.write_str(human_readable)
648640
} else {
649641
let value = value
650-
.map(|(v, _)| {
651-
fmt::from_fn(move |f| write!(f, "={}", self.1.escape(v.as_str())))
652-
})
642+
.map(|v| fmt::from_fn(move |f| write!(f, "={}", self.1.escape(v.as_str()))))
653643
.maybe_display();
654644
self.code_wrappers()
655645
.wrap(format_args!("{}{value}", self.1.escape(name.as_str())))
@@ -684,9 +674,7 @@ impl NameValueCfg {
684674
impl<'a> From<&'a CfgEntry> for NameValueCfg {
685675
fn from(cfg: &'a CfgEntry) -> Self {
686676
match cfg {
687-
CfgEntry::NameValue { name, value, .. } => {
688-
NameValueCfg { name: *name, value: (*value).map(|(v, _)| v) }
689-
}
677+
CfgEntry::NameValue { name, value, .. } => NameValueCfg { name: *name, value: *value },
690678
_ => NameValueCfg { name: sym::empty, value: None },
691679
}
692680
}
@@ -886,8 +874,7 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
886874
for (feature, _) in features {
887875
cfg_info.current_cfg &= Cfg(CfgEntry::NameValue {
888876
name: sym::target_feature,
889-
value: Some((*feature, DUMMY_SP)),
890-
name_span: DUMMY_SP,
877+
value: Some(*feature),
891878
span: DUMMY_SP,
892879
});
893880
}

src/librustdoc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
extern crate rustc_abi;
3333
extern crate rustc_ast;
3434
extern crate rustc_ast_pretty;
35-
extern crate rustc_attr_parsing;
3635
extern crate rustc_data_structures;
3736
extern crate rustc_driver;
3837
extern crate rustc_errors;

src/librustdoc/passes/check_doc_cfg.rs

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/librustdoc/passes/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ pub(crate) use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;
3232
mod check_doc_test_visibility;
3333
pub(crate) use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY;
3434

35-
mod check_doc_cfg;
36-
pub(crate) use self::check_doc_cfg::CHECK_DOC_CFG;
37-
3835
mod collect_trait_impls;
3936
pub(crate) use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
4037

@@ -75,7 +72,6 @@ pub(crate) enum Condition {
7572

7673
/// The full list of passes.
7774
pub(crate) const PASSES: &[Pass] = &[
78-
CHECK_DOC_CFG,
7975
CHECK_DOC_TEST_VISIBILITY,
8076
PROPAGATE_DOC_CFG,
8177
STRIP_ALIASED_NON_LOCAL,
@@ -93,7 +89,6 @@ pub(crate) const PASSES: &[Pass] = &[
9389
pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
9490
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
9591
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
96-
ConditionalPass::always(CHECK_DOC_CFG),
9792
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
9893
ConditionalPass::always(PROPAGATE_DOC_CFG),
9994
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),

tests/rustdoc-ui/doc-cfg-2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
// Shouldn't lint
1313
#[doc(auto_cfg(hide(windows)))]
1414
#[doc(auto_cfg(hide(feature = "windows")))]
15+
//~^ WARN unexpected `cfg` condition name: `feature`
1516
#[doc(auto_cfg(hide(foo)))]
17+
//~^ WARN unexpected `cfg` condition name: `foo`
1618
pub fn foo() {}

tests/rustdoc-ui/doc-cfg-2.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,23 @@ error: expected boolean for `#[doc(auto_cfg = ...)]`
5656
LL | #[doc(auto_cfg = "a")]
5757
| ^^^
5858

59-
error: aborting due to 6 previous errors; 2 warnings emitted
59+
warning: unexpected `cfg` condition name: `feature`
60+
--> $DIR/doc-cfg-2.rs:14:21
61+
|
62+
LL | #[doc(auto_cfg(hide(feature = "windows")))]
63+
| ^^^^^^^^^^^^^^^^^^^
64+
|
65+
= help: to expect this configuration use `--check-cfg=cfg(feature, values("windows"))`
66+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
67+
68+
warning: unexpected `cfg` condition name: `foo`
69+
--> $DIR/doc-cfg-2.rs:16:21
70+
|
71+
LL | #[doc(auto_cfg(hide(foo)))]
72+
| ^^^
73+
|
74+
= help: to expect this configuration use `--check-cfg=cfg(foo)`
75+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
76+
77+
error: aborting due to 6 previous errors; 4 warnings emitted
6078

0 commit comments

Comments
 (0)