This commit is contained in:
Nick Cameron 2016-04-22 18:53:39 +12:00
parent 95ff52f06f
commit 9761cf71d8
8 changed files with 31 additions and 34 deletions

View File

@ -201,9 +201,9 @@ fn format_files(files: &Vec<PathBuf>,
println!("");
}
let mut command = try!(Command::new("rustfmt")
.stdout(stdout)
.args(files)
.args(fmt_args)
.spawn());
.stdout(stdout)
.args(files)
.args(fmt_args)
.spawn());
command.wait()
}

View File

@ -191,7 +191,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
Operation::Stdin { input, config_path } => {
// try to read config from local directory
let (mut config, _) = match_cli_path_or_file(config_path, &env::current_dir().unwrap())
.expect("Error resolving config");
.expect("Error resolving config");
// write_mode is always Plain for Stdin.
config.write_mode = WriteMode::Plain;
@ -205,8 +205,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
// Load the config path file if provided
if let Some(config_file) = config_path {
let (cfg_tmp, path_tmp) = resolve_config(config_file.as_ref())
.expect(&format!("Error resolving config for {:?}",
config_file));
.expect(&format!("Error resolving config for {:?}", config_file));
config = cfg_tmp;
path = path_tmp;
};
@ -219,9 +218,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
// Check the file directory if the config-path could not be read or not provided
if path.is_none() {
let (config_tmp, path_tmp) = resolve_config(file.parent().unwrap())
.expect(&format!("Error resolving config \
for {}",
file.display()));
.expect(&format!("Error resolving config for {}", file.display()));
if let Some(path) = path_tmp.as_ref() {
println!("Using rustfmt config file {} for {}",
path.display(),

View File

@ -144,9 +144,8 @@ pub fn rewrite_chain(expr: &ast::Expr,
// Total of all items excluding the last.
let almost_total = rewrites[..rewrites.len() - 1]
.iter()
.fold(0, |a, b| a + first_line_width(b)) +
parent_rewrite.len();
.iter()
.fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len();
let total_width = almost_total + first_line_width(rewrites.last().unwrap());
let veto_single_line = if context.config.take_source_hints && subexpr_list.len() > 1 {
@ -271,8 +270,9 @@ fn chain_indent(context: &RewriteContext, offset: Indent) -> Indent {
fn hacked_chain_indent(context: &RewriteContext, _offset: Indent) -> Indent {
match context.config.chain_indent {
BlockIndentStyle::Inherit => context.block_indent,
BlockIndentStyle::Visual |
BlockIndentStyle::Tabbed => context.block_indent.block_indent(context.config),
BlockIndentStyle::Visual | BlockIndentStyle::Tabbed => {
context.block_indent.block_indent(context.config)
}
}
}

View File

@ -912,7 +912,7 @@ fn format_tuple_struct(context: &RewriteContext,
// know that earlier, so the where clause will not be indented properly.
result.push('\n');
result.push_str(&(context.block_indent + (context.config.tab_spaces - 1))
.to_string(context.config));
.to_string(context.config));
}
result.push_str(&where_clause_str);

View File

@ -112,10 +112,10 @@ impl<'a> FmtVisitor<'a> {
for (kind, offset, subslice) in CommentCodeSlices::new(snippet) {
if let CodeCharKind::Comment = kind {
let last_char = big_snippet[..(offset + big_diff)]
.chars()
.rev()
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c))
.next();
.chars()
.rev()
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c))
.next();
let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));

View File

@ -102,8 +102,8 @@ fn assert_output(source: &str, expected_filename: &str) {
fn idempotence_tests() {
// Get all files in the tests/target directory.
let files = fs::read_dir("tests/target")
.expect("Couldn't read target dir")
.map(get_path_string);
.expect("Couldn't read target dir")
.map(get_path_string);
let (_reports, count, fails) = check_files(files);
// Display results.
@ -116,9 +116,9 @@ fn idempotence_tests() {
#[test]
fn self_tests() {
let files = fs::read_dir("src/bin")
.expect("Couldn't read src dir")
.chain(fs::read_dir("tests").expect("Couldn't read tests dir"))
.map(get_path_string);
.expect("Couldn't read src dir")
.chain(fs::read_dir("tests").expect("Couldn't read tests dir"))
.map(get_path_string);
// Hack because there's no `IntoIterator` impl for `[T; N]`.
let files = files.chain(Some("src/lib.rs".to_owned()).into_iter());
@ -264,7 +264,7 @@ fn read_significant_comments(file_name: &str) -> HashMap<String, String> {
// Matches lines containing significant comments or whitespace.
let line_regex = regex::Regex::new(r"(^\s*$)|(^\s*//\s*rustfmt-[^:]+:\s*\S+)")
.expect("Failed creating pattern 2");
.expect("Failed creating pattern 2");
reader.lines()
.map(|line| line.expect("Failed getting line"))

View File

@ -2,9 +2,9 @@
fn test() {
let x = my_long_function()
.my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
.my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
}

View File

@ -51,9 +51,9 @@ fn main() {
}
let chain = funktion_kall()
.go_to_next_line_with_tab()
.go_to_next_line_with_tab()
.go_to_next_line_with_tab();
.go_to_next_line_with_tab()
.go_to_next_line_with_tab()
.go_to_next_line_with_tab();
let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
yyyyyyyyyyyyyyyyyyyyyyyyyyy,