Merge pull request #1724 from topecongiro/multiline-string-lit

Align multiline string literal
This commit is contained in:
Nick Cameron 2017-06-19 13:02:21 +12:00 committed by GitHub
commit 82d95cc4e0
5 changed files with 24 additions and 5 deletions

View file

@ -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)
);
}

View file

@ -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(

View file

@ -55,7 +55,7 @@ where
write!(
writer,
"<error line=\"{}\" severity=\"warning\" message=\"Should be `{}`\" \
/>",
/>",
mismatch.line_number,
message
)?;

View file

@ -1857,7 +1857,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() &&

View file

@ -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"
);
}
}