Fix cfg(not)
and cfg(all)
causing Rustdoc stab to disappear
This commit is contained in:
parent
872503d918
commit
9aa1ccdae8
3 changed files with 27 additions and 7 deletions
|
@ -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 })
|
||||
}
|
||||
|
@ -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(..) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![feature(doc_auto_cfg)]
|
||||
|
||||
#![crate_name = "foo"]
|
||||
|
||||
// @has foo/fn.foo.html
|
||||
|
@ -12,3 +11,20 @@ pub fn foo() {}
|
|||
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'test'
|
||||
#[cfg(any(test, doc))]
|
||||
pub fn bar() {}
|
||||
|
||||
// @has foo/fn.appear_1.html
|
||||
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
|
||||
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-test'
|
||||
#[cfg(any(doc, not(test)))]
|
||||
pub fn appear_1() {} // issue #98065
|
||||
|
||||
// @has foo/fn.appear_2.html
|
||||
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
|
||||
// @!has - '//*[@class="item-info"]/*[@class="stab portability"]' 'test'
|
||||
#[cfg(any(doc, all(test)))]
|
||||
pub fn appear_2() {} // issue #98065
|
||||
|
||||
// @has foo/fn.appear_3.html
|
||||
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'doc'
|
||||
#[cfg(any(doc, all()))]
|
||||
pub fn appear_3() {} // issue #98065
|
||||
|
|
Loading…
Add table
Reference in a new issue