]> git.lizzy.rs Git - rust.git/commitdiff
Align multiline string literal
authorSeiichi Uchida <topecongiro@localhost.localdomain>
Sun, 18 Jun 2017 13:44:56 +0000 (22:44 +0900)
committerSeiichi Uchida <topecongiro@localhost.localdomain>
Sun, 18 Jun 2017 13:44:56 +0000 (22:44 +0900)
src/expr.rs

index b69e8bbd42eaf4b6b5472b7322c494098429139f..b667eae8b146d3ab9f886eefe9cae95b93d8c952 100644 (file)
@@ -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::<Vec<_>>()
+                    .join("\n")
+                    .trim_left(),
+            ));
+        } else {
+            return Some(string_lit);
+        }
     }
 
     if !context.config.force_format_strings() &&