Skip to content

Commit 263b36b

Browse files
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
1 parent d2dc21d commit 263b36b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/libproc_macro/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl Span {
270270
/// `self` was generated from, if any.
271271
#[unstable(feature = "proc_macro", issue = "38356")]
272272
pub fn parent(&self) -> Option<Span> {
273-
self.0.ctxt().outer().expn_info().map(|i| Span(i.call_site))
273+
self.0.parent().map(|x| { Span(x) })
274274
}
275275

276276
/// The span for the origin source code that `self` was generated from. If

src/libsyntax_pos/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ impl Span {
291291
self.ctxt().outer().expn_info().map(|info| info.call_site.source_callsite()).unwrap_or(self)
292292
}
293293

294+
/// The `Span for the tokens in the previous macro expansion from which `self` was generated,
295+
/// if any
296+
pub fn parent(self) -> Option<Span> {
297+
self.ctxt().outer().expn_info().map(|i| i.call_site)
298+
}
299+
294300
/// Return the source callee.
295301
///
296302
/// Returns None if the supplied span has no expansion trace,

0 commit comments

Comments
 (0)