Skip to content

Commit ce0c17a

Browse files
* Merge Cfg::render_long_html and Cfg::render_long_plain methods common code
* Fix invalid whitespace handling
1 parent e6152cd commit ce0c17a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
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 {

0 commit comments

Comments
 (0)