Skip to content

Commit 69c7dbc

Browse files
xiongmao86topecongiro
authored andcommitted
Try to solve issue3456. (#3556)
1 parent 3a073f1 commit 69c7dbc

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

src/expr.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,27 +1187,9 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
11871187
.lines()
11881188
.dropping_back(1)
11891189
.all(|line| line.ends_with('\\'))
1190+
&& context.config.version() == Version::Two
11901191
{
1191-
let new_indent = shape.visual_indent(1).indent;
1192-
let indented_string_lit = String::from(
1193-
string_lit
1194-
.lines()
1195-
.map(|line| {
1196-
format!(
1197-
"{}{}",
1198-
new_indent.to_string(context.config),
1199-
line.trim_start()
1200-
)
1201-
})
1202-
.collect::<Vec<_>>()
1203-
.join("\n")
1204-
.trim_start(),
1205-
);
1206-
return if context.config.version() == Version::Two {
1207-
Some(indented_string_lit)
1208-
} else {
1209-
wrap_str(indented_string_lit, context.config.max_width(), shape)
1210-
};
1192+
return Some(string_lit.to_owned());
12111193
} else {
12121194
return wrap_str(string_lit.to_owned(), context.config.max_width(), shape);
12131195
}

src/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,8 @@ pub(crate) fn trim_left_preserve_layout(
618618

619619
/// Based on the given line, determine if the next line can be indented or not.
620620
/// This allows to preserve the indentation of multi-line literals.
621-
pub(crate) fn indent_next_line(kind: FullCodeCharKind, line: &str, config: &Config) -> bool {
621+
pub(crate) fn indent_next_line(kind: FullCodeCharKind, _line: &str, config: &Config) -> bool {
622622
!(kind.is_string() || (config.version() == Version::Two && kind.is_commented_string()))
623-
|| line.ends_with('\\')
624623
}
625624

626625
pub(crate) fn is_empty_line(s: &str) -> bool {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
macro_rules! assert_approx_eq {
2+
($a:expr, $b:expr, $eps:expr) => {{
3+
let (a, b) = (&$a, &$b);
4+
assert!(
5+
(*a - *b).abs() < $eps,
6+
"assertion failed: `(left !== right)` \
7+
(left: `{:?}`, right: `{:?}`, expect diff: `{:?}`, real diff: `{:?}`)",
8+
*a,
9+
*b,
10+
$eps,
11+
(*a - *b).abs()
12+
);
13+
}};
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// format_strings is false by default.
2+
3+
println!(
4+
"DirEntry {{ \
5+
binary_name: {:<64}, \
6+
context_id: {:>2}, \
7+
file_size: {:>6}, \
8+
offset: 0x {:>08X}, \
9+
actual_crc: 0x{:>08X} \
10+
}}",
11+
dir_entry.binary_name,
12+
dir_entry.context_id,
13+
dir_entry.file_size,
14+
dir_entry.offset,
15+
dir_entry.actual_crc
16+
);

0 commit comments

Comments
 (0)