diff --git a/src/utils.rs b/src/utils.rs index dd480f9788f..2f357d7e359 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -22,7 +22,7 @@ use syntax_pos::Mark; use comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses}; -use config::Config; +use config::{Config, Version}; use rewrite::RewriteContext; 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)) }; - let new_veto_trim_value = - (kind.is_string() || kind.is_commented_string()) && !line.ends_with('\\'); + let new_veto_trim_value = (kind.is_string() + || (config.version() == Version::Two && kind.is_commented_string())) + && !line.ends_with('\\'); let line = if veto_trim || new_veto_trim_value { veto_trim = new_veto_trim_value; 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, // such lines should not be taken into account when computing the minimum. match kind { - FullCodeCharKind::InString - | FullCodeCharKind::EndString - | FullCodeCharKind::InStringCommented - | FullCodeCharKind::EndStringCommented => None, + FullCodeCharKind::InStringCommented | FullCodeCharKind::EndStringCommented + if config.version() == Version::Two => + { + None + } + FullCodeCharKind::InString | FullCodeCharKind::EndString => None, _ => prefix_space_width, } }) diff --git a/tests/target/issue-3270.rs b/tests/source/issue-3270/one.rs similarity index 83% rename from tests/target/issue-3270.rs rename to tests/source/issue-3270/one.rs index 4f624f1193b..3c2e27e2293 100644 --- a/tests/target/issue-3270.rs +++ b/tests/source/issue-3270/one.rs @@ -1,3 +1,5 @@ +// rustfmt-version: One + pub fn main() { /* let s = String::from( " diff --git a/tests/source/issue-3270.rs b/tests/source/issue-3270/two.rs similarity index 82% rename from tests/source/issue-3270.rs rename to tests/source/issue-3270/two.rs index 9b1a66a63b7..0eb756471e7 100644 --- a/tests/source/issue-3270.rs +++ b/tests/source/issue-3270/two.rs @@ -1,3 +1,5 @@ +// rustfmt-version: Two + pub fn main() { /* let s = String::from( " diff --git a/tests/target/issue-3132.rs b/tests/target/issue-3132.rs index c3d24fc10f6..4dffe0ab836 100644 --- a/tests/target/issue-3132.rs +++ b/tests/target/issue-3132.rs @@ -1,3 +1,5 @@ +// rustfmt-version: Two + fn test() { /* a diff --git a/tests/target/issue-3270/one.rs b/tests/target/issue-3270/one.rs new file mode 100644 index 00000000000..78de9473243 --- /dev/null +++ b/tests/target/issue-3270/one.rs @@ -0,0 +1,12 @@ +// rustfmt-version: One + +pub fn main() { + /* let s = String::from( + " + hello + world + ", + ); */ + + assert_eq!(s, "\nhello\nworld\n"); +} diff --git a/tests/target/issue-3270/two.rs b/tests/target/issue-3270/two.rs new file mode 100644 index 00000000000..e48b5921329 --- /dev/null +++ b/tests/target/issue-3270/two.rs @@ -0,0 +1,12 @@ +// rustfmt-version: Two + +pub fn main() { + /* let s = String::from( + " +hello +world +", + ); */ + + assert_eq!(s, "\nhello\nworld\n"); +} diff --git a/tests/target/issue-3270-wrap.rs b/tests/target/issue-3270/wrap.rs similarity index 51% rename from tests/target/issue-3270-wrap.rs rename to tests/target/issue-3270/wrap.rs index e27f71aa32f..7435c5f0866 100644 --- a/tests/target/issue-3270-wrap.rs +++ b/tests/target/issue-3270/wrap.rs @@ -1,9 +1,12 @@ // 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() { 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 three lines"; */