Skip to content

Commit 06dc338

Browse files
authored
Rollup merge of #141770 - GuillaumeGomez:cfg-false-mod-rendering, r=camelid
Merge `Cfg::render_long_html` and `Cfg::render_long_plain` methods common code Follow-up of #141747. Thanks `@camelid` for spotting it! r? `@camelid`
2 parents 8ae8989 + fca28ab commit 06dc338

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/librustdoc/clean/cfg.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,36 @@ impl Cfg {
169169
msg
170170
}
171171

172-
/// Renders the configuration for long display, as a long HTML description.
173-
pub(crate) fn render_long_html(&self) -> String {
172+
fn render_long_inner(&self, format: Format) -> String {
174173
let on = if self.omit_preposition() {
175-
""
174+
" "
176175
} else if self.should_use_with_in_description() {
177-
"with "
176+
" with "
178177
} else {
179-
"on "
178+
" on "
180179
};
181180

182-
let mut msg = format!("Available {on}<strong>{}</strong>", Display(self, Format::LongHtml));
181+
let mut msg = if matches!(format, Format::LongHtml) {
182+
format!("Available{on}<strong>{}</strong>", Display(self, format))
183+
} else {
184+
format!("Available{on}{}", Display(self, format))
185+
};
183186
if self.should_append_only_to_description() {
184187
msg.push_str(" only");
185188
}
189+
msg
190+
}
191+
192+
/// Renders the configuration for long display, as a long HTML description.
193+
pub(crate) fn render_long_html(&self) -> String {
194+
let mut msg = self.render_long_inner(Format::LongHtml);
186195
msg.push('.');
187196
msg
188197
}
189198

190199
/// Renders the configuration for long display, as a long plain text description.
191200
pub(crate) fn render_long_plain(&self) -> String {
192-
let on = if self.should_use_with_in_description() { "with" } else { "on" };
193-
194-
let mut msg = format!("Available {on} {}", Display(self, Format::LongPlain));
195-
if self.should_append_only_to_description() {
196-
msg.push_str(" only");
197-
}
198-
msg
201+
self.render_long_inner(Format::LongPlain)
199202
}
200203

201204
fn should_capitalize_first_letter(&self) -> bool {

tests/rustdoc/cfg-bool.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
// regression test for https://github.com/rust-lang/rust/issues/138112
55

6-
//@ has 'foo/fn.foo.html' '//div[@class="stab portability"]' 'Available nowhere'
6+
//@ has 'foo/index.html'
7+
//@ has - '//*[@class="stab portability"]/@title' 'Available nowhere'
8+
9+
//@ count 'foo/fn.foo.html' '//*[@class="stab portability"]' 1
10+
//@ has 'foo/fn.foo.html' '//*[@class="stab portability"]' 'Available nowhere'
711
#[doc(cfg(false))]
812
pub fn foo() {}
913

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"]' ''
14+
// a cfg(true) will simply be omitted, as it is the same as no cfg.
15+
//@ count 'foo/fn.bar.html' '//*[@class="stab portability"]' 0
1216
#[doc(cfg(true))]
1317
pub fn bar() {}

0 commit comments

Comments
 (0)