mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-06 13:44:13 +00:00
Remove empty lines at the beginning of the file
This commit is contained in:
parent
6ce42823cb
commit
05798572bb
@ -321,6 +321,7 @@ where
|
||||
let filemap = visitor.codemap.lookup_char_pos(module.inner.lo()).file;
|
||||
// Format inner attributes if available.
|
||||
if !krate.attrs.is_empty() && path == main_file {
|
||||
visitor.skip_empty_lines(filemap.end_pos);
|
||||
if visitor.visit_attrs(&krate.attrs, ast::AttrStyle::Inner) {
|
||||
visitor.push_rewrite(module.inner, None);
|
||||
} else {
|
||||
@ -328,6 +329,7 @@ where
|
||||
}
|
||||
} else {
|
||||
visitor.last_pos = filemap.start_pos;
|
||||
visitor.skip_empty_lines(filemap.end_pos);
|
||||
visitor.format_separate_mod(module, &*filemap);
|
||||
};
|
||||
|
||||
|
@ -699,6 +699,20 @@ impl<'a> FmtVisitor<'a> {
|
||||
self.format_missing_with_indent(filemap.end_pos);
|
||||
}
|
||||
|
||||
pub fn skip_empty_lines(&mut self, end_pos: BytePos) {
|
||||
while let Some(pos) = self.codemap
|
||||
.opt_span_after(mk_sp(self.last_pos, end_pos), "\n")
|
||||
{
|
||||
if let Some(snippet) = self.opt_snippet(mk_sp(self.last_pos, pos)) {
|
||||
if snippet.trim().is_empty() {
|
||||
self.last_pos = pos;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_context(&self) -> RewriteContext {
|
||||
RewriteContext {
|
||||
parse_session: self.parse_session,
|
||||
|
Loading…
Reference in New Issue
Block a user