about summary refs log tree commit diff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorNick Cameron <nrc@ncameron.org>2019-01-17 20:22:36 +1300
committerGitHub <noreply@github.com>2019-01-17 20:22:36 +1300
commitd2e91b5b68f4b163ab1c041e72028f33a9e3e075 (patch)
tree30e00c41758857082b872560949b1a73ee18ef02 /src/utils.rs
parenta01990c4d0f6415a1e4824cf109125effacaaa81 (diff)
parent083a20fb1aee4daef685735652ae21e9b370350d (diff)
Merge pull request #3284 from scampi/issue-3270
recognize strings inside comments in order to avoid indenting them
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 9efe57e7277..3c260cae22e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -22,7 +22,7 @@ use syntax::source_map::{BytePos, Span, NO_EXPANSION};
 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,11 @@ pub fn trim_left_preserve_layout(orig: &str, indent: Indent, config: &Config) ->
                 Some(get_prefix_space_width(config, &line))
             };
 
-            let line = if veto_trim || (kind.is_string() && !line.ends_with('\\')) {
-                veto_trim = kind.is_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;
                 line
             } else {
@@ -536,9 +539,14 @@ pub fn trim_left_preserve_layout(orig: &str, indent: Indent, config: &Config) ->
             };
             trimmed_lines.push((trimmed, line, prefix_space_width));
 
-            // When computing the minimum, do not consider lines within a string.
-            // The reason is there is a veto against trimming and indenting such lines
+            // 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::InStringCommented | FullCodeCharKind::EndStringCommented
+                    if config.version() == Version::Two =>
+                {
+                    None
+                }
                 FullCodeCharKind::InString | FullCodeCharKind::EndString => None,
                 _ => prefix_space_width,
             }