Skip to content

Commit

Permalink
Improve rendering of crate features via doc(cfg)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Aug 9, 2020
1 parent f50f1c8 commit a8de713
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/librustdoc/clean/cfg.rs
Expand Up @@ -413,6 +413,13 @@ impl<'a> fmt::Display for Html<'a> {
return write!(fmt, "target feature <code>{}</code>", feat);
}
}
(sym::feature, Some(feat)) => {
if self.1 {
return write!(fmt, "<code>{}</code>", feat);
} else {
return write!(fmt, "crate feature <code>{}</code>", feat);
}
}
_ => "",
};
if !human_readable.is_empty() {
Expand Down
10 changes: 5 additions & 5 deletions src/test/rustdoc/duplicate-cfg.rs
Expand Up @@ -4,37 +4,37 @@
#![feature(doc_cfg)]

// @has 'foo/struct.Foo.html'
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" only.'
// @has '-' '//*[@class="stab portability"]' 'This is supported on crate feature sync only.'
#[doc(cfg(feature = "sync"))]
#[doc(cfg(feature = "sync"))]
pub struct Foo;

// @has 'foo/bar/struct.Bar.html'
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" only.'
// @has '-' '//*[@class="stab portability"]' 'This is supported on crate feature sync only.'
#[doc(cfg(feature = "sync"))]
pub mod bar {
#[doc(cfg(feature = "sync"))]
pub struct Bar;
}

// @has 'foo/baz/struct.Baz.html'
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" and feature="send" only.'
// @has '-' '//*[@class="stab portability"]' 'This is supported on crate feature sync and crate feature send only.'
#[doc(cfg(all(feature = "sync", feature = "send")))]
pub mod baz {
#[doc(cfg(feature = "sync"))]
pub struct Baz;
}

// @has 'foo/qux/struct.Qux.html'
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" and feature="send" only.'
// @has '-' '//*[@class="stab portability"]' 'This is supported on crate feature sync and crate feature send only.'
#[doc(cfg(feature = "sync"))]
pub mod qux {
#[doc(cfg(all(feature = "sync", feature = "send")))]
pub struct Qux;
}

// @has 'foo/quux/struct.Quux.html'
// @has '-' '//*[@class="stab portability"]' 'This is supported on feature="sync" and feature="send" and foo and bar only.'
// @has '-' '//*[@class="stab portability"]' 'This is supported on crate feature sync and crate feature send and foo and bar only.'
#[doc(cfg(all(feature = "sync", feature = "send", foo)))]
pub mod quux {
#[doc(cfg(all(feature = "send", feature = "sync", bar)))]
Expand Down

0 comments on commit a8de713

Please sign in to comment.