Skip to content

Commit dc44c57

Browse files
refactor: symb/source_map/syntax_pos to rustc_span
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
1 parent 900c527 commit dc44c57

30 files changed

+49
-61
lines changed

rustfmt-core/rustfmt-config/src/file_lines.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
1010
use serde_json as json;
1111
use thiserror::Error;
1212

13-
use syntax_pos::{self, SourceFile};
13+
use rustc_span::{self, SourceFile};
1414

1515
/// A range of lines in a file, inclusive of both ends.
1616
pub struct LineRange {
@@ -26,21 +26,21 @@ pub enum FileName {
2626
Stdin,
2727
}
2828

29-
impl From<syntax_pos::FileName> for FileName {
30-
fn from(name: syntax_pos::FileName) -> FileName {
29+
impl From<rustc_span::FileName> for FileName {
30+
fn from(name: rustc_span::FileName) -> FileName {
3131
match name {
32-
syntax_pos::FileName::Real(p) => FileName::Real(p),
33-
syntax_pos::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin,
32+
rustc_span::FileName::Real(p) => FileName::Real(p),
33+
rustc_span::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin,
3434
_ => unreachable!(),
3535
}
3636
}
3737
}
3838

39-
impl From<&FileName> for syntax_pos::FileName {
40-
fn from(filename: &FileName) -> syntax_pos::FileName {
39+
impl From<&FileName> for rustc_span::FileName {
40+
fn from(filename: &FileName) -> rustc_span::FileName {
4141
match filename {
42-
FileName::Real(path) => syntax_pos::FileName::Real(path.to_owned()),
43-
FileName::Stdin => syntax_pos::FileName::Custom("stdin".to_owned()),
42+
FileName::Real(path) => rustc_span::FileName::Real(path.to_owned()),
43+
FileName::Stdin => rustc_span::FileName::Custom("stdin".to_owned()),
4444
}
4545
}
4646
}

rustfmt-core/rustfmt-config/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl Default for Edition {
374374
}
375375
}
376376

377-
impl From<Edition> for syntax_pos::edition::Edition {
377+
impl From<Edition> for rustc_span::edition::Edition {
378378
fn from(edition: Edition) -> Self {
379379
match edition {
380380
Edition::Edition2015 => Self::Edition2015,

rustfmt-core/rustfmt-lib/src/attr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Format attributes and meta items.
22
3+
use rustc_span::{BytePos, DUMMY_SP, Span, symbol::sym};
34
use syntax::ast;
4-
use syntax::source_map::{BytePos, Span, DUMMY_SP};
5-
use syntax::symbol::sym;
65

76
use self::doc_comment::DocCommentFormatter;
87
use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle};

rustfmt-core/rustfmt-lib/src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
use std::borrow::Cow;
5959
use std::cmp::min;
6060

61-
use syntax::source_map::{BytePos, Span};
61+
use rustc_span::{BytePos, Span};
6262
use syntax::{ast, ptr};
6363

6464
use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar};

rustfmt-core/rustfmt-lib/src/closures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syntax::source_map::Span;
1+
use rustc_span::Span;
22
use syntax::{ast, ptr};
33

44
use crate::attr::get_attrs_from_stmt;

rustfmt-core/rustfmt-lib/src/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::{self, borrow::Cow, iter};
44

55
use itertools::{multipeek, MultiPeek};
6-
use syntax::source_map::Span;
6+
use rustc_span::Span;
77

88
use crate::config::Config;
99
use crate::rewrite::RewriteContext;

rustfmt-core/rustfmt-lib/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::borrow::Cow;
22
use std::cmp::min;
33

44
use itertools::Itertools;
5+
use rustc_span::{BytePos, Span};
56
use syntax::parse::token::{DelimToken, LitKind};
6-
use syntax::source_map::{BytePos, Span};
77
use syntax::{ast, ptr};
88

99
use crate::chains::rewrite_chain;

rustfmt-core/rustfmt-lib/src/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::collections::HashMap;
44
use std::io::{self, Write};
55
use std::time::{Duration, Instant};
66

7+
use rustc_span::Span;
78
use syntax::ast;
8-
use syntax::source_map::Span;
99

1010
use self::newline_style::apply_newline_style;
1111
use crate::comment::{CharClasses, FullCodeCharKind};

rustfmt-core/rustfmt-lib/src/imports.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use std::borrow::Cow;
22
use std::cmp::Ordering;
33
use std::fmt;
44

5+
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol::sym};
56
use syntax::ast::{self, UseTreeKind};
6-
use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
7-
use syntax::symbol::sym;
87

98
use crate::comment::combine_strs_with_missing_comments;
109
use crate::config::lists::*;
@@ -854,7 +853,7 @@ impl Rewrite for UseTree {
854853
#[cfg(test)]
855854
mod test {
856855
use super::*;
857-
use syntax::source_map::DUMMY_SP;
856+
use rustc_span::DUMMY_SP;
858857

859858
// Parse the path part of an import. This parser is not robust and is only
860859
// suitable for use in a test harness.

rustfmt-core/rustfmt-lib/src/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::borrow::Cow;
44
use std::cmp::{max, min, Ordering};
55

66
use regex::Regex;
7+
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol};
78
use rustc_target::spec::abi;
8-
use syntax::source_map::{self, BytePos, Span};
99
use syntax::visit;
10-
use syntax::{ast, ptr, symbol};
10+
use syntax::{ast, ptr};
1111

1212
use crate::attr::filter_inline_attrs;
1313
use crate::comment::{
@@ -35,7 +35,7 @@ use crate::visitor::FmtVisitor;
3535

3636
const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned {
3737
node: ast::VisibilityKind::Inherited,
38-
span: source_map::DUMMY_SP,
38+
span: DUMMY_SP,
3939
};
4040

4141
fn type_annotation_separator(config: &Config) -> &str {

rustfmt-core/rustfmt-lib/src/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::cmp;
44
use std::iter::Peekable;
55

6-
use syntax::source_map::BytePos;
6+
use rustc_span::BytePos;
77

88
use crate::comment::{find_comment_end, rewrite_comment, FindUncommented};
99
use crate::config::lists::*;

rustfmt-core/rustfmt-lib/src/macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
use std::collections::HashMap;
1313
use std::panic::{catch_unwind, AssertUnwindSafe};
1414

15+
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, symbol::kw};
1516
use syntax::parse::new_parser_from_tts;
1617
use syntax::parse::parser::Parser;
1718
use syntax::parse::token::{BinOpToken, DelimToken, Token, TokenKind};
1819
use syntax::print::pprust;
19-
use syntax::source_map::{BytePos, Span};
20-
use syntax::symbol::kw;
2120
use syntax::tokenstream::{Cursor, TokenStream, TokenTree};
2221
use syntax::ThinVec;
2322
use syntax::{ast, parse, ptr};
24-
use syntax_pos::{Symbol, DUMMY_SP};
2523

2624
use crate::comment::{
2725
contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses,

rustfmt-core/rustfmt-lib/src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::iter::repeat;
44

5-
use syntax::source_map::{BytePos, Span};
5+
use rustc_span::{BytePos, Span};
66
use syntax::{ast, ptr};
77

88
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};

rustfmt-core/rustfmt-lib/src/missed_spans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syntax::source_map::{BytePos, Pos, Span};
1+
use rustc_span::{BytePos, Pos, Span};
22

33
use crate::comment::{is_last_comment_block, rewrite_comment, CodeCharKind, CommentCodeSlices};
44
use crate::config::file_lines::FileLines;

rustfmt-core/rustfmt-lib/src/modules.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use std::borrow::Cow;
22
use std::collections::BTreeMap;
33
use std::path::{Path, PathBuf};
44

5+
use rustc_span::symbol::{sym, Symbol};
56
use syntax::ast;
6-
use syntax::symbol::sym;
77
use syntax::visit::Visitor;
8-
use syntax_pos::symbol::Symbol;
98

109
use crate::attr::MetaVisitor;
1110
use crate::config::FileName;

rustfmt-core/rustfmt-lib/src/modules/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use rustc_span::Symbol;
12
use syntax::ast;
23
use syntax::visit::Visitor;
3-
use syntax_pos::Symbol;
44

55
use crate::attr::MetaVisitor;
66
use crate::syntux::parser::{Directory, Parser};

rustfmt-core/rustfmt-lib/src/overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::cmp::min;
44

55
use itertools::Itertools;
6+
use rustc_span::Span;
67
use syntax::parse::token::DelimToken;
7-
use syntax::source_map::Span;
88
use syntax::{ast, ptr};
99

1010
use crate::closures;

rustfmt-core/rustfmt-lib/src/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use rustc_span::{BytePos, Span};
12
use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
23
use syntax::ptr;
3-
use syntax::source_map::{BytePos, Span};
44

55
use crate::comment::{combine_strs_with_missing_comments, FindUncommented};
66
use crate::config::lists::*;

rustfmt-core/rustfmt-lib/src/reorder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

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

11-
use syntax::{ast, attr, source_map::Span, symbol::sym};
11+
use rustc_span::{Span, symbol::sym};
12+
use syntax::{ast, attr};
1213

1314
use crate::config::Config;
1415
use crate::imports::{merge_use_trees, UseTree};
@@ -31,9 +32,9 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
3132
// `extern crate foo as bar;`
3233
// ^^^ Comparing this.
3334
let a_orig_name =
34-
a_name.map_or_else(|| a.ident.as_str(), syntax_pos::symbol::Symbol::as_str);
35+
a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str);
3536
let b_orig_name =
36-
b_name.map_or_else(|| b.ident.as_str(), syntax_pos::symbol::Symbol::as_str);
37+
b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str);
3738
let result = a_orig_name.cmp(&b_orig_name);
3839
if result != Ordering::Equal {
3940
return result;

rustfmt-core/rustfmt-lib/src/rewrite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::cell::{Cell, RefCell};
44
use std::rc::Rc;
55

6+
use rustc_span::Span;
67
use syntax::ptr;
7-
use syntax::source_map::Span;
88

99
use crate::config::{Config, IndentStyle};
1010
use crate::shape::Shape;

rustfmt-core/rustfmt-lib/src/skip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Module that contains skip related stuffs.
22
3+
use rustc_span::symbol::{sym, Symbol};
34
use syntax::ast::{Attribute, PathSegment};
4-
use syntax::symbol::{sym, Symbol};
55

66
macro_rules! sym {
77
($tt:tt) => {

rustfmt-core/rustfmt-lib/src/source_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module contains utilities that work with the `SourceMap` from `libsyntax`/`syntex_syntax`.
22
//! This includes extension traits and methods for looking up spans and line ranges for AST nodes.
33
4-
use syntax::source_map::{BytePos, Span};
4+
use rustc_span::{BytePos, Span};
55

66
use crate::comment::FindUncommented;
77
use crate::config::file_lines::LineRange;

rustfmt-core/rustfmt-lib/src/spanned.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::cmp::max;
22

3-
use syntax::{
4-
ast, ptr,
5-
source_map::{self, Span},
6-
};
3+
use rustc_span::{source_map, Span};
4+
use syntax::{ast, ptr};
75

86
use crate::macros::MacroArg;
97
use crate::utils::{mk_sp, outer_attributes};

rustfmt-core/rustfmt-lib/src/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use rustc_span::Span;
12
use syntax::ast;
2-
use syntax_pos::Span;
33

44
use crate::comment::recover_comment_removed;
55
use crate::expr::{format_expr, ExprType};

rustfmt-core/rustfmt-lib/src/syntux/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use std::borrow::Cow;
22
use std::panic::{catch_unwind, AssertUnwindSafe};
33
use std::path::{Path, PathBuf};
44

5+
use rustc_span::{DUMMY_SP, Span, symbol::kw};
56
use syntax::ast;
67
use syntax::errors::Diagnostic;
78
use syntax::parse::parser::Parser as RawParser;
89
use syntax::parse::token::{DelimToken, TokenKind};
910
use syntax::parse::{new_sub_parser_from_file, PResult};
10-
use syntax::source_map::{Span, DUMMY_SP};
11-
use syntax::symbol::kw;
1211

1312
use crate::syntux::session::ParseSess;
1413
use crate::{Config, Input};
@@ -108,7 +107,7 @@ impl<'a> ParserBuilder<'a> {
108107
}),
109108
Input::Text(text) => syntax::parse::maybe_new_parser_from_source_str(
110109
sess,
111-
syntax::source_map::FileName::Custom("stdin".to_owned()),
110+
rustc_span::FileName::Custom("stdin".to_owned()),
112111
text,
113112
)
114113
.map(|mut parser| {

rustfmt-core/rustfmt-lib/src/syntux/session.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use std::path::Path;
33
use std::rc::Rc;
44

55
use rustc_data_structures::sync::Send;
6+
use rustc_span::{BytePos, source_map::{FilePathMapping, SourceMap}, Span};
67
use syntax::ast;
78
use syntax::errors::emitter::{ColorConfig, Emitter, EmitterWriter};
89
use syntax::errors::{Diagnostic, Handler, Level as DiagnosticLevel};
910
use syntax::parse::ParseSess as RawParseSess;
10-
use syntax::source_map::{FilePathMapping, SourceMap};
11-
use syntax_pos::{BytePos, Span};
1211

1312
use crate::config::file_lines::LineRange;
1413
use crate::ignore_path::IgnorePathSet;
@@ -59,7 +58,7 @@ impl Emitter for SilentOnIgnoredFilesEmitter {
5958
}
6059
if let Some(primary_span) = &db.span.primary_span() {
6160
let file_name = self.source_map.span_to_filename(*primary_span);
62-
if let syntax_pos::FileName::Real(ref path) = file_name {
61+
if let rustc_span::FileName::Real(ref path) = file_name {
6362
if self
6463
.ignore_path_set
6564
.is_match(&FileName::Real(path.to_path_buf()))
@@ -154,7 +153,7 @@ impl ParseSess {
154153
pub(crate) fn is_file_parsed(&self, path: &Path) -> bool {
155154
self.parse_sess
156155
.source_map()
157-
.get_source_file(&syntax_pos::FileName::Real(path.to_path_buf()))
156+
.get_source_file(&rustc_span::FileName::Real(path.to_path_buf()))
158157
.is_some()
159158
}
160159

@@ -270,8 +269,7 @@ mod tests {
270269
use crate::is_nightly_channel;
271270
use crate::utils::mk_sp;
272271
use std::path::PathBuf;
273-
use syntax::source_map::FileName as SourceMapFileName;
274-
use syntax_pos::MultiSpan;
272+
use rustc_span::{MultiSpan, FileName as SourceMapFileName};
275273

276274
struct TestEmitter {
277275
num_emitted_errors: Rc<RefCell<u32>>,

rustfmt-core/rustfmt-lib/src/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::iter::ExactSizeIterator;
22
use std::ops::Deref;
33

4+
use rustc_span::{BytePos, DUMMY_SP, Span, symbol::kw};
45
use syntax::ast::{self, FunctionRetTy, Mutability};
5-
use syntax::source_map::{BytePos, Span, DUMMY_SP};
6-
use syntax::symbol::kw;
76

87
use crate::config::lists::*;
98
use crate::config::{IndentStyle, TypeDensity};

rustfmt-core/rustfmt-lib/src/utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use std::borrow::Cow;
22

3+
use rustc_span::{BytePos, ExpnId, Span, sym, Symbol, SyntaxContext};
34
use rustc_target::spec::abi;
45
use syntax::ast::{
56
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
67
VisibilityKind,
78
};
89
use syntax::ptr;
9-
use syntax::source_map::{BytePos, Span, SyntaxContext};
10-
use syntax::symbol::{sym, Symbol};
11-
use syntax_pos::ExpnId;
1210
use unicode_width::UnicodeWidthStr;
1311

1412
use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};

rustfmt-core/rustfmt-lib/src/vertical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::cmp;
44

55
use itertools::Itertools;
6+
use rustc_span::{BytePos, Span};
67
use syntax::ast;
7-
use syntax::source_map::{BytePos, Span};
88

99
use crate::comment::combine_strs_with_missing_comments;
1010
use crate::config::lists::*;

0 commit comments

Comments
 (0)