diff --git a/src/missed_spans.rs b/src/missed_spans.rs index a6800b15e6111..a957d3b3e3025 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -7,7 +7,7 @@ use crate::config::Version; use crate::coverage::transform_missing_snippet; use crate::shape::{Indent, Shape}; use crate::source_map::LineRangeUtils; -use crate::utils::{count_lf_crlf, count_newlines, last_line_indent, last_line_width, mk_sp}; +use crate::utils::{count_lf_crlf, count_newlines, last_line_width, mk_sp}; use crate::visitor::FmtVisitor; struct SnippetStatus { @@ -254,7 +254,7 @@ impl<'a> FmtVisitor<'a> { // the same level and avoid mixing it with possible other comment. on_same_line = true; self.push_str(" "); - Indent::from_width(self.config, last_line_indent(&self.buffer)) + self.block_indent } else { self.push_str(" "); Indent::from_width(self.config, last_line_width(&self.buffer)) diff --git a/src/utils.rs b/src/utils.rs index 12e3d943417da..47f9cd94b8df5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -205,13 +205,6 @@ pub(crate) fn last_line_width(s: &str) -> usize { unicode_str_width(s.rsplitn(2, '\n').next().unwrap_or("")) } -/// The indent width of the last line in s. -#[inline] -pub(crate) fn last_line_indent(s: &str) -> usize { - let last_line = s.rsplitn(2, '\n').next().unwrap_or(""); - last_line.chars().take_while(|c| c.is_whitespace()).count() -} - /// The total used width of the last line. #[inline] pub(crate) fn last_line_used_width(s: &str, offset: usize) -> usize { diff --git a/tests/source/trailing_comments/hard_tabs.rs b/tests/source/trailing_comments/hard_tabs.rs new file mode 100644 index 0000000000000..88249aa5fb997 --- /dev/null +++ b/tests/source/trailing_comments/hard_tabs.rs @@ -0,0 +1,21 @@ +// rustfmt-version: Two +// rustfmt-wrap_comments: true +// rustfmt-hard_tabs: true + +impl Foo { + fn foo() { + bar(); // comment 1 + // comment 2 + // comment 3 + baz(); + } +} + +fn lorem_ipsum() { + let f = bar(); // Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. Lorem. + // Id turpis. Nam posuere lectus vitae nibh. Etiam tortor orci, sagittis malesuada, rhoncus quis, hendrerit eget, libero. Quisque commodo nulla at nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci bibendum enim, a sagittis nulla nunc quis elit. Phasellus augue. Nunc suscipit, magna tincidunt lacinia faucibus, lacus tellus ornare purus, a pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor faucibus. In hac habitasse platea dictumst. Vivamus a orci at nulla tristique condimentum. Donec arcu quam, dictum accumsan, convallis accumsan, cursus sit amet, ipsum. In pharetra sagittis nunc. + let b = baz(); + + let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0] + // TODO(emilio): It may make sense to make this range [.01, 10.0], to align with css-fonts-4's range of [1, 1000]. +} diff --git a/tests/source/trailing_comments.rs b/tests/source/trailing_comments/soft_tabs.rs similarity index 100% rename from tests/source/trailing_comments.rs rename to tests/source/trailing_comments/soft_tabs.rs diff --git a/tests/target/trailing_comments/hard_tabs.rs b/tests/target/trailing_comments/hard_tabs.rs new file mode 100644 index 0000000000000..35e72f1affdbd --- /dev/null +++ b/tests/target/trailing_comments/hard_tabs.rs @@ -0,0 +1,30 @@ +// rustfmt-version: Two +// rustfmt-wrap_comments: true +// rustfmt-hard_tabs: true + +impl Foo { + fn foo() { + bar(); // comment 1 + // comment 2 + // comment 3 + baz(); + } +} + +fn lorem_ipsum() { + let f = bar(); // Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. Lorem. + // Id turpis. Nam posuere lectus vitae nibh. Etiam tortor orci, sagittis + // malesuada, rhoncus quis, hendrerit eget, libero. Quisque commodo nulla at + // nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci + // bibendum enim, a sagittis nulla nunc quis elit. Phasellus augue. Nunc + // suscipit, magna tincidunt lacinia faucibus, lacus tellus ornare purus, a + // pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor faucibus. + // In hac habitasse platea dictumst. Vivamus a orci at nulla tristique + // condimentum. Donec arcu quam, dictum accumsan, convallis accumsan, cursus sit + // amet, ipsum. In pharetra sagittis nunc. + let b = baz(); + + let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0] + // TODO(emilio): It may make sense to make this range [.01, 10.0], to align + // with css-fonts-4's range of [1, 1000]. +} diff --git a/tests/target/trailing_comments.rs b/tests/target/trailing_comments/soft_tabs.rs similarity index 100% rename from tests/target/trailing_comments.rs rename to tests/target/trailing_comments/soft_tabs.rs