Skip to content

Conversation

SergioBenitez
Copy link
Contributor

@SergioBenitez SergioBenitez commented Jan 1, 2018

As the title suggests: a couple of useful methods for proc_macro.

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

r? @jseyfried

@@ -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> {
Copy link
Member

@kennytm kennytm Jan 2, 2018

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]     | |_____^

@SergioBenitez
Copy link
Contributor Author

Yes, of course. I'll add some ui-tests as well.

@jseyfried
Copy link
Contributor

Great!
Alternative naming idea: parent -> source, source -> original_source. parent sounds a little strange to me w.r.t. spans. I don't have a super strong opinion though.

cc @nrc

@SergioBenitez
Copy link
Contributor Author

Added tests and fixed up the definition. I don't have a strong opinion about naming. parent simply felt more natural to me as I'm "moving up the chain".

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 3, 2018
@SergioBenitez
Copy link
Contributor Author

@jseyfried Look okay?

@jseyfried
Copy link
Contributor

jseyfried commented Jan 5, 2018

Yeah, let's land. @bors r+

@bors
Copy link
Collaborator

bors commented Jan 5, 2018

📌 Commit ab365be has been approved by jseyfried

@rust-lang rust-lang deleted a comment from bors Jan 5, 2018
@rust-lang rust-lang deleted a comment from bors Jan 5, 2018
@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 5, 2018
@bors
Copy link
Collaborator

bors commented Jan 6, 2018

⌛ Testing commit ab365be with merge a9a03d9...

bors added a commit that referenced this pull request Jan 6, 2018
Add 'Span::parent()' and 'Span::source()' to proc_macro API.

As the title suggests: a couple of useful methods for `proc_macro`.
@bors
Copy link
Collaborator

bors commented Jan 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: jseyfried
Pushing a9a03d9 to master...

@bors bors merged commit ab365be into rust-lang:master Jan 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants