diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-09-22 18:38:02 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-10-03 11:28:06 +0300 |
| commit | d1310dc6c989e191d85c73c943d4175fbf1dccb8 (patch) | |
| tree | d0ca6fac9bdb651e328a8a6990c16208ad5dc43a /src/libsyntax | |
| parent | c6293e359848c8c7275330719b33ccd168df04c3 (diff) | |
| download | rust-d1310dc6c989e191d85c73c943d4175fbf1dccb8.tar.gz rust-d1310dc6c989e191d85c73c943d4175fbf1dccb8.zip | |
proc_macro: Add `Span::mixed_site` exposing `macro_rules` hygiene
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/proc_macro_server.rs | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 54cfb80573e..583fb3f7701 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -953,6 +953,12 @@ impl<'a> ExtCtxt<'a> { span.with_call_site_ctxt(self.current_expansion.id) } + /// Equivalent of `Span::mixed_site` from the proc macro API, + /// except that the location is taken from the span passed as an argument. + pub fn with_mixed_site_ctxt(&self, span: Span) -> Span { + span.with_mixed_site_ctxt(self.current_expansion.id) + } + /// Returns span for the macro which originally caused the current expansion to happen. /// /// Stops backtracing at include! boundary. diff --git a/src/libsyntax/ext/proc_macro_server.rs b/src/libsyntax/ext/proc_macro_server.rs index dfec9ee2880..021ec46d987 100644 --- a/src/libsyntax/ext/proc_macro_server.rs +++ b/src/libsyntax/ext/proc_macro_server.rs @@ -355,6 +355,7 @@ pub(crate) struct Rustc<'a> { sess: &'a ParseSess, def_site: Span, call_site: Span, + mixed_site: Span, } impl<'a> Rustc<'a> { @@ -364,6 +365,7 @@ impl<'a> Rustc<'a> { sess: cx.parse_sess, def_site: cx.with_def_site_ctxt(expn_data.def_site), call_site: cx.with_call_site_ctxt(expn_data.call_site), + mixed_site: cx.with_mixed_site_ctxt(expn_data.call_site), } } @@ -664,6 +666,9 @@ impl server::Span for Rustc<'_> { fn call_site(&mut self) -> Self::Span { self.call_site } + fn mixed_site(&mut self) -> Self::Span { + self.mixed_site + } fn source_file(&mut self, span: Self::Span) -> Self::SourceFile { self.sess.source_map().lookup_char_pos(span.lo()).file } |
