Skip to content

Commit

Permalink
refactor: symb/source_map/syntax_pos to rustc_span
Browse files Browse the repository at this point in the history
syntax_pos was renamed to rustc_span
rust-lang/rust#67707

and modules like `symbol` and `source_map` are no longer re-exported in
libsyanx so we also need to consume them directly from the rustc_span
crate
rust-lang/rust#67786
  • Loading branch information
calebcartwright committed Jan 14, 2020
1 parent 900c527 commit dc44c57
Show file tree
Hide file tree
Showing 30 changed files with 49 additions and 61 deletions.
18 changes: 9 additions & 9 deletions rustfmt-core/rustfmt-config/src/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
use serde_json as json;
use thiserror::Error;

use syntax_pos::{self, SourceFile};
use rustc_span::{self, SourceFile};

/// A range of lines in a file, inclusive of both ends.
pub struct LineRange {
Expand All @@ -26,21 +26,21 @@ pub enum FileName {
Stdin,
}

impl From<syntax_pos::FileName> for FileName {
fn from(name: syntax_pos::FileName) -> FileName {
impl From<rustc_span::FileName> for FileName {
fn from(name: rustc_span::FileName) -> FileName {
match name {
syntax_pos::FileName::Real(p) => FileName::Real(p),
syntax_pos::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin,
rustc_span::FileName::Real(p) => FileName::Real(p),
rustc_span::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin,
_ => unreachable!(),
}
}
}

impl From<&FileName> for syntax_pos::FileName {
fn from(filename: &FileName) -> syntax_pos::FileName {
impl From<&FileName> for rustc_span::FileName {
fn from(filename: &FileName) -> rustc_span::FileName {
match filename {
FileName::Real(path) => syntax_pos::FileName::Real(path.to_owned()),
FileName::Stdin => syntax_pos::FileName::Custom("stdin".to_owned()),
FileName::Real(path) => rustc_span::FileName::Real(path.to_owned()),
FileName::Stdin => rustc_span::FileName::Custom("stdin".to_owned()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-config/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Default for Edition {
}
}

impl From<Edition> for syntax_pos::edition::Edition {
impl From<Edition> for rustc_span::edition::Edition {
fn from(edition: Edition) -> Self {
match edition {
Edition::Edition2015 => Self::Edition2015,
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/rustfmt-lib/src/attr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Format attributes and meta items.

use rustc_span::{BytePos, DUMMY_SP, Span, symbol::sym};
use syntax::ast;
use syntax::source_map::{BytePos, Span, DUMMY_SP};
use syntax::symbol::sym;

use self::doc_comment::DocCommentFormatter;
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
use std::borrow::Cow;
use std::cmp::min;

use syntax::source_map::{BytePos, Span};
use rustc_span::{BytePos, Span};
use syntax::{ast, ptr};

use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/closures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use syntax::source_map::Span;
use rustc_span::Span;
use syntax::{ast, ptr};

use crate::attr::get_attrs_from_stmt;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{self, borrow::Cow, iter};

use itertools::{multipeek, MultiPeek};
use syntax::source_map::Span;
use rustc_span::Span;

use crate::config::Config;
use crate::rewrite::RewriteContext;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::borrow::Cow;
use std::cmp::min;

use itertools::Itertools;
use rustc_span::{BytePos, Span};
use syntax::parse::token::{DelimToken, LitKind};
use syntax::source_map::{BytePos, Span};
use syntax::{ast, ptr};

use crate::chains::rewrite_chain;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::collections::HashMap;
use std::io::{self, Write};
use std::time::{Duration, Instant};

use rustc_span::Span;
use syntax::ast;
use syntax::source_map::Span;

use self::newline_style::apply_newline_style;
use crate::comment::{CharClasses, FullCodeCharKind};
Expand Down
5 changes: 2 additions & 3 deletions rustfmt-core/rustfmt-lib/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::borrow::Cow;
use std::cmp::Ordering;
use std::fmt;

use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol::sym};
use syntax::ast::{self, UseTreeKind};
use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
use syntax::symbol::sym;

use crate::comment::combine_strs_with_missing_comments;
use crate::config::lists::*;
Expand Down Expand Up @@ -854,7 +853,7 @@ impl Rewrite for UseTree {
#[cfg(test)]
mod test {
use super::*;
use syntax::source_map::DUMMY_SP;
use rustc_span::DUMMY_SP;

// Parse the path part of an import. This parser is not robust and is only
// suitable for use in a test harness.
Expand Down
6 changes: 3 additions & 3 deletions rustfmt-core/rustfmt-lib/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::borrow::Cow;
use std::cmp::{max, min, Ordering};

use regex::Regex;
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol};
use rustc_target::spec::abi;
use syntax::source_map::{self, BytePos, Span};
use syntax::visit;
use syntax::{ast, ptr, symbol};
use syntax::{ast, ptr};

use crate::attr::filter_inline_attrs;
use crate::comment::{
Expand Down Expand Up @@ -35,7 +35,7 @@ use crate::visitor::FmtVisitor;

const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned {
node: ast::VisibilityKind::Inherited,
span: source_map::DUMMY_SP,
span: DUMMY_SP,
};

fn type_annotation_separator(config: &Config) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::cmp;
use std::iter::Peekable;

use syntax::source_map::BytePos;
use rustc_span::BytePos;

use crate::comment::{find_comment_end, rewrite_comment, FindUncommented};
use crate::config::lists::*;
Expand Down
4 changes: 1 addition & 3 deletions rustfmt-core/rustfmt-lib/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
use std::collections::HashMap;
use std::panic::{catch_unwind, AssertUnwindSafe};

use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, symbol::kw};
use syntax::parse::new_parser_from_tts;
use syntax::parse::parser::Parser;
use syntax::parse::token::{BinOpToken, DelimToken, Token, TokenKind};
use syntax::print::pprust;
use syntax::source_map::{BytePos, Span};
use syntax::symbol::kw;
use syntax::tokenstream::{Cursor, TokenStream, TokenTree};
use syntax::ThinVec;
use syntax::{ast, parse, ptr};
use syntax_pos::{Symbol, DUMMY_SP};

use crate::comment::{
contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses,
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::iter::repeat;

use syntax::source_map::{BytePos, Span};
use rustc_span::{BytePos, Span};
use syntax::{ast, ptr};

use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/missed_spans.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use syntax::source_map::{BytePos, Pos, Span};
use rustc_span::{BytePos, Pos, Span};

use crate::comment::{is_last_comment_block, rewrite_comment, CodeCharKind, CommentCodeSlices};
use crate::config::file_lines::FileLines;
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/rustfmt-lib/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::borrow::Cow;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

use rustc_span::symbol::{sym, Symbol};
use syntax::ast;
use syntax::symbol::sym;
use syntax::visit::Visitor;
use syntax_pos::symbol::Symbol;

use crate::attr::MetaVisitor;
use crate::config::FileName;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/modules/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_span::Symbol;
use syntax::ast;
use syntax::visit::Visitor;
use syntax_pos::Symbol;

use crate::attr::MetaVisitor;
use crate::syntux::parser::{Directory, Parser};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::cmp::min;

use itertools::Itertools;
use rustc_span::Span;
use syntax::parse::token::DelimToken;
use syntax::source_map::Span;
use syntax::{ast, ptr};

use crate::closures;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/patterns.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_span::{BytePos, Span};
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
use syntax::ptr;
use syntax::source_map::{BytePos, Span};

use crate::comment::{combine_strs_with_missing_comments, FindUncommented};
use crate::config::lists::*;
Expand Down
7 changes: 4 additions & 3 deletions rustfmt-core/rustfmt-lib/src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

use std::cmp::{Ord, Ordering};

use syntax::{ast, attr, source_map::Span, symbol::sym};
use rustc_span::{Span, symbol::sym};
use syntax::{ast, attr};

use crate::config::Config;
use crate::imports::{merge_use_trees, UseTree};
Expand All @@ -31,9 +32,9 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
// `extern crate foo as bar;`
// ^^^ Comparing this.
let a_orig_name =
a_name.map_or_else(|| a.ident.as_str(), syntax_pos::symbol::Symbol::as_str);
a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str);
let b_orig_name =
b_name.map_or_else(|| b.ident.as_str(), syntax_pos::symbol::Symbol::as_str);
b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str);
let result = a_orig_name.cmp(&b_orig_name);
if result != Ordering::Equal {
return result;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::cell::{Cell, RefCell};
use std::rc::Rc;

use rustc_span::Span;
use syntax::ptr;
use syntax::source_map::Span;

use crate::config::{Config, IndentStyle};
use crate::shape::Shape;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/skip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Module that contains skip related stuffs.

use rustc_span::symbol::{sym, Symbol};
use syntax::ast::{Attribute, PathSegment};
use syntax::symbol::{sym, Symbol};

macro_rules! sym {
($tt:tt) => {
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/source_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! 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 syntax::source_map::{BytePos, Span};
use rustc_span::{BytePos, Span};

use crate::comment::FindUncommented;
use crate::config::file_lines::LineRange;
Expand Down
6 changes: 2 additions & 4 deletions rustfmt-core/rustfmt-lib/src/spanned.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::cmp::max;

use syntax::{
ast, ptr,
source_map::{self, Span},
};
use rustc_span::{source_map, Span};
use syntax::{ast, ptr};

use crate::macros::MacroArg;
use crate::utils::{mk_sp, outer_attributes};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_span::Span;
use syntax::ast;
use syntax_pos::Span;

use crate::comment::recover_comment_removed;
use crate::expr::{format_expr, ExprType};
Expand Down
5 changes: 2 additions & 3 deletions rustfmt-core/rustfmt-lib/src/syntux/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use std::borrow::Cow;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::path::{Path, PathBuf};

use rustc_span::{DUMMY_SP, Span, symbol::kw};
use syntax::ast;
use syntax::errors::Diagnostic;
use syntax::parse::parser::Parser as RawParser;
use syntax::parse::token::{DelimToken, TokenKind};
use syntax::parse::{new_sub_parser_from_file, PResult};
use syntax::source_map::{Span, DUMMY_SP};
use syntax::symbol::kw;

use crate::syntux::session::ParseSess;
use crate::{Config, Input};
Expand Down Expand Up @@ -108,7 +107,7 @@ impl<'a> ParserBuilder<'a> {
}),
Input::Text(text) => syntax::parse::maybe_new_parser_from_source_str(
sess,
syntax::source_map::FileName::Custom("stdin".to_owned()),
rustc_span::FileName::Custom("stdin".to_owned()),
text,
)
.map(|mut parser| {
Expand Down
10 changes: 4 additions & 6 deletions rustfmt-core/rustfmt-lib/src/syntux/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use std::path::Path;
use std::rc::Rc;

use rustc_data_structures::sync::Send;
use rustc_span::{BytePos, source_map::{FilePathMapping, SourceMap}, Span};
use syntax::ast;
use syntax::errors::emitter::{ColorConfig, Emitter, EmitterWriter};
use syntax::errors::{Diagnostic, Handler, Level as DiagnosticLevel};
use syntax::parse::ParseSess as RawParseSess;
use syntax::source_map::{FilePathMapping, SourceMap};
use syntax_pos::{BytePos, Span};

use crate::config::file_lines::LineRange;
use crate::ignore_path::IgnorePathSet;
Expand Down Expand Up @@ -59,7 +58,7 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
}
if let Some(primary_span) = &db.span.primary_span() {
let file_name = self.source_map.span_to_filename(*primary_span);
if let syntax_pos::FileName::Real(ref path) = file_name {
if let rustc_span::FileName::Real(ref path) = file_name {
if self
.ignore_path_set
.is_match(&FileName::Real(path.to_path_buf()))
Expand Down Expand Up @@ -154,7 +153,7 @@ impl ParseSess {
pub(crate) fn is_file_parsed(&self, path: &Path) -> bool {
self.parse_sess
.source_map()
.get_source_file(&syntax_pos::FileName::Real(path.to_path_buf()))
.get_source_file(&rustc_span::FileName::Real(path.to_path_buf()))
.is_some()
}

Expand Down Expand Up @@ -270,8 +269,7 @@ mod tests {
use crate::is_nightly_channel;
use crate::utils::mk_sp;
use std::path::PathBuf;
use syntax::source_map::FileName as SourceMapFileName;
use syntax_pos::MultiSpan;
use rustc_span::{MultiSpan, FileName as SourceMapFileName};

struct TestEmitter {
num_emitted_errors: Rc<RefCell<u32>>,
Expand Down
3 changes: 1 addition & 2 deletions rustfmt-core/rustfmt-lib/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::iter::ExactSizeIterator;
use std::ops::Deref;

use rustc_span::{BytePos, DUMMY_SP, Span, symbol::kw};
use syntax::ast::{self, FunctionRetTy, Mutability};
use syntax::source_map::{BytePos, Span, DUMMY_SP};
use syntax::symbol::kw;

use crate::config::lists::*;
use crate::config::{IndentStyle, TypeDensity};
Expand Down
4 changes: 1 addition & 3 deletions rustfmt-core/rustfmt-lib/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::borrow::Cow;

use rustc_span::{BytePos, ExpnId, Span, sym, Symbol, SyntaxContext};
use rustc_target::spec::abi;
use syntax::ast::{
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
VisibilityKind,
};
use syntax::ptr;
use syntax::source_map::{BytePos, Span, SyntaxContext};
use syntax::symbol::{sym, Symbol};
use syntax_pos::ExpnId;
use unicode_width::UnicodeWidthStr;

use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
Expand Down
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/vertical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::cmp;

use itertools::Itertools;
use rustc_span::{BytePos, Span};
use syntax::ast;
use syntax::source_map::{BytePos, Span};

use crate::comment::combine_strs_with_missing_comments;
use crate::config::lists::*;
Expand Down
Loading

0 comments on commit dc44c57

Please sign in to comment.