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:
binarycat 2025-05-29 15:40:50 -05:00
parent 642e49bfed
commit c6eb1d95d3
2 changed files with 25 additions and 3 deletions

View File

@ -171,10 +171,15 @@ impl Cfg {
/// Renders the configuration for long display, as a long HTML description.
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 =
format!("Available {on} <strong>{}</strong>", Display(self, Format::LongHtml));
let mut msg = format!("Available {on}<strong>{}</strong>", Display(self, Format::LongHtml));
if self.should_append_only_to_description() {
msg.push_str(" only");
}
@ -244,6 +249,10 @@ impl Cfg {
Some(self.clone())
}
}
fn omit_preposition(&self) -> bool {
matches!(self, Cfg::True | Cfg::False)
}
}
impl ops::Not for Cfg {

13
tests/rustdoc/cfg-bool.rs Normal file
View 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() {}