about summary refs log tree commit diff
path: root/src/libsyntax/ext/mbe/macro_rules.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/ext/mbe/macro_rules.rs')
-rw-r--r--src/libsyntax/ext/mbe/macro_rules.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libsyntax/ext/mbe/macro_rules.rs b/src/libsyntax/ext/mbe/macro_rules.rs
index 2ec171a7fb5..816baadb12f 100644
--- a/src/libsyntax/ext/mbe/macro_rules.rs
+++ b/src/libsyntax/ext/mbe/macro_rules.rs
@@ -8,7 +8,7 @@ use crate::ext::mbe;
 use crate::ext::mbe::macro_check;
 use crate::ext::mbe::macro_parser::{parse, parse_failure_msg};
 use crate::ext::mbe::macro_parser::{Error, Failure, Success};
-use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq};
+use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult};
 use crate::ext::mbe::transcribe::transcribe;
 use crate::feature_gate::Features;
 use crate::parse::parser::Parser;
@@ -1171,3 +1171,16 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
         ),
     }
 }
+
+impl TokenTree {
+    /// Use this token tree as a matcher to parse given tts.
+    fn parse(cx: &ExtCtxt<'_>, mtch: &[mbe::TokenTree], tts: TokenStream)
+             -> NamedParseResult {
+        // `None` is because we're not interpolating
+        let directory = Directory {
+            path: Cow::from(cx.current_expansion.module.directory.as_path()),
+            ownership: cx.current_expansion.directory_ownership,
+        };
+        parse(cx.parse_sess(), tts, mtch, Some(directory), true)
+    }
+}