Skip to content

Commit

Permalink
Auto merge of #98108 - SpriteOvO:doc_auto_cfg-feature-rmv-fix, r=notr…
Browse files Browse the repository at this point in the history
…iddle,GuillaumeGomez

Rustdoc: Fix stab disappearing and exclude cfg "doc" and "doctest"

Fixes #98065 Context: #43781 (comment)

r? `@GuillaumeGomez`
  • Loading branch information
bors committed Jun 16, 2022
2 parents 1b9daa6 + 713578b commit 392d272
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,20 @@ impl Cfg {
}),
},
MetaItemKind::List(ref items) => {
let orig_len = items.len();
let sub_cfgs =
items.iter().filter_map(|i| Cfg::parse_nested(i, exclude).transpose());
let ret = match name {
sym::all => sub_cfgs.fold(Ok(Cfg::True), |x, y| Ok(x? & y?)),
sym::any => sub_cfgs.fold(Ok(Cfg::False), |x, y| Ok(x? | y?)),
sym::not => {
let mut sub_cfgs = sub_cfgs.collect::<Vec<_>>();
if sub_cfgs.len() == 1 {
Ok(!sub_cfgs.pop().unwrap()?)
if orig_len == 1 {
let mut sub_cfgs = sub_cfgs.collect::<Vec<_>>();
if sub_cfgs.len() == 1 {
Ok(!sub_cfgs.pop().unwrap()?)
} else {
return Ok(None);
}
} else {
Err(InvalidCfgError { msg: "expected 1 cfg-pattern", span: cfg.span })
}
Expand Down Expand Up @@ -304,8 +309,7 @@ impl ops::BitAnd for Cfg {
impl ops::BitOrAssign for Cfg {
fn bitor_assign(&mut self, other: Cfg) {
match (self, other) {
(&mut Cfg::True, _) | (_, Cfg::False) => {}
(s, Cfg::True) => *s = Cfg::True,
(Cfg::True, _) | (_, Cfg::False) | (_, Cfg::True) => {}
(s @ &mut Cfg::False, b) => *s = b,
(&mut Cfg::Any(ref mut a), Cfg::Any(ref mut b)) => {
for c in b.drain(..) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/cfg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn test_cfg_or() {

x = word_cfg("test");
x |= Cfg::True;
assert_eq!(x, Cfg::True);
assert_eq!(x, word_cfg("test"));

x = word_cfg("test2");
x |= Cfg::False;
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
})
.collect::<Vec<_>>()
})
.chain([Cfg::Cfg(sym::test, None)].into_iter())
.chain(
[Cfg::Cfg(sym::test, None), Cfg::Cfg(sym::doc, None), Cfg::Cfg(sym::doctest, None)]
.into_iter(),
)
.collect();

self.cx.cache.exact_paths = self.exact_paths;
Expand Down
31 changes: 26 additions & 5 deletions src/test/rustdoc/doc-auto-cfg.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
#![feature(doc_auto_cfg)]

#![crate_name = "foo"]

// @has foo/fn.foo.html
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-doctest'
#[cfg(not(doctest))]
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meowmeow'
#[cfg(not(meowmeow))]
pub fn foo() {}

// @has foo/fn.bar.html
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'meowmeow'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'test'
#[cfg(any(test, doc))]
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doctest'
#[cfg(any(meowmeow, test, doc, doctest))]
pub fn bar() {}

// @has foo/fn.appear_1.html
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'meowmeow'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-test'
#[cfg(any(meowmeow, doc, not(test)))]
pub fn appear_1() {} // issue #98065

// @has foo/fn.appear_2.html
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'meowmeow'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'test'
#[cfg(any(meowmeow, doc, all(test)))]
pub fn appear_2() {} // issue #98065

// @has foo/fn.appear_3.html
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'meowmeow'
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
#[cfg(any(meowmeow, doc, all()))]
pub fn appear_3() {} // issue #98065

0 comments on commit 392d272

Please sign in to comment.