about summary refs log tree commit diff
path: root/src/libproc_macro/bridge
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-03-27 08:58:40 +0000
committerbors <bors@rust-lang.org>2019-03-27 08:58:40 +0000
commitc5fb4d0d2f464bc9ab61f7693ed4dde4d9326820 (patch)
treecdee8726acffb5087a4cb9343491a4b72e80a487 /src/libproc_macro/bridge
parent267fb90b55736dc2362e8621a247f54da5fd8d40 (diff)
parente88b0d9a94118168fd02a917e7c99ad47cf3418e (diff)
downloadrust-c5fb4d0d2f464bc9ab61f7693ed4dde4d9326820.tar.gz
rust-c5fb4d0d2f464bc9ab61f7693ed4dde4d9326820.zip
Auto merge of #55780 - ogoffart:span_source_text, r=petrochenkov
Introduce proc_macro::Span::source_text

A function to extract the actual source behind a Span.

Background: I would like to use `syn` in a `build.rs` script to parse the rust code, and extract part of the source code. However, `syn` only gives access to proc_macro2::Span, and i would like to get the source code behind that.
I opened an issue on proc_macro2 bug tracker for this feature https://github.com/alexcrichton/proc-macro2/issues/110  and @alexcrichton said the feature should first go upstream in proc_macro.  So there it is!

Since most of the Span API is unstable anyway, this is guarded by the same `proc_macro_span` feature as everything else.
Diffstat (limited to 'src/libproc_macro/bridge')
-rw-r--r--src/libproc_macro/bridge/mod.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/libproc_macro/bridge/mod.rs b/src/libproc_macro/bridge/mod.rs
index 276edb73009..3c48466fffa 100644
--- a/src/libproc_macro/bridge/mod.rs
+++ b/src/libproc_macro/bridge/mod.rs
@@ -155,6 +155,7 @@ macro_rules! with_api {
                 fn end($self: $S::Span) -> LineColumn;
                 fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
                 fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
+                fn source_text($self: $S::Span) -> Option<String>;
             },
         }
     };