// except according to those terms.
use syntax::attr::HasAttrs;
-use syntax::codemap::{self, BytePos, CodeMap, Pos, Span};
use syntax::parse::ParseSess;
+use syntax::source_map::{self, BytePos, Pos, SourceMap, Span};
use syntax::{ast, visit};
use attr::*;
-use codemap::{LineRangeUtils, SpanUtils};
use comment::{CodeCharKind, CommentCodeSlices, FindUncommented};
use config::{BraceStyle, Config};
use items::{
use macros::{rewrite_macro, rewrite_macro_def, MacroPosition};
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
+use source_map::{LineRangeUtils, SpanUtils};
use spanned::Spanned;
use utils::{
self, contains_skip, count_newlines, inner_attributes, mk_sp, ptr_vec_to_ref_vec,
pub struct FmtVisitor<'a> {
pub parse_session: &'a ParseSess,
- pub codemap: &'a CodeMap,
+ pub source_map: &'a SourceMap,
pub buffer: String,
pub last_pos: BytePos,
// FIXME: use an RAII util or closure for indenting
fn visit_stmt(&mut self, stmt: &ast::Stmt) {
debug!(
"visit_stmt: {:?} {:?}",
- self.codemap.lookup_char_pos(stmt.span.lo()),
- self.codemap.lookup_char_pos(stmt.span.hi())
+ self.source_map.lookup_char_pos(stmt.span.lo()),
+ self.source_map.lookup_char_pos(stmt.span.hi())
);
match stmt.node {
ast::StmtKind::Item(ref item) => {
self.visit_item(item);
+ // Handle potential `;` after the item.
+ self.format_missing(stmt.span.hi());
}
ast::StmtKind::Local(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => {
if contains_skip(get_attrs_from_stmt(stmt)) {
) {
debug!(
"visit_block: {:?} {:?}",
- self.codemap.lookup_char_pos(b.span.lo()),
- self.codemap.lookup_char_pos(b.span.hi())
+ self.source_map.lookup_char_pos(b.span.lo()),
+ self.source_map.lookup_char_pos(b.span.hi())
);
// Check if this block has braces.
// Note that this only gets called for function definitions. Required methods
// on traits do not get handled here.
- // FIXME(topecongiro) Format async fn (#2812).
fn visit_fn(
&mut self,
fk: visit::FnKind,
}
pub fn from_context(ctx: &'a RewriteContext) -> FmtVisitor<'a> {
- FmtVisitor::from_codemap(
+ FmtVisitor::from_source_map(
ctx.parse_session,
ctx.config,
ctx.snippet_provider,
)
}
- pub(crate) fn from_codemap(
+ pub(crate) fn from_source_map(
parse_session: &'a ParseSess,
config: &'a Config,
snippet_provider: &'a SnippetProvider,
) -> FmtVisitor<'a> {
FmtVisitor {
parse_session,
- codemap: parse_session.codemap(),
+ source_map: parse_session.source_map(),
buffer: String::with_capacity(snippet_provider.big_snippet.len() * 2),
last_pos: BytePos(0),
block_indent: Indent::empty(),
pub fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -> bool {
for attr in attrs {
if attr.name() == DEPR_SKIP_ANNOTATION {
- let file_name = self.codemap.span_to_filename(attr.span).into();
+ let file_name = self.source_map.span_to_filename(attr.span).into();
self.report.append(
file_name,
vec![FormattingError::from_span(
- &attr.span,
- &self.codemap,
+ attr.span,
+ &self.source_map,
ErrorKind::DeprecatedAttr,
)],
);
if attr.path.segments.len() == 1
|| attr.path.segments[1].ident.to_string() != "skip"
{
- let file_name = self.codemap.span_to_filename(attr.span).into();
+ let file_name = self.source_map.span_to_filename(attr.span).into();
self.report.append(
file_name,
vec![FormattingError::from_span(
- &attr.span,
- &self.codemap,
+ attr.span,
+ &self.source_map,
ErrorKind::BadAttr,
)],
);
}
}
- pub fn format_separate_mod(&mut self, m: &ast::Mod, filemap: &codemap::FileMap) {
+ pub fn format_separate_mod(&mut self, m: &ast::Mod, source_file: &source_map::SourceFile) {
self.block_indent = Indent::empty();
self.walk_mod_items(m);
- self.format_missing_with_indent(filemap.end_pos);
+ self.format_missing_with_indent(source_file.end_pos);
}
pub fn skip_empty_lines(&mut self, end_pos: BytePos) {
pub fn get_context(&self) -> RewriteContext {
RewriteContext {
parse_session: self.parse_session,
- codemap: self.codemap,
+ source_map: self.source_map,
config: self.config,
inside_macro: RefCell::new(false),
use_block: RefCell::new(false),