-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'Span::parent()' and 'Span::source()' to proc_macro API. #47099
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @jseyfried |
src/libproc_macro/lib.rs
Outdated
@@ -221,6 +221,19 @@ impl Span { | |||
} | |||
} | |||
|
|||
/// The `Span` for the tokens in the previous macro expansion from which | |||
/// `self` was generated from, if any. | |||
pub fn parent(&self) -> Option<Span> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs #[unstable(feature = "proc_macro", …)]
. (Similar for source()
)
[00:07:40] error: This node does not have a stability attribute
[00:07:40] --> /checkout/src/libproc_macro/lib.rs:226:5
[00:07:40] |
[00:07:40] 226 | / pub fn parent(&self) -> Option<Span> {
[00:07:40] 227 | | self.0.ctxt().outer().expn_info().map(|i| Span(i.call_site))
[00:07:40] 228 | | }
[00:07:40] | |_____^
[00:07:40]
[00:07:40] error: This node does not have a stability attribute
[00:07:40] --> /checkout/src/libproc_macro/lib.rs:233:5
[00:07:40] |
[00:07:40] 233 | / pub fn source(&self) -> Span {
[00:07:40] 234 | | Span(self.0.source_callsite())
[00:07:40] 235 | | }
[00:07:40] | |_____^
Yes, of course. I'll add some ui-tests as well. |
Great! cc @nrc |
Added tests and fixed up the definition. I don't have a strong opinion about naming. |
@jseyfried Look okay? |
Yeah, let's land. @bors r+ |
📌 Commit ab365be has been approved by |
Add 'Span::parent()' and 'Span::source()' to proc_macro API. As the title suggests: a couple of useful methods for `proc_macro`.
☀️ Test successful - status-appveyor, status-travis |
As the title suggests: a couple of useful methods for
proc_macro
.