Skip to content

Commit

Permalink
Auto merge of rust-lang#85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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: rust-lang/rust-clippy#7260.
  • Loading branch information
bors committed Jun 20, 2021
2 parents dd94145 + c08ea17 commit e82b650
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/issues/issue-20644.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e82b650

Please sign in to comment.