Skip to content

Commit 82d95cc

Browse files
authored
Merge pull request #1724 from topecongiro/multiline-string-lit
Align multiline string literal
2 parents 392d34b + 75d86eb commit 82d95cc

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

src/bin/cargo-fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn print_usage(opts: &Options, reason: &str) {
9494
let msg = format!("{}\nusage: cargo fmt [options]", reason);
9595
println!(
9696
"{}\nThis utility formats all bin and lib files of the current crate using rustfmt. \
97-
Arguments after `--` are passed to rustfmt.",
97+
Arguments after `--` are passed to rustfmt.",
9898
opts.usage(&msg)
9999
);
100100
}

src/bin/rustfmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn make_opts() -> Options {
144144
"",
145145
"config-path",
146146
"Recursively searches the given path for the rustfmt.toml config file. If not \
147-
found reverts to the input file path",
147+
found reverts to the input file path",
148148
"[Path for the configuration file]",
149149
);
150150
opts.optopt(

src/checkstyle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ where
5555
write!(
5656
writer,
5757
"<error line=\"{}\" severity=\"warning\" message=\"Should be `{}`\" \
58-
/>",
58+
/>",
5959
mismatch.line_number,
6060
message
6161
)?;

src/expr.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,26 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
18571857
let string_lit = context.snippet(span);
18581858

18591859
if !context.config.format_strings() && !context.config.force_format_strings() {
1860-
return Some(string_lit);
1860+
if string_lit
1861+
.lines()
1862+
.rev()
1863+
.skip(1)
1864+
.all(|line| line.ends_with('\\'))
1865+
{
1866+
let new_indent = shape.visual_indent(1).indent;
1867+
return Some(String::from(
1868+
string_lit
1869+
.lines()
1870+
.map(|line| {
1871+
new_indent.to_string(context.config) + line.trim_left()
1872+
})
1873+
.collect::<Vec<_>>()
1874+
.join("\n")
1875+
.trim_left(),
1876+
));
1877+
} else {
1878+
return Some(string_lit);
1879+
}
18611880
}
18621881

18631882
if !context.config.force_format_strings() &&

src/file_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl<'de> ::serde::de::Deserialize<'de> for FileLines {
228228
{
229229
panic!(
230230
"FileLines cannot be deserialized from a project rustfmt.toml file: please \
231-
specify it via the `--file-lines` option instead"
231+
specify it via the `--file-lines` option instead"
232232
);
233233
}
234234
}

0 commit comments

Comments
 (0)