Merge pull request #2950 from CAD97/master

Rename CodeMap/FileMap to SourceMap/SourceFile
This commit is contained in:
Nick Cameron 2018-08-24 11:17:15 +12:00 committed by GitHub
commit f009252a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 210 additions and 204 deletions

70
Cargo.lock generated
View File

@ -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"

View File

@ -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]

View File

@ -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] {

View File

@ -65,7 +65,6 @@
//! .qux
//! ```
use codemap::SpanUtils;
use comment::rewrite_comment;
use config::IndentStyle;
use expr::rewrite_call;
@ -73,6 +72,7 @@ use lists::{extract_post_comment, extract_pre_comment, get_comment_end};
use macros::convert_try_mac;
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use utils::{
first_line_width, last_line_extendable, last_line_width, mk_sp, trimmed_last_line_width,
wrap_str,
@ -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<String> {

View File

@ -9,16 +9,16 @@
// except according to those terms.
use config::lists::*;
use syntax::codemap::Span;
use syntax::parse::classify;
use syntax::source_map::Span;
use syntax::{ast, ptr};
use codemap::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};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use utils::{last_line_width, left_most_sub_expr, stmt_expr};
// This module is pretty messy because of the rules around closures and blocks:
@ -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)
}

View File

@ -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,
)],
);

View File

@ -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<FileMap>,
pub file: Rc<SourceFile>,
pub lo: usize,
pub hi: usize,
}
@ -35,11 +35,11 @@ pub enum FileName {
Stdin,
}
impl From<codemap::FileName> for FileName {
fn from(name: codemap::FileName) -> FileName {
impl From<source_map::FileName> 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!(),
}
}

View File

@ -12,13 +12,12 @@ use std::borrow::Cow;
use std::cmp::min;
use config::lists::*;
use syntax::codemap::{BytePos, CodeMap, Span};
use syntax::parse::token::DelimToken;
use syntax::source_map::{BytePos, SourceMap, Span};
use syntax::{ast, ptr};
use chains::rewrite_chain;
use closures;
use codemap::{LineRangeUtils, SpanUtils};
use comment::{
combine_strs_with_missing_comments, contains_comment, recover_comment_removed, rewrite_comment,
rewrite_missing_comment, CharClasses, FindUncommented,
@ -35,6 +34,7 @@ use pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
use patterns::{can_be_overflowed_pat, is_short_pattern, TuplePatField};
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use source_map::{LineRangeUtils, SpanUtils};
use spanned::Spanned;
use string::{rewrite_string, StringFormat};
use types::{can_be_overflowed_type, rewrite_path, PathContext};
@ -425,7 +425,9 @@ 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 +485,7 @@ fn rewrite_single_line_block(
label: Option<ast::Label>,
shape: Shape,
) -> Option<String> {
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 +771,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 +1115,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 +1127,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 +1140,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 +1152,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())
}

View File

@ -7,19 +7,19 @@ use std::rc::Rc;
use std::time::{Duration, Instant};
use syntax::ast;
use syntax::codemap::{CodeMap, FilePathMapping, Span};
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
use syntax::errors::Handler;
use syntax::parse::{self, ParseSess};
use syntax::source_map::{FilePathMapping, SourceMap, Span};
use comment::{CharClasses, FullCodeCharKind};
use config::{Config, FileName, Verbosity};
use issues::BadIssueSeeker;
use visitor::{FmtVisitor, SnippetProvider};
use {filemap, modules, ErrorKind, FormatReport, Input, Session};
use {modules, source_file, ErrorKind, FormatReport, Input, Session};
// A map of the files of a crate, with their new content
pub(crate) type FileMap = Vec<FileRecord>;
pub(crate) type SourceFile = Vec<FileRecord>;
pub(crate) type FileRecord = (FileName, String);
impl<'b, T: Write + 'b> Session<'b, T> {
@ -70,19 +70,19 @@ fn format_project<T: FormatHandler>(
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,17 @@ 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 +591,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 +625,18 @@ fn parse_crate(
Err(ErrorKind::ParseError)
}
fn silent_emitter(codemap: Rc<CodeMap>) -> Box<EmitterWriter> {
fn silent_emitter(source_map: Rc<SourceMap>) -> Box<EmitterWriter> {
Box::new(EmitterWriter::new(
Box::new(Vec::new()),
Some(codemap),
Some(source_map),
false,
false,
))
}
fn make_parse_sess(codemap: Rc<CodeMap>, config: &Config) -> ParseSess {
fn make_parse_sess(source_map: Rc<SourceMap>, 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 +645,10 @@ fn make_parse_sess(codemap: Rc<CodeMap>, 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<F>(is_stdin: bool, config: &Config, f: F)

View File

@ -12,14 +12,14 @@ 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 comment::combine_strs_with_missing_comments;
use config::IndentStyle;
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use spanned::Spanned;
use utils::{is_same_visibility, mk_sp, rewrite_ident};
use visitor::FmtVisitor;
@ -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.

View File

@ -16,11 +16,10 @@ 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 comment::{
combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented,
@ -35,14 +34,15 @@ use macros::{rewrite_macro, MacroPosition};
use overflow;
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use source_map::{LineRangeUtils, SpanUtils};
use spanned::Spanned;
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) {

View File

@ -49,7 +49,7 @@ use syntax::ast;
use comment::LineClasses;
use failure::Fail;
use formatting::{FileMap, FormatErrorMap, FormattingError, ReportedErrors};
use formatting::{FormatErrorMap, FormattingError, ReportedErrors, SourceFile};
use issues::Issue;
use shape::Indent;
@ -65,11 +65,9 @@ mod attr;
mod chains;
pub(crate) mod checkstyle;
mod closures;
pub(crate) mod codemap;
mod comment;
pub(crate) mod config;
mod expr;
pub(crate) mod filemap;
pub(crate) mod formatting;
mod imports;
mod issues;
@ -86,6 +84,8 @@ mod reorder;
mod rewrite;
pub(crate) mod rustfmt_diff;
mod shape;
pub(crate) mod source_file;
pub(crate) mod source_map;
mod spanned;
mod string;
#[cfg(test)]
@ -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(),
}
}

View File

@ -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};

View File

@ -22,17 +22,16 @@
use std::collections::HashMap;
use config::lists::*;
use syntax::codemap::{BytePos, Span};
use syntax::parse::new_parser_from_tts;
use syntax::parse::parser::Parser;
use syntax::parse::token::{BinOpToken, DelimToken, Token};
use syntax::print::pprust;
use syntax::source_map::{BytePos, Span};
use syntax::symbol;
use syntax::tokenstream::{Cursor, ThinTokenStream, TokenStream, TokenTree};
use syntax::ThinVec;
use syntax::{ast, ptr};
use codemap::SpanUtils;
use comment::{
contains_comment, remove_trailing_white_spaces, CharClasses, FindUncommented, FullCodeCharKind,
LineClasses,
@ -42,6 +41,7 @@ use lists::{itemize_list, write_list, ListFormatting};
use overflow;
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use source_map::SpanUtils;
use spanned::Spanned;
use utils::{format_visibility, mk_sp, rewrite_ident, wrap_str};

View File

@ -13,10 +13,9 @@
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 comment::{combine_strs_with_missing_comments, rewrite_comment};
use config::{Config, ControlBraceStyle, IndentStyle};
use expr::{
@ -26,6 +25,7 @@ use expr::{
use lists::{itemize_list, write_list, ListFormatting};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use spanned::Spanned;
use utils::{
contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
@ -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)

View File

@ -10,12 +10,12 @@
use std::borrow::Cow;
use syntax::codemap::{BytePos, Pos, Span};
use syntax::source_map::{BytePos, Pos, Span};
use codemap::LineRangeUtils;
use comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
use config::{EmitMode, FileName};
use shape::{Indent, Shape};
use source_map::LineRangeUtils;
use utils::{count_newlines, last_line_width, mk_sp};
use visitor::FmtVisitor;
@ -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);

View File

@ -13,8 +13,8 @@ use std::io;
use std::path::{Path, PathBuf};
use syntax::ast;
use syntax::codemap;
use syntax::parse::{parser, DirectoryOwnership};
use syntax::source_map;
use syntax_pos::symbol::Symbol;
use config::FileName;
@ -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<BTreeMap<FileName, &'a ast::Mod>, 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,15 +59,15 @@ fn list_submodules<'a>(
module: &'a ast::Mod,
search_dir: &Path,
relative: Option<ast::Ident>,
codemap: &codemap::CodeMap,
source_map: &source_map::SourceMap,
result: &mut BTreeMap<FileName, &'a ast::Mod>,
) -> Result<(), io::Error> {
debug!("list_submodules: search_dir: {:?}", search_dir);
for item in &module.items {
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);
let is_internal = 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<ast::Ident>,
codemap: &codemap::CodeMap,
source_map: &source_map::SourceMap,
) -> Result<(PathBuf, Option<ast::Ident>), 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,

View File

@ -13,15 +13,15 @@
use config::lists::*;
use syntax::ast;
use syntax::codemap::Span;
use syntax::parse::token::DelimToken;
use syntax::source_map::Span;
use closures;
use codemap::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};
use shape::Shape;
use source_map::SpanUtils;
use spanned::Spanned;
use utils::{count_newlines, extra_offset, first_line_width, last_line_width, mk_sp};

View File

@ -10,10 +10,9 @@
use config::lists::*;
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
use syntax::codemap::{self, BytePos, Span};
use syntax::ptr;
use syntax::source_map::{self, BytePos, Span};
use codemap::SpanUtils;
use comment::FindUncommented;
use expr::{can_be_overflowed_expr, rewrite_unary_prefix, wrap_struct_field};
use lists::{
@ -25,6 +24,7 @@ use overflow;
use pairs::{rewrite_pair, PairParts};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use spanned::Spanned;
use types::{rewrite_path, PathContext};
use utils::{format_mutability, mk_sp, rewrite_ident};
@ -171,7 +171,7 @@ impl Rewrite for Pat {
fn rewrite_struct_pat(
path: &ast::Path,
fields: &[codemap::Spanned<ast::FieldPat>],
fields: &[source_map::Spanned<ast::FieldPat>],
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);
}

View File

@ -17,16 +17,16 @@
// 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 comment::combine_strs_with_missing_comments;
use imports::{merge_use_trees, UseTree};
use items::{is_mod_decl, rewrite_extern_crate, rewrite_mod};
use lists::{itemize_list, write_list, ListFormatting, ListItem};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::LineRangeUtils;
use spanned::Spanned;
use utils::mk_sp;
use visitor::FmtVisitor;
@ -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

View File

@ -10,8 +10,8 @@
// A generic trait to abstract the rewriting of an element (of the AST).
use syntax::codemap::{CodeMap, Span};
use syntax::parse::ParseSess;
use syntax::source_map::{SourceMap, Span};
use config::{Config, IndentStyle};
use shape::Shape;
@ -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<bool>,
// Force block indent style even if we are using visual indent style.

View File

@ -25,7 +25,7 @@ pub fn append_newline(s: &mut String) {
#[cfg(test)]
pub(crate) fn write_all_files<T>(
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 {

View File

@ -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();

View File

@ -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};

View File

@ -20,9 +20,9 @@ use std::path::{Path, PathBuf};
use std::str::Chars;
use config::{Color, Config, EmitMode, FileName, ReportTactic};
use filemap;
use formatting::{FileMap, ModifiedChunk};
use formatting::{ModifiedChunk, SourceFile};
use rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, OutputWriter};
use source_file;
use {FormatReport, Input, Session};
const DIFF_CONTEXT_SIZE: usize = 3;
@ -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<P: Into<PathBuf>>(filepath: P, config: Config) -> (bool, FileMap, FormatReport) {
fn format_file<P: Into<PathBuf>>(filepath: P, config: Config) -> (bool, SourceFile, FormatReport) {
let filepath = filepath.into();
let input = Input::File(filepath);
let mut session = Session::<io::Stdout>::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);
}

View File

@ -13,10 +13,9 @@ 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 config::{IndentStyle, TypeDensity};
use expr::{rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ToExpr};
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
@ -25,6 +24,7 @@ use overflow;
use pairs::{rewrite_pair, PairParts};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use spanned::Spanned;
use utils::{
colon_spaces, extra_offset, first_line_width, format_abi, format_mutability,
@ -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),

View File

@ -15,8 +15,8 @@ use syntax::ast::{
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind, Path,
Visibility, VisibilityKind,
};
use syntax::codemap::{BytePos, Span, NO_EXPANSION};
use syntax::ptr;
use syntax::source_map::{BytePos, Span, NO_EXPANSION};
use comment::filter_normal_code;
use rewrite::RewriteContext;
@ -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))
};
}

View File

@ -14,15 +14,15 @@ use std::cmp;
use config::lists::*;
use syntax::ast;
use syntax::codemap::{BytePos, Span};
use syntax::source_map::{BytePos, Span};
use codemap::SpanUtils;
use comment::{combine_strs_with_missing_comments, contains_comment};
use expr::rewrite_field;
use items::{rewrite_struct_field, rewrite_struct_field_prefix};
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use source_map::SpanUtils;
use spanned::Spanned;
use utils::{contains_skip, is_attributes_extendable, mk_sp, rewrite_ident};

View File

@ -9,12 +9,11 @@
// 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::{
@ -26,6 +25,7 @@ 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,
@ -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),

View File

@ -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(),

View File

@ -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))

View File

@ -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(),

View File

@ -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))

View File

@ -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(),
);