Skip to content

Commit 38afa91

Browse files
authored
Unrolled build for #141747
Rollup merge of #141747 - lolbinarycat:rustdoc-cfg-138112, r=GuillaumeGomez rustdoc: display doc(cfg(false)) properly before we had an extra 'on' that was ungramatical. fixes #138112 this is what it looks like now: ![screenshot: Available nowhere](https://github.com/user-attachments/assets/e27b4990-09a7-4f13-8bcf-26d44c8c1bea)
2 parents 1c0849d + c6eb1d9 commit 38afa91

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/librustdoc/clean/cfg.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,15 @@ impl Cfg {
171171

172172
/// Renders the configuration for long display, as a long HTML description.
173173
pub(crate) fn render_long_html(&self) -> String {
174-
let on = if self.should_use_with_in_description() { "with" } else { "on" };
174+
let on = if self.omit_preposition() {
175+
""
176+
} else if self.should_use_with_in_description() {
177+
"with "
178+
} else {
179+
"on "
180+
};
175181

176-
let mut msg =
177-
format!("Available {on} <strong>{}</strong>", Display(self, Format::LongHtml));
182+
let mut msg = format!("Available {on}<strong>{}</strong>", Display(self, Format::LongHtml));
178183
if self.should_append_only_to_description() {
179184
msg.push_str(" only");
180185
}
@@ -244,6 +249,10 @@ impl Cfg {
244249
Some(self.clone())
245250
}
246251
}
252+
253+
fn omit_preposition(&self) -> bool {
254+
matches!(self, Cfg::True | Cfg::False)
255+
}
247256
}
248257

249258
impl ops::Not for Cfg {

tests/rustdoc/cfg-bool.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(doc_cfg)]
2+
#![crate_name = "foo"]
3+
4+
// regression test for https://github.com/rust-lang/rust/issues/138112
5+
6+
//@ has 'foo/fn.foo.html' '//div[@class="stab portability"]' 'Available nowhere'
7+
#[doc(cfg(false))]
8+
pub fn foo() {}
9+
10+
// a cfg(true) will simply be ommited, as it is the same as no cfg.
11+
//@ !has 'foo/fn.bar.html' '//div[@class="stab portability"]' ''
12+
#[doc(cfg(true))]
13+
pub fn bar() {}

0 commit comments

Comments
 (0)