diff options
| author | bobtwinkles <srkoser+GitHub@gmail.com> | 2018-04-21 18:15:54 -0400 |
|---|---|---|
| committer | bobtwinkles <srkoser+GitHub@gmail.com> | 2018-04-23 23:59:58 -0400 |
| commit | 263b36b071ba8b52cd4f79ca36494b05d4762430 (patch) | |
| tree | 8b3471fd52750a0ae4c0fea9138d9fc081f60199 /src | |
| parent | d2dc21df02a6f24b0c5629d3c3ebc7c9b85d20da (diff) | |
| download | rust-263b36b071ba8b52cd4f79ca36494b05d4762430.tar.gz rust-263b36b071ba8b52cd4f79ca36494b05d4762430.zip | |
Implement parent() on `syntax_pos::Span`
... and reimplement proc_macro::Span::parent using it. This function turns out to be useful in the compiler as well
Diffstat (limited to 'src')
| -rw-r--r-- | src/libproc_macro/lib.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index e171216523a..4d24353a383 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -270,7 +270,7 @@ impl Span { /// `self` was generated from, if any. #[unstable(feature = "proc_macro", issue = "38356")] pub fn parent(&self) -> Option<Span> { - self.0.ctxt().outer().expn_info().map(|i| Span(i.call_site)) + self.0.parent().map(|x| { Span(x) }) } /// The span for the origin source code that `self` was generated from. If diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 9a7d1fd8ee6..19f52d83a01 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -291,6 +291,12 @@ impl Span { self.ctxt().outer().expn_info().map(|info| info.call_site.source_callsite()).unwrap_or(self) } + /// The `Span for the tokens in the previous macro expansion from which `self` was generated, + /// if any + pub fn parent(self) -> Option<Span> { + self.ctxt().outer().expn_info().map(|i| i.call_site) + } + /// Return the source callee. /// /// Returns None if the supplied span has no expansion trace, |
