version-gate the formatting of commented strings
This commit is contained in:
parent
baa62c609e
commit
083a20fb1a
17
src/utils.rs
17
src/utils.rs
@ -22,7 +22,7 @@ use syntax::source_map::{BytePos, Span, NO_EXPANSION};
|
|||||||
use syntax_pos::Mark;
|
use syntax_pos::Mark;
|
||||||
|
|
||||||
use comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
|
use comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
|
||||||
use config::Config;
|
use config::{Config, Version};
|
||||||
use rewrite::RewriteContext;
|
use rewrite::RewriteContext;
|
||||||
use shape::{Indent, Shape};
|
use shape::{Indent, Shape};
|
||||||
|
|
||||||
@ -527,8 +527,9 @@ pub fn trim_left_preserve_layout(orig: &str, indent: Indent, config: &Config) ->
|
|||||||
Some(get_prefix_space_width(config, &line))
|
Some(get_prefix_space_width(config, &line))
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_veto_trim_value =
|
let new_veto_trim_value = (kind.is_string()
|
||||||
(kind.is_string() || kind.is_commented_string()) && !line.ends_with('\\');
|
|| (config.version() == Version::Two && kind.is_commented_string()))
|
||||||
|
&& !line.ends_with('\\');
|
||||||
let line = if veto_trim || new_veto_trim_value {
|
let line = if veto_trim || new_veto_trim_value {
|
||||||
veto_trim = new_veto_trim_value;
|
veto_trim = new_veto_trim_value;
|
||||||
trimmed = false;
|
trimmed = false;
|
||||||
@ -541,10 +542,12 @@ pub fn trim_left_preserve_layout(orig: &str, indent: Indent, config: &Config) ->
|
|||||||
// Because there is a veto against trimming and indenting lines within a string,
|
// Because there is a veto against trimming and indenting lines within a string,
|
||||||
// such lines should not be taken into account when computing the minimum.
|
// such lines should not be taken into account when computing the minimum.
|
||||||
match kind {
|
match kind {
|
||||||
FullCodeCharKind::InString
|
FullCodeCharKind::InStringCommented | FullCodeCharKind::EndStringCommented
|
||||||
| FullCodeCharKind::EndString
|
if config.version() == Version::Two =>
|
||||||
| FullCodeCharKind::InStringCommented
|
{
|
||||||
| FullCodeCharKind::EndStringCommented => None,
|
None
|
||||||
|
}
|
||||||
|
FullCodeCharKind::InString | FullCodeCharKind::EndString => None,
|
||||||
_ => prefix_space_width,
|
_ => prefix_space_width,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// rustfmt-version: One
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
/* let s = String::from(
|
/* let s = String::from(
|
||||||
"
|
"
|
@ -1,3 +1,5 @@
|
|||||||
|
// rustfmt-version: Two
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
/* let s = String::from(
|
/* let s = String::from(
|
||||||
"
|
"
|
@ -1,3 +1,5 @@
|
|||||||
|
// rustfmt-version: Two
|
||||||
|
|
||||||
fn test() {
|
fn test() {
|
||||||
/*
|
/*
|
||||||
a
|
a
|
||||||
|
12
tests/target/issue-3270/one.rs
Normal file
12
tests/target/issue-3270/one.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// rustfmt-version: One
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
/* let s = String::from(
|
||||||
|
"
|
||||||
|
hello
|
||||||
|
world
|
||||||
|
",
|
||||||
|
); */
|
||||||
|
|
||||||
|
assert_eq!(s, "\nhello\nworld\n");
|
||||||
|
}
|
12
tests/target/issue-3270/two.rs
Normal file
12
tests/target/issue-3270/two.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// rustfmt-version: Two
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
/* let s = String::from(
|
||||||
|
"
|
||||||
|
hello
|
||||||
|
world
|
||||||
|
",
|
||||||
|
); */
|
||||||
|
|
||||||
|
assert_eq!(s, "\nhello\nworld\n");
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
// rustfmt-wrap_comments: true
|
// rustfmt-wrap_comments: true
|
||||||
|
// rustfmt-version: Two
|
||||||
|
|
||||||
|
// check that a line below max_width does not get over the limit when wrapping
|
||||||
|
// it in a block comment
|
||||||
fn func() {
|
fn func() {
|
||||||
let x = 42;
|
let x = 42;
|
||||||
/*
|
/*
|
||||||
let something = "one line line line line line line line line line line line line
|
let something = "one line line line line line line line line line line line line line
|
||||||
two lines
|
two lines
|
||||||
three lines";
|
three lines";
|
||||||
*/
|
*/
|
Loading…
x
Reference in New Issue
Block a user