From ce0c17a6e70f26a9133b24d0ea570e4af0178715 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 30 May 2025 15:33:20 +0200 Subject: [PATCH 1/2] * Merge `Cfg::render_long_html` and `Cfg::render_long_plain` methods common code * Fix invalid whitespace handling --- src/librustdoc/clean/cfg.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index ebc276b38fbfa..81a6f902c6a5e 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -169,33 +169,36 @@ impl Cfg { msg } - /// Renders the configuration for long display, as a long HTML description. - pub(crate) fn render_long_html(&self) -> String { + fn render_long_inner(&self, format: Format) -> String { let on = if self.omit_preposition() { - "" + " " } else if self.should_use_with_in_description() { - "with " + " with " } else { - "on " + " on " }; - let mut msg = format!("Available {on}{}", Display(self, Format::LongHtml)); + let mut msg = if matches!(format, Format::LongHtml) { + format!("Available{on}{}", Display(self, format)) + } else { + format!("Available{on}{}", Display(self, format)) + }; if self.should_append_only_to_description() { msg.push_str(" only"); } + msg + } + + /// Renders the configuration for long display, as a long HTML description. + pub(crate) fn render_long_html(&self) -> String { + let mut msg = self.render_long_inner(Format::LongHtml); msg.push('.'); msg } /// Renders the configuration for long display, as a long plain text description. pub(crate) fn render_long_plain(&self) -> String { - let on = if self.should_use_with_in_description() { "with" } else { "on" }; - - let mut msg = format!("Available {on} {}", Display(self, Format::LongPlain)); - if self.should_append_only_to_description() { - msg.push_str(" only"); - } - msg + self.render_long_inner(Format::LongPlain) } fn should_capitalize_first_letter(&self) -> bool { From fca28ab5132810b21182176ac02bdd292b77a368 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 30 May 2025 15:34:04 +0200 Subject: [PATCH 2/2] * Add test case for `cfg(false)` on module level * Fix typo * Remove usage of `!has` --- tests/rustdoc/cfg-bool.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/rustdoc/cfg-bool.rs b/tests/rustdoc/cfg-bool.rs index 34fdfbe930e12..0aaa132e0b540 100644 --- a/tests/rustdoc/cfg-bool.rs +++ b/tests/rustdoc/cfg-bool.rs @@ -3,11 +3,15 @@ // regression test for https://github.com/rust-lang/rust/issues/138112 -//@ has 'foo/fn.foo.html' '//div[@class="stab portability"]' 'Available nowhere' +//@ has 'foo/index.html' +//@ has - '//*[@class="stab portability"]/@title' 'Available nowhere' + +//@ count 'foo/fn.foo.html' '//*[@class="stab portability"]' 1 +//@ has 'foo/fn.foo.html' '//*[@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"]' '' +// a cfg(true) will simply be omitted, as it is the same as no cfg. +//@ count 'foo/fn.bar.html' '//*[@class="stab portability"]' 0 #[doc(cfg(true))] pub fn bar() {}