diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs
index 439777843fb0..ebc276b38fbf 100644
--- a/src/librustdoc/clean/cfg.rs
+++ b/src/librustdoc/clean/cfg.rs
@@ -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} {}", Display(self, Format::LongHtml));
+ let mut msg = format!("Available {on}{}", 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 {
diff --git a/tests/rustdoc/cfg-bool.rs b/tests/rustdoc/cfg-bool.rs
new file mode 100644
index 000000000000..34fdfbe930e1
--- /dev/null
+++ b/tests/rustdoc/cfg-bool.rs
@@ -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() {}