about summary refs log tree commit diff
path: root/src/libsyntax_pos/lib.rs
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-21 21:28:22 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-23 01:44:33 +0300
commit0fb01d219c7b7de142ad4097dd1e5cf708e7a27f (patch)
treeb800e81720ceccc8ad2ea2722288cea4d6ec3a72 /src/libsyntax_pos/lib.rs
parent760226733e940cb375f791e894fbb554555eeb01 (diff)
downloadrust-0fb01d219c7b7de142ad4097dd1e5cf708e7a27f.tar.gz
rust-0fb01d219c7b7de142ad4097dd1e5cf708e7a27f.zip
Audit uses of `apply_mark` in built-in macros
Replace them with equivalents of `Span::{def_site,call_site}` from proc macro API.
The new API is much less error prone and doesn't rely on macros having default transparency.
Diffstat (limited to 'src/libsyntax_pos/lib.rs')
-rw-r--r--src/libsyntax_pos/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index a17cd7625fb..6fffefd0d6c 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -22,6 +22,7 @@ pub mod edition;
 use edition::Edition;
 pub mod hygiene;
 pub use hygiene::{ExpnId, SyntaxContext, ExpnData, ExpnKind, MacroKind, DesugaringKind};
+use hygiene::Transparency;
 
 mod span_encoding;
 pub use span_encoding::{Span, DUMMY_SP};
@@ -512,6 +513,13 @@ impl Span {
                   span.ctxt)
     }
 
+    /// Produces a span with the same location as `self` and context produced by a macro with the
+    /// given ID and transparency, assuming that macro was defined directly and not produced by
+    /// some other macro (which is the case for built-in and procedural macros).
+    pub fn with_ctxt_from_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
+        self.with_ctxt(SyntaxContext::root().apply_mark_with_transparency(expn_id, transparency))
+    }
+
     #[inline]
     pub fn apply_mark(self, mark: ExpnId) -> Span {
         let span = self.data();