about summary refs log tree commit diff
diff options
context:
space:
mode:
authorklensy <klensy@users.noreply.github.com>2022-05-24 13:35:54 -0400
committerklensy <klensy@users.noreply.github.com>2022-05-24 13:35:54 -0400
commit2a326bcc748edf03a2f64a7a154eab593688c0f6 (patch)
tree2163e49cdc05b1e610b9352c191f98b384d4e89e
parent678059f7d03f05b5a9b81b509d251ac83e87f464 (diff)
downloadrust-2a326bcc748edf03a2f64a7a154eab593688c0f6.tar.gz
rust-2a326bcc748edf03a2f64a7a154eab593688c0f6.zip
fix clippy perf lints
-rw-r--r--src/librustdoc/html/format.rs23
-rw-r--r--src/librustdoc/html/render/mod.rs4
-rw-r--r--src/librustdoc/html/render/search_index.rs4
-rw-r--r--src/librustdoc/html/toc.rs7
4 files changed, 23 insertions, 15 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 589d500cce2..30946834583 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -5,6 +5,7 @@
 //! assume that HTML output is desired, although it may be possible to redesign
 //! them in the future to instead emit any format desired.
 
+use std::borrow::Cow;
 use std::cell::Cell;
 use std::fmt;
 use std::iter;
@@ -1295,9 +1296,11 @@ impl clean::Visibility {
         item_did: ItemId,
         cx: &'a Context<'tcx>,
     ) -> impl fmt::Display + 'a + Captures<'tcx> {
-        let to_print = match self {
-            clean::Public => "pub ".to_owned(),
-            clean::Inherited => String::new(),
+        use std::fmt::Write as _;
+
+        let to_print: Cow<'static, str> = match self {
+            clean::Public => "pub ".into(),
+            clean::Inherited => "".into(),
             clean::Visibility::Restricted(vis_did) => {
                 // FIXME(camelid): This may not work correctly if `item_did` is a module.
                 //                 However, rustdoc currently never displays a module's
@@ -1305,16 +1308,16 @@ impl clean::Visibility {
                 let parent_module = find_nearest_parent_module(cx.tcx(), item_did.expect_def_id());
 
                 if vis_did.is_crate_root() {
-                    "pub(crate) ".to_owned()
+                    "pub(crate) ".into()
                 } else if parent_module == Some(vis_did) {
                     // `pub(in foo)` where `foo` is the parent module
                     // is the same as no visibility modifier
-                    String::new()
+                    "".into()
                 } else if parent_module
                     .and_then(|parent| find_nearest_parent_module(cx.tcx(), parent))
                     == Some(vis_did)
                 {
-                    "pub(super) ".to_owned()
+                    "pub(super) ".into()
                 } else {
                     let path = cx.tcx().def_path(vis_did);
                     debug!("path={:?}", path);
@@ -1324,14 +1327,14 @@ impl clean::Visibility {
 
                     let mut s = "pub(in ".to_owned();
                     for seg in &path.data[..path.data.len() - 1] {
-                        s.push_str(&format!("{}::", seg.data.get_opt_name().unwrap()));
+                        let _ = write!(s, "{}::", seg.data.get_opt_name().unwrap());
                     }
-                    s.push_str(&format!("{}) ", anchor));
-                    s
+                    let _ = write!(s, "{}) ", anchor);
+                    s.into()
                 }
             }
         };
-        display_fn(move |f| f.write_str(&to_print))
+        display_fn(move |f| write!(f, "{}", to_print))
     }
 
     /// This function is the same as print_with_space, except that it renders no links.
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 78191e715b8..3809738cc33 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -2537,6 +2537,8 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
 }
 
 fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
+    use std::fmt::Write as _;
+
     let mut sidebar = String::new();
 
     let item_sections_in_use: FxHashSet<_> = items
@@ -2554,7 +2556,7 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
         .map(|it| item_ty_to_section(it.type_()))
         .collect();
     for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) {
-        sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name()));
+        let _ = write!(sidebar, "<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name());
     }
 
     if !sidebar.is_empty() {
diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 45e447064a5..3daef3dbb79 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -182,8 +182,8 @@ pub(crate) fn build_index<'tcx>(
         })
         .expect("failed serde conversion")
         // All these `replace` calls are because we have to go through JS string for JSON content.
-        .replace(r#"\"#, r"\\")
-        .replace(r#"'"#, r"\'")
+        .replace('\\', r"\\")
+        .replace('\'', r"\'")
         // We need to escape double quotes for the JSON.
         .replace("\\\"", "\\\\\"")
     )
diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs
index 07e33052aa7..a12c2a6a16c 100644
--- a/src/librustdoc/html/toc.rs
+++ b/src/librustdoc/html/toc.rs
@@ -163,15 +163,18 @@ impl TocBuilder {
 
 impl Toc {
     fn print_inner(&self, v: &mut String) {
+        use std::fmt::Write as _;
+
         v.push_str("<ul>");
         for entry in &self.entries {
             // recursively format this table of contents
-            v.push_str(&format!(
+            let _ = write!(
+                v,
                 "\n<li><a href=\"#{id}\">{num} {name}</a>",
                 id = entry.id,
                 num = entry.sec_number,
                 name = entry.name
-            ));
+            );
             entry.children.print_inner(&mut *v);
             v.push_str("</li>");
         }