mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-20 11:37:32 +00:00
rustdoc: display doc(cfg(false)) properly
before we had an extra 'on' that was ungramatical. fixes https://github.com/rust-lang/rust/issues/138112
This commit is contained in:
parent
642e49bfed
commit
c6eb1d95d3
@ -171,10 +171,15 @@ impl Cfg {
|
|||||||
|
|
||||||
/// Renders the configuration for long display, as a long HTML description.
|
/// Renders the configuration for long display, as a long HTML description.
|
||||||
pub(crate) fn render_long_html(&self) -> String {
|
pub(crate) fn render_long_html(&self) -> String {
|
||||||
let on = if self.should_use_with_in_description() { "with" } else { "on" };
|
let on = if self.omit_preposition() {
|
||||||
|
""
|
||||||
|
} else if self.should_use_with_in_description() {
|
||||||
|
"with "
|
||||||
|
} else {
|
||||||
|
"on "
|
||||||
|
};
|
||||||
|
|
||||||
let mut msg =
|
let mut msg = format!("Available {on}<strong>{}</strong>", Display(self, Format::LongHtml));
|
||||||
format!("Available {on} <strong>{}</strong>", Display(self, Format::LongHtml));
|
|
||||||
if self.should_append_only_to_description() {
|
if self.should_append_only_to_description() {
|
||||||
msg.push_str(" only");
|
msg.push_str(" only");
|
||||||
}
|
}
|
||||||
@ -244,6 +249,10 @@ impl Cfg {
|
|||||||
Some(self.clone())
|
Some(self.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn omit_preposition(&self) -> bool {
|
||||||
|
matches!(self, Cfg::True | Cfg::False)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::Not for Cfg {
|
impl ops::Not for Cfg {
|
||||||
|
13
tests/rustdoc/cfg-bool.rs
Normal file
13
tests/rustdoc/cfg-bool.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#![feature(doc_cfg)]
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// regression test for https://github.com/rust-lang/rust/issues/138112
|
||||||
|
|
||||||
|
//@ has 'foo/fn.foo.html' '//div[@class="stab portability"]' 'Available nowhere'
|
||||||
|
#[doc(cfg(false))]
|
||||||
|
pub fn foo() {}
|
||||||
|
|
||||||
|
// a cfg(true) will simply be ommited, as it is the same as no cfg.
|
||||||
|
//@ !has 'foo/fn.bar.html' '//div[@class="stab portability"]' ''
|
||||||
|
#[doc(cfg(true))]
|
||||||
|
pub fn bar() {}
|
Loading…
Reference in New Issue
Block a user