Skip to content

Commit 9835697

Browse files
committed
push TokenTree::parse down
1 parent 9fd75f5 commit 9835697

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/libsyntax/ext/mbe/macro_rules.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ext::mbe;
88
use crate::ext::mbe::macro_check;
99
use crate::ext::mbe::macro_parser::{parse, parse_failure_msg};
1010
use crate::ext::mbe::macro_parser::{Error, Failure, Success};
11-
use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq};
11+
use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult};
1212
use crate::ext::mbe::transcribe::transcribe;
1313
use crate::feature_gate::Features;
1414
use crate::parse::parser::Parser;
@@ -1171,3 +1171,16 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
11711171
),
11721172
}
11731173
}
1174+
1175+
impl TokenTree {
1176+
/// Use this token tree as a matcher to parse given tts.
1177+
fn parse(cx: &ExtCtxt<'_>, mtch: &[mbe::TokenTree], tts: TokenStream)
1178+
-> NamedParseResult {
1179+
// `None` is because we're not interpolating
1180+
let directory = Directory {
1181+
path: Cow::from(cx.current_expansion.module.directory.as_path()),
1182+
ownership: cx.current_expansion.directory_ownership,
1183+
};
1184+
parse(cx.parse_sess(), tts, mtch, Some(directory), true)
1185+
}
1186+
}

src/libsyntax/tokenstream.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
1414
//! ownership of the original.
1515
16-
use crate::ext::base;
17-
use crate::ext::mbe::{self, macro_parser};
18-
use crate::parse::Directory;
1916
use crate::parse::token::{self, DelimToken, Token, TokenKind};
2017
use crate::print::pprust;
2118

@@ -26,7 +23,6 @@ use rustc_data_structures::sync::Lrc;
2623
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
2724
use smallvec::{SmallVec, smallvec};
2825

29-
use std::borrow::Cow;
3026
use std::{fmt, iter, mem};
3127

3228
#[cfg(test)]
@@ -63,17 +59,6 @@ where
6359
{}
6460

6561
impl TokenTree {
66-
/// Use this token tree as a matcher to parse given tts.
67-
crate fn parse(cx: &base::ExtCtxt<'_>, mtch: &[mbe::TokenTree], tts: TokenStream)
68-
-> macro_parser::NamedParseResult {
69-
// `None` is because we're not interpolating
70-
let directory = Directory {
71-
path: Cow::from(cx.current_expansion.module.directory.as_path()),
72-
ownership: cx.current_expansion.directory_ownership,
73-
};
74-
macro_parser::parse(cx.parse_sess(), tts, mtch, Some(directory), true)
75-
}
76-
7762
/// Checks if this TokenTree is equal to the other, regardless of span information.
7863
pub fn eq_unspanned(&self, other: &TokenTree) -> bool {
7964
match (self, other) {

0 commit comments

Comments
 (0)