This commit is contained in:
Shotaro Yamada 2018-10-10 10:50:25 +09:00
parent 751bcf5fa0
commit 6380f88527
2 changed files with 4 additions and 18 deletions

View File

@ -120,7 +120,7 @@ fn format_missing_inner<F: Fn(&mut FmtVisitor, &str, &str)>(
}
fn push_vertical_spaces(&mut self, mut newline_count: usize) {
let offset = self.count_trailing_newlines();
let offset = self.buffer.chars().rev().take_while(|c| *c == '\n').count();
let newline_upper_bound = self.config.blank_lines_upper_bound() + 1;
let newline_lower_bound = self.config.blank_lines_lower_bound() + 1;
@ -142,16 +142,6 @@ fn push_vertical_spaces(&mut self, mut newline_count: usize) {
self.push_str(&blank_lines);
}
fn count_trailing_newlines(&self) -> usize {
let mut buf = &*self.buffer;
let mut result = 0;
while buf.ends_with('\n') {
buf = &buf[..buf.len() - 1];
result += 1;
}
result
}
fn write_snippet<F>(&mut self, span: Span, process_last_snippet: F)
where
F: Fn(&mut FmtVisitor, &str, &str),
@ -271,11 +261,7 @@ fn process_comment(
if let Some('/') = subslice.chars().nth(1) {
// check that there are no contained block comments
if !subslice
.split('\n')
.map(|s| s.trim_left())
.any(|s| s.len() >= 2 && &s[0..2] == "/*")
{
if !subslice.lines().any(|s| s.trim_left().starts_with("/*")) {
// Add a newline after line comments
self.push_str("\n");
}

View File

@ -242,9 +242,9 @@ fn break_string(max_chars: usize, trim_end: bool, line_end: &str, input: &[&str]
for (i, grapheme) in input[0..=index].iter().enumerate() {
if is_line_feed(grapheme) {
if i <= index_minus_ws {
let mut line = input[0..i].join("");
let mut line = &input[0..i].join("")[..];
if trim_end {
line = line.trim_right().to_string();
line = line.trim_right();
}
return SnippetState::EndWithLineFeed(format!("{}\n", line), i + 1);
}