diff --git a/src/expr.rs b/src/expr.rs index 1d9625298c5..8665f2a7248 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1187,27 +1187,9 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> .lines() .dropping_back(1) .all(|line| line.ends_with('\\')) + && context.config.version() == Version::Two { - let new_indent = shape.visual_indent(1).indent; - let indented_string_lit = String::from( - string_lit - .lines() - .map(|line| { - format!( - "{}{}", - new_indent.to_string(context.config), - line.trim_start() - ) - }) - .collect::>() - .join("\n") - .trim_start(), - ); - return if context.config.version() == Version::Two { - Some(indented_string_lit) - } else { - wrap_str(indented_string_lit, context.config.max_width(), shape) - }; + return Some(string_lit.to_owned()); } else { return wrap_str(string_lit.to_owned(), context.config.max_width(), shape); } diff --git a/src/utils.rs b/src/utils.rs index 47f9cd94b8d..d01a0ff73ba 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -618,9 +618,8 @@ pub(crate) fn trim_left_preserve_layout( /// Based on the given line, determine if the next line can be indented or not. /// This allows to preserve the indentation of multi-line literals. -pub(crate) fn indent_next_line(kind: FullCodeCharKind, line: &str, config: &Config) -> bool { +pub(crate) fn indent_next_line(kind: FullCodeCharKind, _line: &str, config: &Config) -> bool { !(kind.is_string() || (config.version() == Version::Two && kind.is_commented_string())) - || line.ends_with('\\') } pub(crate) fn is_empty_line(s: &str) -> bool { diff --git a/tests/target/multiline_string_in_macro_def.rs b/tests/target/multiline_string_in_macro_def.rs new file mode 100644 index 00000000000..dafc738f8db --- /dev/null +++ b/tests/target/multiline_string_in_macro_def.rs @@ -0,0 +1,14 @@ +macro_rules! assert_approx_eq { + ($a:expr, $b:expr, $eps:expr) => {{ + let (a, b) = (&$a, &$b); + assert!( + (*a - *b).abs() < $eps, + "assertion failed: `(left !== right)` \ + (left: `{:?}`, right: `{:?}`, expect diff: `{:?}`, real diff: `{:?}`)", + *a, + *b, + $eps, + (*a - *b).abs() + ); + }}; +} diff --git a/tests/target/should_not_format_string_when_format_strings_is_not_set.rs b/tests/target/should_not_format_string_when_format_strings_is_not_set.rs new file mode 100644 index 00000000000..efb755d4aea --- /dev/null +++ b/tests/target/should_not_format_string_when_format_strings_is_not_set.rs @@ -0,0 +1,16 @@ +// format_strings is false by default. + +println!( + "DirEntry {{ \ + binary_name: {:<64}, \ + context_id: {:>2}, \ + file_size: {:>6}, \ + offset: 0x {:>08X}, \ + actual_crc: 0x{:>08X} \ + }}", + dir_entry.binary_name, + dir_entry.context_id, + dir_entry.file_size, + dir_entry.offset, + dir_entry.actual_crc +);