From 3525368a562435622c3c8f293354805e6961b0bf Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sun, 1 Apr 2018 13:48:15 +0900 Subject: [PATCH 1/5] Use str::repeat --- src/libcore/tests/num/dec2flt/parse.rs | 3 +-- src/librustc/util/common.rs | 3 +-- src/librustc_driver/lib.rs | 9 ++------- src/librustc_errors/emitter.rs | 4 +--- src/librustc_mir/hair/pattern/_match.rs | 4 ++-- src/librustdoc/html/format.rs | 20 +++++++++----------- src/librustdoc/html/render.rs | 6 ++---- src/libstd/tests/env.rs | 3 +-- src/libsyntax/print/pprust.rs | 10 ++++------ src/libtest/lib.rs | 3 +-- 10 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/libcore/tests/num/dec2flt/parse.rs b/src/libcore/tests/num/dec2flt/parse.rs index 09acf2bc517b0..3ad694e38adb0 100644 --- a/src/libcore/tests/num/dec2flt/parse.rs +++ b/src/libcore/tests/num/dec2flt/parse.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::iter; use core::num::dec2flt::parse::{Decimal, parse_decimal}; use core::num::dec2flt::parse::ParseResult::{Valid, Invalid}; @@ -46,7 +45,7 @@ fn valid() { assert_eq!(parse_decimal("1.e300"), Valid(Decimal::new(b"1", b"", 300))); assert_eq!(parse_decimal(".1e300"), Valid(Decimal::new(b"", b"1", 300))); assert_eq!(parse_decimal("101e-33"), Valid(Decimal::new(b"101", b"", -33))); - let zeros: String = iter::repeat('0').take(25).collect(); + let zeros = "0".repeat(25); let s = format!("1.5e{}", zeros); assert_eq!(parse_decimal(&s), Valid(Decimal::new(b"1", b"5", 0))); } diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 85533caffce2e..857cabe18b1e2 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -17,7 +17,6 @@ use std::collections::HashMap; use std::ffi::CString; use std::fmt::Debug; use std::hash::{Hash, BuildHasher}; -use std::iter::repeat; use std::panic; use std::env; use std::path::Path; @@ -219,7 +218,7 @@ fn print_time_passes_entry_internal(what: &str, dur: Duration) { None => "".to_owned(), }; println!("{}time: {}{}\t{}", - repeat(" ").take(indentation).collect::(), + " ".repeat(indentation), duration_to_secs_str(dur), mem_string, what); diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 000025c49a698..d896df151a7dc 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -98,7 +98,6 @@ use std::error::Error; use std::ffi::OsString; use std::fmt::{self, Display}; use std::io::{self, Read, Write}; -use std::iter::repeat; use std::mem; use std::panic; use std::path::{PathBuf, Path}; @@ -1253,9 +1252,7 @@ Available lint options: .max() .unwrap_or(0); let padded = |x: &str| { - let mut s = repeat(" ") - .take(max_name_len - x.chars().count()) - .collect::(); + let mut s = " ".repeat(max_name_len - x.chars().count()); s.push_str(x); s }; @@ -1287,9 +1284,7 @@ Available lint options: .unwrap_or(0)); let padded = |x: &str| { - let mut s = repeat(" ") - .take(max_name_len - x.chars().count()) - .collect::(); + let mut s = " ".repeat(max_name_len - x.chars().count()); s.push_str(x); s }; diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 6bcf0d9eff6c5..a392278cab982 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -901,9 +901,7 @@ impl EmitterWriter { // | | length of label // | magic `3` // `max_line_num_len` - let padding = (0..padding + label.len() + 5) - .map(|_| " ") - .collect::(); + let padding = " ".repeat(padding + label.len() + 5); /// Return whether `style`, or the override if present and the style is `NoStyle`. fn style_or_override(style: Style, override_style: Option