mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
Merge pull request #2351 from topecongiro/issue-2256
Use correct BytePos when recovering comments on removed import
This commit is contained in:
+7
-4
@@ -314,11 +314,14 @@ pub fn format_import(&mut self, item: &ast::Item, tree: &ast::UseTree) {
|
||||
Some(ref s) if s.is_empty() => {
|
||||
// Format up to last newline
|
||||
let prev_span = mk_sp(self.last_pos, source!(self, span).lo());
|
||||
let span_end = match self.snippet(prev_span).rfind('\n') {
|
||||
Some(offset) => self.last_pos + BytePos(offset as u32),
|
||||
None => source!(self, span).lo(),
|
||||
};
|
||||
let trimmed_snippet = self.snippet(prev_span).trim_right();
|
||||
let span_end = self.last_pos + BytePos(trimmed_snippet.len() as u32);
|
||||
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();
|
||||
}
|
||||
Some(ref s) => {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// こんにちは
|
||||
use std::{};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/* comment */ use std::{};
|
||||
/* comment */ use std::{};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* comment */ use std::{};
|
||||
@@ -0,0 +1,7 @@
|
||||
// こんにちは
|
||||
use std::borrow::Cow;
|
||||
|
||||
/* comment */
|
||||
/* comment */
|
||||
|
||||
/* comment */
|
||||
Reference in New Issue
Block a user