From 3f144e119ec958b2a6ac3db3568b1bd2b3ba488a Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 13 Sep 2019 08:41:27 -0400 Subject: [PATCH] Move Toc printing from fmt::Display --- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/html/toc.rs | 37 ++++++++++++++------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 1a4fa38ff8db..9ff1e1d31197 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -752,7 +752,7 @@ impl MarkdownWithToc<'_> { html::push_html(&mut s, p); } - format!("{}", toc.into_toc(), s) + format!("{}", toc.into_toc().print(), s) } } diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs index 2da7aceae8bf..0fb2f8dd7962 100644 --- a/src/librustdoc/html/toc.rs +++ b/src/librustdoc/html/toc.rs @@ -1,10 +1,7 @@ //! Table-of-contents creation. -use std::fmt; -use std::string::String; - /// A (recursive) table of contents -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub struct Toc { /// The levels are strictly decreasing, i.e. /// @@ -28,7 +25,7 @@ impl Toc { } } -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub struct TocEntry { level: u32, sec_number: String, @@ -165,25 +162,23 @@ impl TocBuilder { } } -impl fmt::Debug for Toc { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, f) - } -} - -impl fmt::Display for Toc { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(fmt, ""); + } + crate fn print(&self) -> String { + let mut v = String::new(); + self.print_inner(&mut v); + v } }