Skip to content

Commit

Permalink
Replace some std::iter::repeat with str::repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
wooster0 committed Jun 4, 2021
1 parent 6f5a198 commit c08ea17
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 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 @@ -858,7 +858,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
3 changes: 1 addition & 2 deletions src/tools/clippy/clippy_lints/src/mem_discriminant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc_errors::Applicability;
use rustc_hir::{BorrowKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::iter;

declare_clippy_lint! {
/// **What it does:** Checks for calls of `mem::discriminant()` on a non-enum type.
Expand Down Expand Up @@ -67,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for MemDiscriminant {
}
}

let derefs: String = iter::repeat('*').take(derefs_needed).collect();
let derefs = "*".repeat(derefs_needed);
diag.span_suggestion(
param.span,
"try dereferencing",
Expand Down
5 changes: 2 additions & 3 deletions src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, MatchSource, Node, PatKind};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, adjustment::Adjust};
use rustc_span::symbol::{sym, Symbol};
use std::iter;

use super::CLONE_DOUBLE_REF;
use super::CLONE_ON_COPY;
Expand Down Expand Up @@ -54,8 +53,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol,
ty = inner;
n += 1;
}
let refs: String = iter::repeat('&').take(n + 1).collect();
let derefs: String = iter::repeat('*').take(n).collect();
let refs = "&".repeat(n + 1);
let derefs = "*".repeat(n);
let explicit = format!("<{}{}>::clone({})", refs, ty, snip);
diag.span_suggestion(
expr.span,
Expand Down

0 comments on commit c08ea17

Please sign in to comment.