Skip to content

Commit 8682dfc

Browse files
committed
Get rid of unnecessary BufDisplay abstraction
1 parent 7a68021 commit 8682dfc

File tree

3 files changed

+6
-28
lines changed

3 files changed

+6
-28
lines changed

src/librustdoc/html/layout.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{self, Display};
1+
use std::fmt::Display;
22
use std::path::PathBuf;
33

44
use askama::Template;
@@ -71,23 +71,6 @@ struct PageLayout<'a> {
7171

7272
pub(crate) use crate::html::render::sidebar::filters;
7373

74-
/// Implements [`Display`] for a function that accepts a mutable reference to a [`String`], and (optionally) writes to it.
75-
///
76-
/// The wrapped function will receive an empty string, and can modify it,
77-
/// and the `Display` implementation will write the contents of the string after the function has finished.
78-
pub(crate) struct BufDisplay<F>(pub F);
79-
80-
impl<F> Display for BufDisplay<F>
81-
where
82-
F: Fn(&mut String),
83-
{
84-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85-
let mut buf = String::new();
86-
self.0(&mut buf);
87-
f.write_str(&buf)
88-
}
89-
}
90-
9174
pub(crate) fn render<T: Display, S: Display>(
9275
layout: &Layout,
9376
page: &Page<'_>,

src/librustdoc/html/render/context.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ use crate::formats::cache::Cache;
2828
use crate::formats::item_type::ItemType;
2929
use crate::html::escape::Escape;
3030
use crate::html::format::join_with_double_colon;
31-
use crate::html::layout::{self, BufDisplay};
3231
use crate::html::markdown::{self, ErrorCodes, IdMap, plain_text_summary};
3332
use crate::html::render::write_shared::write_shared;
3433
use crate::html::url_parts_builder::UrlPartsBuilder;
35-
use crate::html::{sources, static_files};
34+
use crate::html::{layout, sources, static_files};
3635
use crate::scrape_examples::AllCallLocations;
3736
use crate::{DOC_RUST_LANG_ORG_VERSION, try_err};
3837

@@ -250,9 +249,7 @@ impl<'tcx> Context<'tcx> {
250249
layout::render(
251250
&self.shared.layout,
252251
&page,
253-
BufDisplay(|buf: &mut String| {
254-
print_sidebar(self, it, buf).unwrap();
255-
}),
252+
fmt::from_fn(|f| print_sidebar(self, it, f)),
256253
content,
257254
&self.shared.style_files,
258255
)

src/librustdoc/html/sources.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use rustc_session::Session;
1111
use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, sym};
1212
use tracing::info;
1313

14-
use super::highlight;
15-
use super::layout::{self, BufDisplay};
1614
use super::render::Context;
15+
use super::{highlight, layout};
1716
use crate::clean;
1817
use crate::clean::utils::has_doc_flag;
1918
use crate::docfs::PathError;
@@ -243,17 +242,16 @@ impl SourceCollector<'_, '_> {
243242
&shared.layout,
244243
&page,
245244
"",
246-
BufDisplay(|buf: &mut String| {
245+
fmt::from_fn(|f| {
247246
print_src(
248-
buf,
247+
f,
249248
contents,
250249
file_span,
251250
self.cx,
252251
&root_path,
253252
&highlight::DecorationInfo::default(),
254253
&source_context,
255254
)
256-
.unwrap();
257255
}),
258256
&shared.style_files,
259257
);

0 commit comments

Comments
 (0)