Skip to content

Commit 9aa1ccd

Browse files
committed
Fix cfg(not) and cfg(all) causing Rustdoc stab to disappear
1 parent 872503d commit 9aa1ccd

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/librustdoc/clean/cfg.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,20 @@ impl Cfg {
8787
}),
8888
},
8989
MetaItemKind::List(ref items) => {
90+
let orig_len = items.len();
9091
let sub_cfgs =
9192
items.iter().filter_map(|i| Cfg::parse_nested(i, exclude).transpose());
9293
let ret = match name {
9394
sym::all => sub_cfgs.fold(Ok(Cfg::True), |x, y| Ok(x? & y?)),
9495
sym::any => sub_cfgs.fold(Ok(Cfg::False), |x, y| Ok(x? | y?)),
9596
sym::not => {
96-
let mut sub_cfgs = sub_cfgs.collect::<Vec<_>>();
97-
if sub_cfgs.len() == 1 {
98-
Ok(!sub_cfgs.pop().unwrap()?)
97+
if orig_len == 1 {
98+
let mut sub_cfgs = sub_cfgs.collect::<Vec<_>>();
99+
if sub_cfgs.len() == 1 {
100+
Ok(!sub_cfgs.pop().unwrap()?)
101+
} else {
102+
return Ok(None);
103+
}
99104
} else {
100105
Err(InvalidCfgError { msg: "expected 1 cfg-pattern", span: cfg.span })
101106
}
@@ -304,8 +309,7 @@ impl ops::BitAnd for Cfg {
304309
impl ops::BitOrAssign for Cfg {
305310
fn bitor_assign(&mut self, other: Cfg) {
306311
match (self, other) {
307-
(&mut Cfg::True, _) | (_, Cfg::False) => {}
308-
(s, Cfg::True) => *s = Cfg::True,
312+
(Cfg::True, _) | (_, Cfg::False) | (_, Cfg::True) => {}
309313
(s @ &mut Cfg::False, b) => *s = b,
310314
(&mut Cfg::Any(ref mut a), Cfg::Any(ref mut b)) => {
311315
for c in b.drain(..) {

src/librustdoc/clean/cfg/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn test_cfg_or() {
161161

162162
x = word_cfg("test");
163163
x |= Cfg::True;
164-
assert_eq!(x, Cfg::True);
164+
assert_eq!(x, word_cfg("test"));
165165

166166
x = word_cfg("test2");
167167
x |= Cfg::False;

src/test/rustdoc/doc-auto-cfg.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(doc_auto_cfg)]
2-
32
#![crate_name = "foo"]
43

54
// @has foo/fn.foo.html
@@ -12,3 +11,20 @@ pub fn foo() {}
1211
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'test'
1312
#[cfg(any(test, doc))]
1413
pub fn bar() {}
14+
15+
// @has foo/fn.appear_1.html
16+
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
17+
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-test'
18+
#[cfg(any(doc, not(test)))]
19+
pub fn appear_1() {} // issue #98065
20+
21+
// @has foo/fn.appear_2.html
22+
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
23+
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'test'
24+
#[cfg(any(doc, all(test)))]
25+
pub fn appear_2() {} // issue #98065
26+
27+
// @has foo/fn.appear_3.html
28+
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
29+
#[cfg(any(doc, all()))]
30+
pub fn appear_3() {} // issue #98065

0 commit comments

Comments
 (0)