Skip to content

Commit 93b2bb0

Browse files
author
Esteban Küber
committed
Remove dependency on libsyntax
1 parent a7a6837 commit 93b2bb0

File tree

5 files changed

+13
-23
lines changed

5 files changed

+13
-23
lines changed

src/Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,6 @@ dependencies = [
715715
[[package]]
716716
name = "fmt_macros"
717717
version = "0.0.0"
718-
dependencies = [
719-
"syntax 0.0.0",
720-
]
721718

722719
[[package]]
723720
name = "fnv"

src/libfmt_macros/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ version = "0.0.0"
77
name = "fmt_macros"
88
path = "lib.rs"
99
crate-type = ["dylib"]
10-
11-
[dependencies]
12-
syntax = { path = "../libsyntax" }

src/libfmt_macros/lib.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ pub use self::Alignment::*;
2828
pub use self::Flag::*;
2929
pub use self::Count::*;
3030

31-
extern crate syntax;
32-
3331
use std::str;
3432
use std::string;
3533
use std::iter;
@@ -152,8 +150,8 @@ pub struct Parser<'a> {
152150
pub errors: Vec<ParseError>,
153151
/// Current position of implicit positional argument pointer
154152
curarg: usize,
155-
/// The style of the string (raw or not), used to position spans correctly
156-
style: syntax::ast::StrStyle,
153+
/// `Some(raw count)` when the string is "raw", used to position spans correctly
154+
style: Option<usize>,
157155
/// How many newlines have been seen in the string so far, to adjust the error spans
158156
seen_newlines: usize,
159157
}
@@ -162,10 +160,7 @@ impl<'a> Iterator for Parser<'a> {
162160
type Item = Piece<'a>;
163161

164162
fn next(&mut self) -> Option<Piece<'a>> {
165-
let raw = match self.style {
166-
syntax::ast::StrStyle::Raw(raw) => raw as usize + self.seen_newlines,
167-
_ => 0,
168-
};
163+
let raw = self.style.map(|raw| raw + self.seen_newlines).unwrap_or(0);
169164
if let Some(&(pos, c)) = self.cur.peek() {
170165
match c {
171166
'{' => {
@@ -208,7 +203,7 @@ impl<'a> Iterator for Parser<'a> {
208203

209204
impl<'a> Parser<'a> {
210205
/// Creates a new parser for the given format string
211-
pub fn new(s: &'a str, style: syntax::ast::StrStyle) -> Parser<'a> {
206+
pub fn new(s: &'a str, style: Option<usize>) -> Parser<'a> {
212207
Parser {
213208
input: s,
214209
cur: s.char_indices().peekable(),
@@ -278,10 +273,7 @@ impl<'a> Parser<'a> {
278273
/// found, an error is emitted.
279274
fn must_consume(&mut self, c: char) {
280275
self.ws();
281-
let raw = match self.style {
282-
syntax::ast::StrStyle::Raw(raw) => raw as usize,
283-
_ => 0,
284-
};
276+
let raw = self.style.unwrap_or(0);
285277

286278
let padding = raw + self.seen_newlines;
287279
if let Some(&(pos, maybe)) = self.cur.peek() {

src/librustc/traits/on_unimplemented.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ty::{self, TyCtxt, GenericParamDefKind};
1515
use util::common::ErrorReported;
1616
use util::nodemap::FxHashMap;
1717

18-
use syntax::ast::{self, MetaItem, NestedMetaItem};
18+
use syntax::ast::{MetaItem, NestedMetaItem};
1919
use syntax::attr;
2020
use syntax_pos::Span;
2121
use syntax_pos::symbol::LocalInternedString;
@@ -242,7 +242,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
242242
{
243243
let name = tcx.item_name(trait_def_id);
244244
let generics = tcx.generics_of(trait_def_id);
245-
let parser = Parser::new(&self.0, ast::StrStyle::Cooked);
245+
let parser = Parser::new(&self.0, None);
246246
let mut result = Ok(());
247247
for token in parser {
248248
match token {
@@ -298,7 +298,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
298298
Some((name, value))
299299
}).collect::<FxHashMap<String, String>>();
300300

301-
let parser = Parser::new(&self.0, ast::StrStyle::Cooked);
301+
let parser = Parser::new(&self.0, None);
302302
parser.map(|p| {
303303
match p {
304304
Piece::String(s) => s,

src/libsyntax_ext/format.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,11 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
778778
};
779779

780780
let fmt_str = &*fmt.node.0.as_str();
781-
let mut parser = parse::Parser::new(fmt_str, fmt.node.1);
781+
let str_style = match fmt.node.1 {
782+
ast::StrStyle::Cooked => None,
783+
ast::StrStyle::Raw(raw) => Some(raw as usize),
784+
};
785+
let mut parser = parse::Parser::new(fmt_str, str_style);
782786
let mut pieces = vec![];
783787

784788
while let Some(mut piece) = parser.next() {

0 commit comments

Comments
 (0)