Skip to content

Commit e82b650

Browse files
committed
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: rust-lang/rust-clippy#7260.
2 parents dd94145 + c08ea17 commit e82b650

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

compiler/rustc_typeck/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ fn missing_items_err(
849849
// Obtain the level of indentation ending in `sugg_sp`.
850850
let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0);
851851
// Make the whitespace that will make the suggestion have the right indentation.
852-
let padding: String = std::iter::repeat(" ").take(indentation).collect();
852+
let padding: String = " ".repeat(indentation);
853853

854854
for trait_item in missing_items {
855855
let snippet = suggestion_signature(&trait_item, tcx);

src/test/ui/issues/issue-20644.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use std::path::Path;
1919

2020
pub fn parse_summary<R: Read>(_: R, _: &Path) {
2121
let path_from_root = Path::new("");
22-
Path::new(&iter::repeat("../")
23-
.take(path_from_root.components().count() - 1)
24-
.collect::<String>());
22+
Path::new(&"../".repeat(path_from_root.components().count() - 1));
2523
}
2624

2725
fn foo() {

0 commit comments

Comments
 (0)