From ae9ce7bcd9e628e3a4df5a3da91e7dfc29dff9f2 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sun, 18 Jun 2017 22:44:56 +0900 Subject: [PATCH 1/2] Align multiline string literal --- src/expr.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index b69e8bbd42ea..b667eae8b146 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1856,7 +1856,26 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt let string_lit = context.snippet(span); if !context.config.format_strings() && !context.config.force_format_strings() { - return Some(string_lit); + if string_lit + .lines() + .rev() + .skip(1) + .all(|line| line.ends_with('\\')) + { + let new_indent = shape.visual_indent(1).indent; + return Some(String::from( + string_lit + .lines() + .map(|line| { + new_indent.to_string(context.config) + line.trim_left() + }) + .collect::>() + .join("\n") + .trim_left(), + )); + } else { + return Some(string_lit); + } } if !context.config.force_format_strings() && From 75d86eb1a04e1179cddf093da25082def9da570c Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sun, 18 Jun 2017 22:45:08 +0900 Subject: [PATCH 2/2] Format source codes --- Cargo.lock | 2 +- src/bin/cargo-fmt.rs | 2 +- src/bin/rustfmt.rs | 2 +- src/checkstyle.rs | 2 +- src/file_lines.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d56da60ea21a..c17aea726969 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "rustfmt-nightly" -version = "0.1.2" +version = "0.1.3" dependencies = [ "diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/bin/cargo-fmt.rs b/src/bin/cargo-fmt.rs index eeccae5c0776..93348b829966 100644 --- a/src/bin/cargo-fmt.rs +++ b/src/bin/cargo-fmt.rs @@ -94,7 +94,7 @@ fn print_usage(opts: &Options, reason: &str) { let msg = format!("{}\nusage: cargo fmt [options]", reason); println!( "{}\nThis utility formats all bin and lib files of the current crate using rustfmt. \ - Arguments after `--` are passed to rustfmt.", + Arguments after `--` are passed to rustfmt.", opts.usage(&msg) ); } diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index 58b7e3ac8fd0..e819579db143 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -144,7 +144,7 @@ fn make_opts() -> Options { "", "config-path", "Recursively searches the given path for the rustfmt.toml config file. If not \ - found reverts to the input file path", + found reverts to the input file path", "[Path for the configuration file]", ); opts.optopt( diff --git a/src/checkstyle.rs b/src/checkstyle.rs index 90ba45610246..7b7ab2e1b2de 100644 --- a/src/checkstyle.rs +++ b/src/checkstyle.rs @@ -55,7 +55,7 @@ where write!( writer, "", + />", mismatch.line_number, message )?; diff --git a/src/file_lines.rs b/src/file_lines.rs index 81755eae8051..939a7bf09a4b 100644 --- a/src/file_lines.rs +++ b/src/file_lines.rs @@ -228,7 +228,7 @@ impl<'de> ::serde::de::Deserialize<'de> for FileLines { { panic!( "FileLines cannot be deserialized from a project rustfmt.toml file: please \ - specify it via the `--file-lines` option instead" + specify it via the `--file-lines` option instead" ); } }