Skip to content

Commit 479116e

Browse files
committed
return impl fmt::Display in more places instead of writing to strings
1 parent 0769736 commit 479116e

File tree

5 files changed

+2476
-2274
lines changed

5 files changed

+2476
-2274
lines changed

Diff for: src/librustdoc/html/format.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use super::url_parts_builder::{UrlPartsBuilder, estimate_item_path_byte_length};
3030
use crate::clean::types::ExternalLocation;
3131
use crate::clean::utils::find_nearest_parent_module;
3232
use crate::clean::{self, ExternalCrate, PrimitiveType};
33-
use crate::display::Joined as _;
33+
use crate::display::{Joined as _, MaybeDisplay as _};
3434
use crate::formats::cache::Cache;
3535
use crate::formats::item_type::ItemType;
3636
use crate::html::escape::{Escape, EscapeBodyText};
@@ -178,12 +178,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
178178
cx: &'a Context<'tcx>,
179179
indent: usize,
180180
ending: Ending,
181-
) -> impl Display + 'a + Captures<'tcx> {
182-
fmt::from_fn(move |f| {
183-
if gens.where_predicates.is_empty() {
184-
return Ok(());
185-
}
181+
) -> Option<impl Display + 'a + Captures<'tcx>> {
182+
if gens.where_predicates.is_empty() {
183+
return None;
184+
}
186185

186+
Some(fmt::from_fn(move |f| {
187187
let where_preds = fmt::from_fn(|f| {
188188
gens.where_predicates
189189
.iter()
@@ -246,7 +246,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
246246
}
247247
};
248248
write!(f, "{clause}")
249-
})
249+
}))
250250
}
251251

252252
impl clean::Lifetime {
@@ -1179,7 +1179,7 @@ impl clean::Impl {
11791179
self.print_type(&self.for_, f, use_absolute, cx)?;
11801180
}
11811181

1182-
print_where_clause(&self.generics, cx, 0, Ending::Newline).fmt(f)
1182+
print_where_clause(&self.generics, cx, 0, Ending::Newline).maybe_display().fmt(f)
11831183
})
11841184
}
11851185
fn print_type<'a, 'tcx: 'a>(

Diff for: src/librustdoc/html/render/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ impl<'tcx> Context<'tcx> {
237237
};
238238

239239
if !render_redirect_pages {
240-
let mut page_buffer = String::new();
241-
print_item(self, it, &mut page_buffer);
240+
let content = print_item(self, it);
242241
let page = layout::Page {
243242
css_class: tyname_s,
244243
root_path: &self.root_path(),
@@ -254,7 +253,7 @@ impl<'tcx> Context<'tcx> {
254253
BufDisplay(|buf: &mut String| {
255254
print_sidebar(self, it, buf);
256255
}),
257-
page_buffer,
256+
content,
258257
&self.shared.style_files,
259258
)
260259
} else {

0 commit comments

Comments
 (0)