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_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,
|
||||
}
|
||||
})
|
||||
|
@ -1,3 +1,5 @@
|
||||
// rustfmt-version: One
|
||||
|
||||
pub fn main() {
|
||||
/* let s = String::from(
|
||||
"
|
@ -1,3 +1,5 @@
|
||||
// rustfmt-version: Two
|
||||
|
||||
pub fn main() {
|
||||
/* let s = String::from(
|
||||
"
|
@ -1,3 +1,5 @@
|
||||
// rustfmt-version: Two
|
||||
|
||||
fn test() {
|
||||
/*
|
||||
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-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";
|
||||
*/
|
Loading…
Reference in New Issue
Block a user