Use str::repeat
This commit is contained in:
parent
e6423cf4b1
commit
ed46a777c8
@ -104,7 +104,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
|
||||
};
|
||||
let parent_rewrite = parent
|
||||
.rewrite(context, parent_shape)
|
||||
.map(|parent_rw| parent_rw + &repeat_try(prefix_try_num))?;
|
||||
.map(|parent_rw| parent_rw + &"?".repeat(prefix_try_num))?;
|
||||
let parent_rewrite_contains_newline = parent_rewrite.contains('\n');
|
||||
let is_small_parent = parent_rewrite.len() <= context.config.tab_spaces();
|
||||
|
||||
@ -297,7 +297,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
|
||||
join_rewrites(&rewrites, &connector)
|
||||
)
|
||||
};
|
||||
let result = format!("{}{}", result, repeat_try(suffix_try_num));
|
||||
let result = format!("{}{}", result, "?".repeat(suffix_try_num));
|
||||
if context.config.indent_style() == IndentStyle::Visual {
|
||||
wrap_str(result, context.config.max_width(), shape)
|
||||
} else {
|
||||
@ -318,10 +318,6 @@ fn chain_only_try(exprs: &[ast::Expr]) -> bool {
|
||||
|
||||
// Try to rewrite and replace the last non-try child. Return `true` if
|
||||
// replacing succeeds.
|
||||
fn repeat_try(try_count: usize) -> String {
|
||||
iter::repeat("?").take(try_count).collect::<String>()
|
||||
}
|
||||
|
||||
fn rewrite_try(
|
||||
expr: &ast::Expr,
|
||||
try_count: usize,
|
||||
@ -329,7 +325,7 @@ fn rewrite_try(
|
||||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
let sub_expr = expr.rewrite(context, shape.sub_width(try_count)?)?;
|
||||
Some(format!("{}{}", sub_expr, repeat_try(try_count)))
|
||||
Some(format!("{}{}", sub_expr, "?".repeat(try_count)))
|
||||
}
|
||||
|
||||
fn join_rewrites(rewrites: &[String], connector: &str) -> String {
|
||||
|
@ -34,7 +34,6 @@ extern crate unicode_segmentation;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::io::{self, stdout, BufRead, Write};
|
||||
use std::iter::repeat;
|
||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
@ -200,7 +199,7 @@ impl FormatReport {
|
||||
for (file, errors) in &self.file_error_map {
|
||||
for error in errors {
|
||||
let prefix_space_len = error.line.to_string().len();
|
||||
let prefix_spaces: String = repeat(" ").take(1 + prefix_space_len).collect();
|
||||
let prefix_spaces = " ".repeat(1 + prefix_space_len);
|
||||
|
||||
// First line: the overview of error
|
||||
t.fg(term::color::RED)?;
|
||||
@ -259,8 +258,8 @@ impl FormatReport {
|
||||
}
|
||||
|
||||
fn target_str(space_len: usize, target_len: usize) -> String {
|
||||
let empty_line: String = repeat(" ").take(space_len).collect();
|
||||
let overflowed: String = repeat("^").take(target_len).collect();
|
||||
let empty_line = " ".repeat(space_len);
|
||||
let overflowed = "^".repeat(target_len);
|
||||
empty_line + &overflowed
|
||||
}
|
||||
|
||||
@ -270,7 +269,7 @@ impl fmt::Display for FormatReport {
|
||||
for (file, errors) in &self.file_error_map {
|
||||
for error in errors {
|
||||
let prefix_space_len = error.line.to_string().len();
|
||||
let prefix_spaces: String = repeat(" ").take(1 + prefix_space_len).collect();
|
||||
let prefix_spaces = " ".repeat(1 + prefix_space_len);
|
||||
|
||||
let error_line_buffer = if error.line_buffer.is_empty() {
|
||||
String::from(" ")
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::iter::repeat;
|
||||
|
||||
use syntax::codemap::{BytePos, FileName, Pos, Span};
|
||||
|
||||
@ -122,7 +121,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let blank_lines: String = repeat('\n').take(newline_count).collect();
|
||||
let blank_lines = "\n".repeat(newline_count);
|
||||
self.push_str(&blank_lines);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user