about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-06-20 20:07:13 +0000
committerbors <bors@rust-lang.org>2021-06-20 20:07:13 +0000
commite82b65026dcadf0998e3abf9dabc677f63160de7 (patch)
tree0670c35787abd16bdadd0bac977a6a37d4050557
parentdd941450fbf705129dff8ce021d4b5602563555a (diff)
parentc08ea1724b0b21a0ef81ee2d6976b0a3cf2db043 (diff)
downloadrust-e82b65026dcadf0998e3abf9dabc677f63160de7.tar.gz
rust-e82b65026dcadf0998e3abf9dabc677f63160de7.zip
Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
Replace some `std::iter::repeat` with `str::repeat`

I noticed that there were some instances where `std::iter::repeat` would be used to repeat a string or a char to take a specific count of it and then collect it into a `String` when `str::repeat` is actually much faster and better for that.

See also: https://github.com/rust-lang/rust-clippy/issues/7260.
-rw-r--r--compiler/rustc_typeck/src/check/mod.rs2
-rw-r--r--src/test/ui/issues/issue-20644.rs4
2 files changed, 2 insertions, 4 deletions
diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs
index d102896bfa6..8703949f488 100644
--- a/compiler/rustc_typeck/src/check/mod.rs
+++ b/compiler/rustc_typeck/src/check/mod.rs
@@ -849,7 +849,7 @@ fn missing_items_err(
     // Obtain the level of indentation ending in `sugg_sp`.
     let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0);
     // Make the whitespace that will make the suggestion have the right indentation.
-    let padding: String = std::iter::repeat(" ").take(indentation).collect();
+    let padding: String = " ".repeat(indentation);
 
     for trait_item in missing_items {
         let snippet = suggestion_signature(&trait_item, tcx);
diff --git a/src/test/ui/issues/issue-20644.rs b/src/test/ui/issues/issue-20644.rs
index 71c6746e0e0..1b90727fbc0 100644
--- a/src/test/ui/issues/issue-20644.rs
+++ b/src/test/ui/issues/issue-20644.rs
@@ -19,9 +19,7 @@ use std::path::Path;
 
 pub fn parse_summary<R: Read>(_: R, _: &Path) {
      let path_from_root = Path::new("");
-     Path::new(&iter::repeat("../")
-               .take(path_from_root.components().count() - 1)
-               .collect::<String>());
+     Path::new(&"../".repeat(path_from_root.components().count() - 1));
  }
 
 fn foo() {