mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Use correct BytePos when recovering comments on removed import
This commit is contained in:
parent
1e7ff38c2d
commit
949708f617
@ -314,11 +314,14 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
Some(ref s) if s.is_empty() => {
|
Some(ref s) if s.is_empty() => {
|
||||||
// Format up to last newline
|
// Format up to last newline
|
||||||
let prev_span = mk_sp(self.last_pos, source!(self, span).lo());
|
let prev_span = mk_sp(self.last_pos, source!(self, span).lo());
|
||||||
let span_end = match self.snippet(prev_span).rfind('\n') {
|
let trimmed_snippet = self.snippet(prev_span).trim_right();
|
||||||
Some(offset) => self.last_pos + BytePos(offset as u32),
|
let span_end = self.last_pos + BytePos(trimmed_snippet.len() as u32);
|
||||||
None => source!(self, span).lo(),
|
|
||||||
};
|
|
||||||
self.format_missing(span_end);
|
self.format_missing(span_end);
|
||||||
|
// We have an excessive newline from the removed import.
|
||||||
|
if self.buffer.ends_with('\n') {
|
||||||
|
self.buffer.pop();
|
||||||
|
self.line_number -= 1;
|
||||||
|
}
|
||||||
self.last_pos = source!(self, span).hi();
|
self.last_pos = source!(self, span).hi();
|
||||||
}
|
}
|
||||||
Some(ref s) => {
|
Some(ref s) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user