diff --git a/Cargo.lock b/Cargo.lock index 1b699b8b2b0..ac3fd7ab242 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -401,15 +401,15 @@ dependencies = [ [[package]] name = "rustc-ap-arena" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rustc-ap-rustc_data_structures 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-rustc_cratesio_shim" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -418,7 +418,7 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_data_structures" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -426,8 +426,8 @@ dependencies = [ "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -436,57 +436,57 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_errors" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-rustc_target" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_cratesio_shim 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_cratesio_shim 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-serialize" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc-ap-syntax" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_errors 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_errors 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-ap-syntax_pos" -version = "230.0.0" +version = "235.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-arena 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_data_structures 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-serialize 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-arena 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_data_structures 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-serialize 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -541,9 +541,9 @@ dependencies = [ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-rustc_target 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-ap-syntax_pos 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-rustc_target 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-ap-syntax_pos 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", @@ -820,14 +820,14 @@ dependencies = [ "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5bbbea44c5490a1e84357ff28b7d518b4619a159fed5d25f6c1de2d19cc42814" "checksum regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "747ba3b235651f6e2f67dfa8bcdcd073ddb7c243cb21c442fc12395dfcac212d" -"checksum rustc-ap-arena 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0cfa6cc1afa6a0f100f07052ae80fadb2af6034bad7e1eedc8b9c399f8f47ff8" -"checksum rustc-ap-rustc_cratesio_shim 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e771302cd244d9579c7ba3344415e88c56ad21eddd79356825fe022d7b2d81ab" -"checksum rustc-ap-rustc_data_structures 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a17d0e44cd437b65748e525111f6b170f9af50a625b45b55b6ef78217d3209c0" -"checksum rustc-ap-rustc_errors 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1553077b149a2272978e94281a8f4a457fe00fc21bb45947c406f50edb8bea72" -"checksum rustc-ap-rustc_target 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "919bf28c3d2e2f695fa6a8c3779a41275d45e02bcfec6156813bcdcc686e5a04" -"checksum rustc-ap-serialize 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96e676167b9a4b49e33ca92a5747205082e667d9064d8bb48447b75f8695e658" -"checksum rustc-ap-syntax 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ad8cf79b47d76743be20371ec61bee5a7c11ffbd0590939378afb9ab573501d" -"checksum rustc-ap-syntax_pos 230.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd44296b68ba3b690f276dba8b5b3fe52aad24b35faa6c993d3ee31dc6b53bb" +"checksum rustc-ap-arena 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f322d66bfa4314b6bbc6e7a0dbce4f33f7a5ed08c5a1bb0588fa8a0d904a99f" +"checksum rustc-ap-rustc_cratesio_shim 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "082c176b1346fd356c086ffb9695d188bb6a2cffc1db987e1604f36d495797d5" +"checksum rustc-ap-rustc_data_structures 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df2ce9493ece082cfb8301a718f2945646fc622386d4c68d8fe503b35f36194f" +"checksum rustc-ap-rustc_errors 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a43a08156fd6b8df7d7e4bae3edd0dc4c67b842518acbfc516cde2ce0638cd82" +"checksum rustc-ap-rustc_target 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36f7dc5977708040caf9a87f3ad877159c2573a75245280239083315f2f958a7" +"checksum rustc-ap-serialize 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca9beb1012c0120f95767975bc41f4b599c105da8d7561185ed22dfe2bc52cd6" +"checksum rustc-ap-syntax 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32fee8563391d36dcef52b180540cf72543a0a4505ee361ac30ed48ce9884a1b" +"checksum rustc-ap-syntax_pos 235.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "35b71f85a97f5c3ed6df05040f0e29227f9c302da4325c27c33a1701ecf9d6a0" "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c6d5a683c6ba4ed37959097e88d71c9e8e26659a3cb5be8b389078e7ad45306" diff --git a/Cargo.toml b/Cargo.toml index b3a341992ef..5583b056085 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,9 +47,9 @@ env_logger = "0.5" getopts = "0.2" derive-new = "0.5" cargo_metadata = "0.6" -rustc-ap-rustc_target = "230.0.0" -rustc-ap-syntax = "230.0.0" -rustc-ap-syntax_pos = "230.0.0" +rustc-ap-rustc_target = "235.0.0" +rustc-ap-syntax = "235.0.0" +rustc-ap-syntax_pos = "235.0.0" failure = "0.1.1" [dev-dependencies] diff --git a/src/attr.rs b/src/attr.rs index b13c873a598..deaf2be46b8 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -22,7 +22,7 @@ use utils::{count_newlines, mk_sp}; use std::borrow::Cow; use syntax::ast; -use syntax::codemap::{BytePos, Span, DUMMY_SP}; +use syntax::source_map::{BytePos, Span, DUMMY_SP}; /// Returns attributes on the given statement. pub fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] { diff --git a/src/chains.rs b/src/chains.rs index 429b9ceb961..8686d2c66b9 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -65,7 +65,7 @@ //! .qux //! ``` -use codemap::SpanUtils; +use source_map::SpanUtils; use comment::rewrite_comment; use config::IndentStyle; use expr::rewrite_call; @@ -82,7 +82,7 @@ use std::borrow::Cow; use std::cmp::min; use std::iter; -use syntax::codemap::{BytePos, Span}; +use syntax::source_map::{BytePos, Span}; use syntax::{ast, ptr}; pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option { diff --git a/src/closures.rs b/src/closures.rs index 1a4a6e44fdf..e786339ed7c 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -9,11 +9,11 @@ // except according to those terms. use config::lists::*; -use syntax::codemap::Span; +use syntax::source_map::Span; use syntax::parse::classify; use syntax::{ast, ptr}; -use codemap::SpanUtils; +use source_map::SpanUtils; use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond, ToExpr}; use items::{span_hi_for_arg, span_lo_for_arg}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; @@ -51,7 +51,7 @@ pub fn rewrite_closure( if let ast::ExprKind::Block(ref block, _) = body.node { // The body of the closure is an empty block. - if block.stmts.is_empty() && !block_contains_comment(block, context.codemap) { + if block.stmts.is_empty() && !block_contains_comment(block, context.source_map) { return body .rewrite(context, shape) .map(|s| format!("{} {}", prefix, s)); @@ -114,7 +114,7 @@ fn get_inner_expr<'a>( fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext) -> bool { is_unsafe_block(block) || block.stmts.len() > 1 - || block_contains_comment(block, context.codemap) + || block_contains_comment(block, context.source_map) || prefix.contains('\n') } @@ -304,7 +304,7 @@ pub fn rewrite_last_closure( let body = match body.node { ast::ExprKind::Block(ref block, _) if !is_unsafe_block(block) - && is_simple_block(block, Some(&body.attrs), context.codemap) => + && is_simple_block(block, Some(&body.attrs), context.source_map) => { stmt_expr(&block.stmts[0]).unwrap_or(body) } diff --git a/src/comment.rs b/src/comment.rs index 4f2f813166b..78d087ce7a4 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -13,7 +13,7 @@ use std::{self, borrow::Cow, iter}; use itertools::{multipeek, MultiPeek}; -use syntax::codemap::Span; +use syntax::source_map::Span; use config::Config; use rewrite::RewriteContext; @@ -1151,10 +1151,10 @@ pub fn recover_comment_removed( // We missed some comments. Warn and keep the original text. if context.config.error_on_unformatted() { context.report.append( - context.codemap.span_to_filename(span).into(), + context.source_map.span_to_filename(span).into(), vec![FormattingError::from_span( &span, - &context.codemap, + &context.source_map, ErrorKind::LostComment, )], ); diff --git a/src/config/file_lines.rs b/src/config/file_lines.rs index 58f65b3c1b6..ba317af8360 100644 --- a/src/config/file_lines.rs +++ b/src/config/file_lines.rs @@ -19,11 +19,11 @@ use serde::de::{Deserialize, Deserializer}; use serde::ser::{self, Serialize, Serializer}; use serde_json as json; -use syntax::codemap::{self, FileMap}; +use syntax::source_map::{self, SourceFile}; /// A range of lines in a file, inclusive of both ends. pub struct LineRange { - pub file: Rc, + pub file: Rc, pub lo: usize, pub hi: usize, } @@ -35,11 +35,11 @@ pub enum FileName { Stdin, } -impl From for FileName { - fn from(name: codemap::FileName) -> FileName { +impl From for FileName { + fn from(name: source_map::FileName) -> FileName { match name { - codemap::FileName::Real(p) => FileName::Real(p), - codemap::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin, + source_map::FileName::Real(p) => FileName::Real(p), + source_map::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin, _ => unreachable!(), } } diff --git a/src/expr.rs b/src/expr.rs index 0f4474d7c0f..909ea46f75d 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -12,13 +12,13 @@ use std::borrow::Cow; use std::cmp::min; use config::lists::*; -use syntax::codemap::{BytePos, CodeMap, Span}; +use syntax::source_map::{BytePos, SourceMap, Span}; use syntax::parse::token::DelimToken; use syntax::{ast, ptr}; use chains::rewrite_chain; use closures; -use codemap::{LineRangeUtils, SpanUtils}; +use source_map::{LineRangeUtils, SpanUtils}; use comment::{ combine_strs_with_missing_comments, contains_comment, recover_comment_removed, rewrite_comment, rewrite_missing_comment, CharClasses, FindUncommented, @@ -425,7 +425,7 @@ fn rewrite_empty_block( return None; } - if block.stmts.is_empty() && !block_contains_comment(block, context.codemap) && shape.width >= 2 + if block.stmts.is_empty() && !block_contains_comment(block, context.source_map) && shape.width >= 2 { return Some(format!("{}{}{{}}", prefix, label_str)); } @@ -483,7 +483,7 @@ fn rewrite_single_line_block( label: Option, shape: Shape, ) -> Option { - if is_simple_block(block, attrs, context.codemap) { + if is_simple_block(block, attrs, context.source_map) { let expr_shape = shape.offset_left(last_line_width(prefix))?; let expr_str = block.stmts[0].rewrite(context, expr_shape)?; let label_str = rewrite_label(label); @@ -769,8 +769,8 @@ impl<'a> ControlFlow<'a> { let fixed_cost = self.keyword.len() + " { } else { }".len(); if let ast::ExprKind::Block(ref else_node, _) = else_block.node { - if !is_simple_block(self.block, None, context.codemap) - || !is_simple_block(else_node, None, context.codemap) + if !is_simple_block(self.block, None, context.source_map) + || !is_simple_block(else_node, None, context.source_map) || pat_expr_str.contains('\n') { return None; @@ -1113,8 +1113,8 @@ fn extract_comment(span: Span, context: &RewriteContext, shape: Shape) -> Option } } -pub fn block_contains_comment(block: &ast::Block, codemap: &CodeMap) -> bool { - let snippet = codemap.span_to_snippet(block.span).unwrap(); +pub fn block_contains_comment(block: &ast::Block, source_map: &SourceMap) -> bool { + let snippet = source_map.span_to_snippet(block.span).unwrap(); contains_comment(&snippet) } @@ -1125,11 +1125,11 @@ pub fn block_contains_comment(block: &ast::Block, codemap: &CodeMap) -> bool { pub fn is_simple_block( block: &ast::Block, attrs: Option<&[ast::Attribute]>, - codemap: &CodeMap, + source_map: &SourceMap, ) -> bool { (block.stmts.len() == 1 && stmt_is_expr(&block.stmts[0]) - && !block_contains_comment(block, codemap) + && !block_contains_comment(block, source_map) && attrs.map_or(true, |a| a.is_empty())) } @@ -1138,10 +1138,10 @@ pub fn is_simple_block( pub fn is_simple_block_stmt( block: &ast::Block, attrs: Option<&[ast::Attribute]>, - codemap: &CodeMap, + source_map: &SourceMap, ) -> bool { block.stmts.len() <= 1 - && !block_contains_comment(block, codemap) + && !block_contains_comment(block, source_map) && attrs.map_or(true, |a| a.is_empty()) } @@ -1150,10 +1150,10 @@ pub fn is_simple_block_stmt( pub fn is_empty_block( block: &ast::Block, attrs: Option<&[ast::Attribute]>, - codemap: &CodeMap, + source_map: &SourceMap, ) -> bool { block.stmts.is_empty() - && !block_contains_comment(block, codemap) + && !block_contains_comment(block, source_map) && attrs.map_or(true, |a| inner_attributes(a).is_empty()) } diff --git a/src/formatting.rs b/src/formatting.rs index a695d3363a6..2c44f21417d 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use std::time::{Duration, Instant}; use syntax::ast; -use syntax::codemap::{CodeMap, FilePathMapping, Span}; +use syntax::source_map::{SourceMap, FilePathMapping, Span}; use syntax::errors::emitter::{ColorConfig, EmitterWriter}; use syntax::errors::Handler; use syntax::parse::{self, ParseSess}; @@ -16,10 +16,10 @@ use comment::{CharClasses, FullCodeCharKind}; use config::{Config, FileName, Verbosity}; use issues::BadIssueSeeker; use visitor::{FmtVisitor, SnippetProvider}; -use {filemap, modules, ErrorKind, FormatReport, Input, Session}; +use {source_file, modules, ErrorKind, FormatReport, Input, Session}; // A map of the files of a crate, with their new content -pub(crate) type FileMap = Vec; +pub(crate) type SourceFile = Vec; pub(crate) type FileRecord = (FileName, String); impl<'b, T: Write + 'b> Session<'b, T> { @@ -70,19 +70,19 @@ fn format_project( let input_is_stdin = main_file == FileName::Stdin; // Parse the crate. - let codemap = Rc::new(CodeMap::new(FilePathMapping::empty())); - let mut parse_session = make_parse_sess(codemap.clone(), config); + let source_map = Rc::new(SourceMap::new(FilePathMapping::empty())); + let mut parse_session = make_parse_sess(source_map.clone(), config); let mut report = FormatReport::new(); let krate = parse_crate(input, &parse_session, config, &mut report)?; timer = timer.done_parsing(); // Suppress error output if we have to do any further parsing. - let silent_emitter = silent_emitter(codemap); + let silent_emitter = silent_emitter(source_map); parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter); let mut context = FormatContext::new(&krate, report, parse_session, config, handler); - let files = modules::list_files(&krate, context.parse_session.codemap())?; + let files = modules::list_files(&krate, context.parse_session.source_map())?; for (path, module) in files { if (config.skip_children() && path != main_file) || config.ignore().skip_file(&path) { continue; @@ -122,14 +122,14 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> { module: &ast::Mod, is_root: bool, ) -> Result<(), ErrorKind> { - let filemap = self + let source_file = self .parse_session - .codemap() + .source_map() .lookup_char_pos(module.inner.lo()) .file; - let big_snippet = filemap.src.as_ref().unwrap(); - let snippet_provider = SnippetProvider::new(filemap.start_pos, big_snippet); - let mut visitor = FmtVisitor::from_codemap( + let big_snippet = source_file.src.as_ref().unwrap(); + let snippet_provider = SnippetProvider::new(source_file.start_pos, big_snippet); + let mut visitor = FmtVisitor::from_source_map( &self.parse_session, &self.config, &snippet_provider, @@ -138,16 +138,16 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> { // Format inner attributes if available. if !self.krate.attrs.is_empty() && is_root { - visitor.skip_empty_lines(filemap.end_pos); + visitor.skip_empty_lines(source_file.end_pos); if visitor.visit_attrs(&self.krate.attrs, ast::AttrStyle::Inner) { visitor.push_rewrite(module.inner, None); } else { - visitor.format_separate_mod(module, &*filemap); + visitor.format_separate_mod(module, &*source_file); } } else { - visitor.last_pos = filemap.start_pos; - visitor.skip_empty_lines(filemap.end_pos); - visitor.format_separate_mod(module, &*filemap); + visitor.last_pos = source_file.start_pos; + visitor.skip_empty_lines(source_file.end_pos); + visitor.format_separate_mod(module, &*source_file); }; debug_assert_eq!( @@ -155,9 +155,9 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> { ::utils::count_newlines(&visitor.buffer) ); - // For some reason, the codemap does not include terminating + // For some reason, the source_map does not include terminating // newlines so we must add one on for each file. This is sad. - filemap::append_newline(&mut visitor.buffer); + source_file::append_newline(&mut visitor.buffer); format_lines( &mut visitor.buffer, @@ -198,7 +198,7 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> { report: &mut FormatReport, ) -> Result<(), ErrorKind> { if let Some(ref mut out) = self.out { - match filemap::write_file(&mut result, &path, out, &self.config) { + match source_file::write_file(&mut result, &path, out, &self.config) { Ok(b) if b => report.add_diff(), Err(e) => { // Create a new error with path_str to help users see which files failed @@ -209,7 +209,7 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> { } } - self.filemap.push((path, result)); + self.source_file.push((path, result)); Ok(()) } } @@ -223,13 +223,13 @@ pub(crate) struct FormattingError { } impl FormattingError { - pub(crate) fn from_span(span: &Span, codemap: &CodeMap, kind: ErrorKind) -> FormattingError { + pub(crate) fn from_span(span: &Span, source_map: &SourceMap, kind: ErrorKind) -> FormattingError { FormattingError { - line: codemap.lookup_char_pos(span.lo()).line, + line: source_map.lookup_char_pos(span.lo()).line, is_comment: kind.is_comment(), kind, is_string: false, - line_buffer: codemap + line_buffer: source_map .span_to_lines(*span) .ok() .and_then(|fl| { @@ -587,7 +587,7 @@ fn parse_crate( Input::File(file) => parse::new_parser_from_file(parse_session, &file), Input::Text(text) => parse::new_parser_from_source_str( parse_session, - syntax::codemap::FileName::Custom("stdin".to_owned()), + syntax::source_map::FileName::Custom("stdin".to_owned()), text, ), }; @@ -621,18 +621,18 @@ fn parse_crate( Err(ErrorKind::ParseError) } -fn silent_emitter(codemap: Rc) -> Box { +fn silent_emitter(source_map: Rc) -> Box { Box::new(EmitterWriter::new( Box::new(Vec::new()), - Some(codemap), + Some(source_map), false, false, )) } -fn make_parse_sess(codemap: Rc, config: &Config) -> ParseSess { +fn make_parse_sess(source_map: Rc, config: &Config) -> ParseSess { let tty_handler = if config.hide_parse_errors() { - let silent_emitter = silent_emitter(codemap.clone()); + let silent_emitter = silent_emitter(source_map.clone()); Handler::with_emitter(true, false, silent_emitter) } else { let supports_color = term::stderr().map_or(false, |term| term.supports_color()); @@ -641,10 +641,10 @@ fn make_parse_sess(codemap: Rc, config: &Config) -> ParseSess { } else { ColorConfig::Never }; - Handler::with_tty_emitter(color_cfg, true, false, Some(codemap.clone())) + Handler::with_tty_emitter(color_cfg, true, false, Some(source_map.clone())) }; - ParseSess::with_span_handler(tty_handler, codemap) + ParseSess::with_span_handler(tty_handler, source_map) } fn should_emit_verbose(is_stdin: bool, config: &Config, f: F) diff --git a/src/imports.rs b/src/imports.rs index 2007d05bc54..d964a21edc3 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -12,9 +12,9 @@ use std::cmp::Ordering; use config::lists::*; use syntax::ast::{self, UseTreeKind}; -use syntax::codemap::{self, BytePos, Span, DUMMY_SP}; +use syntax::source_map::{self, BytePos, Span, DUMMY_SP}; -use codemap::SpanUtils; +use source_map::SpanUtils; use comment::combine_strs_with_missing_comments; use config::IndentStyle; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator}; @@ -470,7 +470,7 @@ impl UseTree { fn same_visibility(&self, other: &UseTree) -> bool { match (&self.visibility, &other.visibility) { ( - Some(codemap::Spanned { + Some(source_map::Spanned { node: ast::VisibilityKind::Inherited, .. }), @@ -478,7 +478,7 @@ impl UseTree { ) | ( None, - Some(codemap::Spanned { + Some(source_map::Spanned { node: ast::VisibilityKind::Inherited, .. }), @@ -785,7 +785,7 @@ impl Rewrite for UseTree { #[cfg(test)] mod test { use super::*; - use syntax::codemap::DUMMY_SP; + use syntax::source_map::DUMMY_SP; // Parse the path part of an import. This parser is not robust and is only // suitable for use in a test harness. diff --git a/src/items.rs b/src/items.rs index 0152fb8794c..51f11d8f58a 100644 --- a/src/items.rs +++ b/src/items.rs @@ -16,11 +16,11 @@ use std::cmp::{min, Ordering}; use config::lists::*; use regex::Regex; use rustc_target::spec::abi; -use syntax::codemap::{self, BytePos, Span}; +use syntax::source_map::{self, BytePos, Span}; use syntax::visit; use syntax::{ast, ptr, symbol}; -use codemap::{LineRangeUtils, SpanUtils}; +use source_map::{LineRangeUtils, SpanUtils}; use comment::{ combine_strs_with_missing_comments, contains_comment, recover_comment_removed, recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented, @@ -40,9 +40,9 @@ use utils::*; use vertical::rewrite_with_alignment; use visitor::FmtVisitor; -const DEFAULT_VISIBILITY: ast::Visibility = codemap::Spanned { +const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned { node: ast::VisibilityKind::Inherited, - span: codemap::DUMMY_SP, + span: source_map::DUMMY_SP, }; fn type_annotation_separator(config: &Config) -> &str { @@ -380,16 +380,16 @@ impl<'a> FmtVisitor<'a> { return None; } - let codemap = self.get_context().codemap; + let source_map = self.get_context().source_map; if self.config.empty_item_single_line() - && is_empty_block(block, None, codemap) + && is_empty_block(block, None, source_map) && self.block_indent.width() + fn_str.len() + 2 <= self.config.max_width() { return Some(format!("{}{{}}", fn_str)); } - if self.config.fn_single_line() && is_simple_block_stmt(block, None, codemap) { + if self.config.fn_single_line() && is_simple_block_stmt(block, None, source_map) { let rewrite = { if let Some(stmt) = block.stmts.first() { match stmt_expr(stmt) { diff --git a/src/lib.rs b/src/lib.rs index 0ee913690b0..0131aa875d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ use syntax::ast; use comment::LineClasses; use failure::Fail; -use formatting::{FileMap, FormatErrorMap, FormattingError, ReportedErrors}; +use formatting::{SourceFile, FormatErrorMap, FormattingError, ReportedErrors}; use issues::Issue; use shape::Indent; @@ -65,11 +65,11 @@ mod attr; mod chains; pub(crate) mod checkstyle; mod closures; -pub(crate) mod codemap; +pub(crate) mod source_map; mod comment; pub(crate) mod config; mod expr; -pub(crate) mod filemap; +pub(crate) mod source_file; pub(crate) mod formatting; mod imports; mod issues; @@ -459,7 +459,7 @@ pub struct Session<'b, T: Write + 'b> { pub config: Config, pub out: Option<&'b mut T>, pub(crate) errors: ReportedErrors, - filemap: FileMap, + source_file: SourceFile, } impl<'b, T: Write + 'b> Session<'b, T> { @@ -472,7 +472,7 @@ impl<'b, T: Write + 'b> Session<'b, T> { config, out, errors: ReportedErrors::default(), - filemap: FileMap::new(), + source_file: SourceFile::new(), } } diff --git a/src/lists.rs b/src/lists.rs index 49548cc26a3..9b65fdbd1da 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -14,7 +14,7 @@ use std::cmp; use std::iter::Peekable; use config::lists::*; -use syntax::codemap::BytePos; +use syntax::source_map::BytePos; use comment::{find_comment_end, rewrite_comment, FindUncommented}; use config::{Config, IndentStyle}; diff --git a/src/macros.rs b/src/macros.rs index df7b3cdb918..9bbee1097e1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -22,7 +22,7 @@ use std::collections::HashMap; use config::lists::*; -use syntax::codemap::{BytePos, Span}; +use syntax::source_map::{BytePos, Span}; use syntax::parse::new_parser_from_tts; use syntax::parse::parser::Parser; use syntax::parse::token::{BinOpToken, DelimToken, Token}; @@ -32,7 +32,7 @@ use syntax::tokenstream::{Cursor, ThinTokenStream, TokenStream, TokenTree}; use syntax::ThinVec; use syntax::{ast, ptr}; -use codemap::SpanUtils; +use source_map::SpanUtils; use comment::{ contains_comment, remove_trailing_white_spaces, CharClasses, FindUncommented, FullCodeCharKind, LineClasses, diff --git a/src/matches.rs b/src/matches.rs index 29e9f19ad7d..0ee63fb0c5a 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -13,10 +13,10 @@ use std::iter::repeat; use config::lists::*; -use syntax::codemap::{BytePos, Span}; +use syntax::source_map::{BytePos, Span}; use syntax::{ast, ptr}; -use codemap::SpanUtils; +use source_map::SpanUtils; use comment::{combine_strs_with_missing_comments, rewrite_comment}; use config::{Config, ControlBraceStyle, IndentStyle}; use expr::{ @@ -302,7 +302,7 @@ fn block_can_be_flattened<'a>( match expr.node { ast::ExprKind::Block(ref block, _) if !is_unsafe_block(block) - && is_simple_block(block, Some(&expr.attrs), context.codemap) => + && is_simple_block(block, Some(&expr.attrs), context.source_map) => { Some(&*block) } @@ -347,7 +347,7 @@ fn rewrite_match_body( let (is_block, is_empty_block) = if let ast::ExprKind::Block(ref block, _) = body.node { ( true, - is_empty_block(block, Some(&body.attrs), context.codemap), + is_empty_block(block, Some(&body.attrs), context.source_map), ) } else { (false, false) diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 70d4c66d7fb..f61098ed879 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -10,9 +10,9 @@ use std::borrow::Cow; -use syntax::codemap::{BytePos, Pos, Span}; +use syntax::source_map::{BytePos, Pos, Span}; -use codemap::LineRangeUtils; +use source_map::LineRangeUtils; use comment::{rewrite_comment, CodeCharKind, CommentCodeSlices}; use config::{EmitMode, FileName}; use shape::{Indent, Shape}; @@ -97,8 +97,8 @@ impl<'a> FmtVisitor<'a> { assert!( start < end, "Request to format inverted span: {:?} to {:?}", - self.codemap.lookup_char_pos(start), - self.codemap.lookup_char_pos(end) + self.source_map.lookup_char_pos(start), + self.source_map.lookup_char_pos(end) ); self.last_pos = end; @@ -159,9 +159,9 @@ impl<'a> FmtVisitor<'a> { // Get a snippet from the file start to the span's hi without allocating. // We need it to determine what precedes the current comment. If the comment // follows code on the same line, we won't touch it. - let big_span_lo = self.codemap.lookup_char_pos(span.lo()).file.start_pos; - let local_begin = self.codemap.lookup_byte_offset(big_span_lo); - let local_end = self.codemap.lookup_byte_offset(span.hi()); + let big_span_lo = self.source_map.lookup_char_pos(span.lo()).file.start_pos; + let local_begin = self.source_map.lookup_byte_offset(big_span_lo); + let local_end = self.source_map.lookup_byte_offset(span.hi()); let start_index = local_begin.pos.to_usize(); let end_index = local_end.pos.to_usize(); let big_snippet = &local_begin.fm.src.as_ref().unwrap()[start_index..end_index]; @@ -187,7 +187,7 @@ impl<'a> FmtVisitor<'a> { // Trim whitespace from the right hand side of each line. // Annoyingly, the library functions for splitting by lines etc. are not // quite right, so we must do it ourselves. - let char_pos = self.codemap.lookup_char_pos(span.lo()); + let char_pos = self.source_map.lookup_char_pos(span.lo()); let file_name = &char_pos.file.name.clone().into(); let mut status = SnippetStatus::new(char_pos.line); diff --git a/src/modules.rs b/src/modules.rs index 7619c0afa57..2f5743fbedf 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -13,7 +13,7 @@ use std::io; use std::path::{Path, PathBuf}; use syntax::ast; -use syntax::codemap; +use syntax::source_map; use syntax::parse::{parser, DirectoryOwnership}; use syntax_pos::symbol::Symbol; @@ -24,16 +24,16 @@ use utils::contains_skip; /// If a file is used twice in a crate, it appears only once. pub fn list_files<'a>( krate: &'a ast::Crate, - codemap: &codemap::CodeMap, + source_map: &source_map::SourceMap, ) -> Result, io::Error> { let mut result = BTreeMap::new(); // Enforce file order determinism - let root_filename = codemap.span_to_filename(krate.span); + let root_filename = source_map.span_to_filename(krate.span); { let parent = match root_filename { - codemap::FileName::Real(ref path) => path.parent().unwrap(), + source_map::FileName::Real(ref path) => path.parent().unwrap(), _ => Path::new(""), }; - list_submodules(&krate.module, parent, None, codemap, &mut result)?; + list_submodules(&krate.module, parent, None, source_map, &mut result)?; } result.insert(root_filename.into(), &krate.module); Ok(result) @@ -59,7 +59,7 @@ fn list_submodules<'a>( module: &'a ast::Mod, search_dir: &Path, relative: Option, - codemap: &codemap::CodeMap, + source_map: &source_map::SourceMap, result: &mut BTreeMap, ) -> Result<(), io::Error> { debug!("list_submodules: search_dir: {:?}", search_dir); @@ -67,7 +67,7 @@ fn list_submodules<'a>( if let ast::ItemKind::Mod(ref sub_mod) = item.node { if !contains_skip(&item.attrs) { let is_internal = - codemap.span_to_filename(item.span) == codemap.span_to_filename(sub_mod.inner); + source_map.span_to_filename(item.span) == source_map.span_to_filename(sub_mod.inner); let (dir_path, relative) = if is_internal { if let Some(path) = find_path_value(&item.attrs) { (search_dir.join(&path.as_str()), None) @@ -76,12 +76,12 @@ fn list_submodules<'a>( } } else { let (mod_path, relative) = - module_file(item.ident, &item.attrs, search_dir, relative, codemap)?; + module_file(item.ident, &item.attrs, search_dir, relative, source_map)?; let dir_path = mod_path.parent().unwrap().to_owned(); result.insert(FileName::Real(mod_path), sub_mod); (dir_path, relative) }; - list_submodules(sub_mod, &dir_path, relative, codemap, result)?; + list_submodules(sub_mod, &dir_path, relative, source_map, result)?; } } } @@ -94,13 +94,13 @@ fn module_file( attrs: &[ast::Attribute], dir_path: &Path, relative: Option, - codemap: &codemap::CodeMap, + source_map: &source_map::SourceMap, ) -> Result<(PathBuf, Option), io::Error> { if let Some(path) = parser::Parser::submod_path_from_attr(attrs, dir_path) { return Ok((path, None)); } - match parser::Parser::default_submod_path(id, relative, dir_path, codemap).result { + match parser::Parser::default_submod_path(id, relative, dir_path, source_map).result { Ok(parser::ModulePathSuccess { path, directory_ownership, diff --git a/src/overflow.rs b/src/overflow.rs index e18fe140c8d..6e63649ca80 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -13,11 +13,11 @@ use config::lists::*; use syntax::ast; -use syntax::codemap::Span; +use syntax::source_map::Span; use syntax::parse::token::DelimToken; use closures; -use codemap::SpanUtils; +use source_map::SpanUtils; use expr::{is_every_expr_simple, is_method_call, is_nested_call, maybe_get_args_offset, ToExpr}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator}; use rewrite::{Rewrite, RewriteContext}; diff --git a/src/patterns.rs b/src/patterns.rs index 465d64627e8..b58431cbb65 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -10,10 +10,10 @@ use config::lists::*; use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax}; -use syntax::codemap::{self, BytePos, Span}; +use syntax::source_map::{self, BytePos, Span}; use syntax::ptr; -use codemap::SpanUtils; +use source_map::SpanUtils; use comment::FindUncommented; use expr::{can_be_overflowed_expr, rewrite_unary_prefix, wrap_struct_field}; use lists::{ @@ -171,7 +171,7 @@ impl Rewrite for Pat { fn rewrite_struct_pat( path: &ast::Path, - fields: &[codemap::Spanned], + fields: &[source_map::Spanned], ellipsis: bool, span: Span, context: &RewriteContext, @@ -332,7 +332,7 @@ fn rewrite_tuple_pat( lo, // 2 == "..".len() lo + BytePos(2), - codemap::NO_EXPANSION, + source_map::NO_EXPANSION, )); pat_vec.insert(pos, dotdot); } diff --git a/src/reorder.rs b/src/reorder.rs index bc429a10ab6..21a3797a6e4 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -17,10 +17,10 @@ // FIXME(#2455): Reorder trait items. use config::Config; -use syntax::{ast, attr, codemap::Span}; +use syntax::{ast, attr, source_map::Span}; use attr::filter_inline_attrs; -use codemap::LineRangeUtils; +use source_map::LineRangeUtils; use comment::combine_strs_with_missing_comments; use imports::{merge_use_trees, UseTree}; use items::{is_mod_decl, rewrite_extern_crate, rewrite_mod}; @@ -226,13 +226,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { item_kind: ReorderableItemKind, in_group: bool, ) -> usize { - let mut last = self.codemap.lookup_line_range(items[0].span()); + let mut last = self.source_map.lookup_line_range(items[0].span()); let item_length = items .iter() .take_while(|ppi| { item_kind.is_same_item_kind(&***ppi) && (!in_group || { - let current = self.codemap.lookup_line_range(ppi.span()); + let current = self.source_map.lookup_line_range(ppi.span()); let in_same_group = current.lo < last.hi + 2; last = current; in_same_group diff --git a/src/rewrite.rs b/src/rewrite.rs index 90b613df6c4..232f4311155 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -10,7 +10,7 @@ // A generic trait to abstract the rewriting of an element (of the AST). -use syntax::codemap::{CodeMap, Span}; +use syntax::source_map::{SourceMap, Span}; use syntax::parse::ParseSess; use config::{Config, IndentStyle}; @@ -28,7 +28,7 @@ pub trait Rewrite { #[derive(Clone)] pub struct RewriteContext<'a> { pub parse_session: &'a ParseSess, - pub codemap: &'a CodeMap, + pub source_map: &'a SourceMap, pub config: &'a Config, pub inside_macro: RefCell, // Force block indent style even if we are using visual indent style. diff --git a/src/filemap.rs b/src/source_file.rs similarity index 97% rename from src/filemap.rs rename to src/source_file.rs index 20140321032..306f2626639 100644 --- a/src/filemap.rs +++ b/src/source_file.rs @@ -25,7 +25,7 @@ pub fn append_newline(s: &mut String) { #[cfg(test)] pub(crate) fn write_all_files( - file_map: &[FileRecord], + source_file: &[FileRecord], out: &mut T, config: &Config, ) -> Result<(), io::Error> @@ -35,7 +35,7 @@ where if config.emit_mode() == EmitMode::Checkstyle { write!(out, "{}", ::checkstyle::header())?; } - for &(ref filename, ref text) in file_map { + for &(ref filename, ref text) in source_file { write_file(text, filename, out, config)?; } if config.emit_mode() == EmitMode::Checkstyle { diff --git a/src/codemap.rs b/src/source_map.rs similarity index 94% rename from src/codemap.rs rename to src/source_map.rs index 2e73fdcec13..678e4fe4cc6 100644 --- a/src/codemap.rs +++ b/src/source_map.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! This module contains utilities that work with the `CodeMap` from `libsyntax` / `syntex_syntax`. +//! This module contains utilities that work with the `SourceMap` from `libsyntax` / `syntex_syntax`. //! This includes extension traits and methods for looking up spans and line ranges for AST nodes. use config::file_lines::LineRange; -use syntax::codemap::{BytePos, CodeMap, Span}; +use syntax::source_map::{BytePos, SourceMap, Span}; use visitor::SnippetProvider; use comment::FindUncommented; @@ -71,7 +71,7 @@ impl<'a> SpanUtils for SnippetProvider<'a> { } } -impl LineRangeUtils for CodeMap { +impl LineRangeUtils for SourceMap { fn lookup_line_range(&self, span: Span) -> LineRange { let lo = self.lookup_line(span.lo()).unwrap(); let hi = self.lookup_line(span.hi()).unwrap(); diff --git a/src/spanned.rs b/src/spanned.rs index c2886fcdd8f..a7ba0f1a72d 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -9,7 +9,7 @@ // except according to those terms. use syntax::ast; -use syntax::codemap::Span; +use syntax::source_map::Span; use macros::MacroArg; use utils::{mk_sp, outer_attributes}; diff --git a/src/test/mod.rs b/src/test/mod.rs index beba2628112..35a720e4c56 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -20,8 +20,8 @@ use std::path::{Path, PathBuf}; use std::str::Chars; use config::{Color, Config, EmitMode, FileName, ReportTactic}; -use filemap; -use formatting::{FileMap, ModifiedChunk}; +use source_file; +use formatting::{SourceFile, ModifiedChunk}; use rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, OutputWriter}; use {FormatReport, Input, Session}; @@ -197,11 +197,11 @@ fn modified_test() { // to a known output file generated by one of the write modes. fn assert_output(source: &Path, expected_filename: &Path) { let config = read_config(source); - let (_, file_map, _) = format_file(source, config.clone()); + let (_, source_file, _) = format_file(source, config.clone()); // Populate output by writing to a vec. let mut out = vec![]; - let _ = filemap::write_all_files(&file_map, &mut out, &config); + let _ = source_file::write_all_files(&source_file, &mut out, &config); let output = String::from_utf8(out).unwrap(); let mut expected_file = fs::File::open(&expected_filename).expect("Couldn't open target"); @@ -414,15 +414,15 @@ fn read_config(filename: &Path) -> Config { config } -fn format_file>(filepath: P, config: Config) -> (bool, FileMap, FormatReport) { +fn format_file>(filepath: P, config: Config) -> (bool, SourceFile, FormatReport) { let filepath = filepath.into(); let input = Input::File(filepath); let mut session = Session::::new(config, None); let result = session.format(input).unwrap(); let parsing_errors = session.has_parsing_errors(); - let mut filemap = FileMap::new(); - mem::swap(&mut session.filemap, &mut filemap); - (parsing_errors, filemap, result) + let mut source_file = SourceFile::new(); + mem::swap(&mut session.source_file, &mut source_file); + (parsing_errors, source_file, result) } enum IdempotentCheckError { @@ -440,13 +440,13 @@ fn idempotent_check( } else { read_config(filename) }; - let (parsing_errors, file_map, format_report) = format_file(filename, config); + let (parsing_errors, source_file, format_report) = format_file(filename, config); if parsing_errors { return Err(IdempotentCheckError::Parse); } let mut write_result = HashMap::new(); - for (filename, text) in file_map { + for (filename, text) in source_file { if let FileName::Real(ref filename) = filename { write_result.insert(filename.to_owned(), text); } diff --git a/src/types.rs b/src/types.rs index 360c7304988..601868bf1f3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -13,10 +13,10 @@ use std::ops::Deref; use config::lists::*; use syntax::ast::{self, FunctionRetTy, Mutability}; -use syntax::codemap::{self, BytePos, Span}; +use syntax::source_map::{self, BytePos, Span}; use syntax::symbol::keywords; -use codemap::SpanUtils; +use source_map::SpanUtils; use config::{IndentStyle, TypeDensity}; use expr::{rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ToExpr}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; @@ -267,7 +267,7 @@ fn rewrite_segment( ast::GenericArgs::Parenthesized(ref data) => { let output = match data.output { Some(ref ty) => FunctionRetTy::Ty(ty.clone()), - None => FunctionRetTy::Default(codemap::DUMMY_SP), + None => FunctionRetTy::Default(source_map::DUMMY_SP), }; result.push_str(&format_function_type( data.inputs.iter().map(|x| &**x), diff --git a/src/utils.rs b/src/utils.rs index 9eac3fd4f0d..1bfccf237b4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -15,7 +15,7 @@ use syntax::ast::{ self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path, Visibility, VisibilityKind, }; -use syntax::codemap::{BytePos, Span, NO_EXPANSION}; +use syntax::source_map::{BytePos, Span, NO_EXPANSION}; use syntax::ptr; use comment::filter_normal_code; @@ -327,7 +327,7 @@ macro_rules! out_of_file_lines_range { !$self.config.file_lines().is_all() && !$self .config .file_lines() - .intersects(&$self.codemap.lookup_line_range($span)) + .intersects(&$self.source_map.lookup_line_range($span)) }; } diff --git a/src/vertical.rs b/src/vertical.rs index c6721bc5010..98f90530e8b 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -14,9 +14,9 @@ use std::cmp; use config::lists::*; use syntax::ast; -use syntax::codemap::{BytePos, Span}; +use syntax::source_map::{BytePos, Span}; -use codemap::SpanUtils; +use source_map::SpanUtils; use comment::{combine_strs_with_missing_comments, contains_comment}; use expr::rewrite_field; use items::{rewrite_struct_field, rewrite_struct_field_prefix}; diff --git a/src/visitor.rs b/src/visitor.rs index c80cd78a992..bc500281a88 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -9,12 +9,12 @@ // except according to those terms. use syntax::attr::HasAttrs; -use syntax::codemap::{self, BytePos, CodeMap, Pos, Span}; +use syntax::source_map::{self, BytePos, SourceMap, Pos, Span}; use syntax::parse::ParseSess; use syntax::{ast, visit}; use attr::*; -use codemap::{LineRangeUtils, SpanUtils}; +use source_map::{LineRangeUtils, SpanUtils}; use comment::{CodeCharKind, CommentCodeSlices, FindUncommented}; use config::{BraceStyle, Config}; use items::{ @@ -61,7 +61,7 @@ impl<'a> SnippetProvider<'a> { 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 @@ -83,8 +83,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { 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 { @@ -121,8 +121,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ) { 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. @@ -575,7 +575,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { } pub fn from_context(ctx: &'a RewriteContext) -> FmtVisitor<'a> { - FmtVisitor::from_codemap( + FmtVisitor::from_source_map( ctx.parse_session, ctx.config, ctx.snippet_provider, @@ -583,7 +583,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ) } - pub(crate) fn from_codemap( + pub(crate) fn from_source_map( parse_session: &'a ParseSess, config: &'a Config, snippet_provider: &'a SnippetProvider, @@ -591,7 +591,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ) -> 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(), @@ -617,12 +617,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { 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, + &self.source_map, ErrorKind::DeprecatedAttr, )], ); @@ -630,12 +630,12 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { 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, + &self.source_map, ErrorKind::BadAttr, )], ); @@ -741,10 +741,10 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { } } - 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) { @@ -779,7 +779,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { 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), diff --git a/tests/source/expr-block.rs b/tests/source/expr-block.rs index f08fd317a51..48cc1fd72ae 100644 --- a/tests/source/expr-block.rs +++ b/tests/source/expr-block.rs @@ -77,7 +77,7 @@ fn arrays() { } fn function_calls() { - let items = itemize_list(context.codemap, + let items = itemize_list(context.source_map, args.iter(), ")", |item| item.span.lo(), @@ -92,7 +92,7 @@ fn function_calls() { span.lo(), span.hi()); - itemize_list(context.codemap, + itemize_list(context.source_map, args.iter(), ")", |item| item.span.lo(), diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 56f90808ab7..7098d65f100 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -9,7 +9,7 @@ fn foo() -> bool { let very_long_variable_name = ( a + first + simple + test ); let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c); - let is_internalxxxx = self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner); + let is_internalxxxx = self.source_map.span_to_filename(s) == self.source_map.span_to_filename(m.inner); let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb / (bbbbbb - function_call(x, *very_long_pointer, y)) diff --git a/tests/target/expr-block.rs b/tests/target/expr-block.rs index 501ee3eaea0..d3a45566efa 100644 --- a/tests/target/expr-block.rs +++ b/tests/target/expr-block.rs @@ -73,7 +73,7 @@ fn arrays() { fn function_calls() { let items = itemize_list( - context.codemap, + context.source_map, args.iter(), ")", |item| item.span.lo(), @@ -92,7 +92,7 @@ fn function_calls() { ); itemize_list( - context.codemap, + context.source_map, args.iter(), ")", |item| item.span.lo(), diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 370e31bdabe..2e2312a11d5 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -11,7 +11,7 @@ fn foo() -> bool { (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c); let is_internalxxxx = - self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner); + self.source_map.span_to_filename(s) == self.source_map.span_to_filename(m.inner); let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb / (bbbbbb - function_call(x, *very_long_pointer, y)) diff --git a/tests/target/nested-visual-block.rs b/tests/target/nested-visual-block.rs index 95b9bc2dea2..ed6c181fc7b 100644 --- a/tests/target/nested-visual-block.rs +++ b/tests/target/nested-visual-block.rs @@ -1,7 +1,7 @@ fn main() { // #1078 let items = itemize_list( - context.codemap, + context.source_map, field_iter, "}", |item| match *item { @@ -33,7 +33,7 @@ fn main() { } } }, - context.codemap.span_after(span, "{"), + context.source_map.span_after(span, "{"), span.hi(), );