diff options
| author | binarycat <binarycat@envs.net> | 2025-05-29 15:40:50 -0500 |
|---|---|---|
| committer | binarycat <binarycat@envs.net> | 2025-05-29 15:40:50 -0500 |
| commit | c6eb1d95d35bcaa0e9cf0e387cd98d4310ed434c (patch) | |
| tree | 12f05c31b2fde2f3d8ffa2c1b1faf891a030460e | |
| parent | 642e49bfed2481e54e252732be20d3c24cbec9e8 (diff) | |
| download | rust-c6eb1d95d35bcaa0e9cf0e387cd98d4310ed434c.tar.gz rust-c6eb1d95d35bcaa0e9cf0e387cd98d4310ed434c.zip | |
rustdoc: display doc(cfg(false)) properly
before we had an extra 'on' that was ungramatical. fixes https://github.com/rust-lang/rust/issues/138112
| -rw-r--r-- | src/librustdoc/clean/cfg.rs | 15 | ||||
| -rw-r--r-- | tests/rustdoc/cfg-bool.rs | 13 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 439777843fb..ebc276b38fb 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} <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 { diff --git a/tests/rustdoc/cfg-bool.rs b/tests/rustdoc/cfg-bool.rs new file mode 100644 index 00000000000..34fdfbe930e --- /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() {} |
