Skip to content
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 proc_macro::Span::{before, after}. #86165

Merged
merged 2 commits into from
Sep 11, 2021

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Jun 9, 2021

This adds proc_macro::Span::before() and proc_macro::Span::after() to get a zero width span at the start or end of the span.

These are equivalent to rustc's Span::shrink_to_lo() and Span::shrink_to_hi() but with a less cryptic name. They are useful when generating diagnostlics like "missing <thing> after <thing>".

E.g.

syn::Error::new(ident.span().after(), "missing `:` after field name").into_compile_error()

@m-ou-se m-ou-se added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-proc-macros Area: Procedural macros labels Jun 9, 2021
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 9, 2021
library/proc_macro/src/lib.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov removed their assignment Jun 9, 2021
@jhpratt
Copy link
Member

jhpratt commented Jun 13, 2021

Part of me would prefer this be called start and end, but those names are already (unstably) taken.

Would it makes sense to repurpose these names and provide a generalized .location() method that would return the LineColumn? Presumably it could point to the start of the span. Alternatively .start_location() and .end_location() could be provided.

Just a random thought I had from a usability perspective; I could certainly get accustomed to the before/after naming.

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 5, 2021
@joelpalmer joelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 20, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Jul 28, 2021

@jhpratt Since a span is not a point/location but a range, calling it start and end doesn't feel entirely accurate to me.

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Sep 8, 2021

r? @dtolnay

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API looks good to me as implemented.

@dtolnay
Copy link
Member

dtolnay commented Sep 9, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Sep 9, 2021

📌 Commit f9be6cd has been approved by dtolnay

@bors
Copy link
Contributor

bors commented Sep 9, 2021

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@bors bors 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 Sep 9, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 11, 2021
…arth

Rollup of 15 pull requests

Successful merges:

 - rust-lang#85200 (Ignore derived Clone and Debug implementations during dead code analysis)
 - rust-lang#86165 (Add proc_macro::Span::{before, after}.)
 - rust-lang#87088 (Fix stray notes when the source code is not available)
 - rust-lang#87441 (Emit suggestion when passing byte literal to format macro)
 - rust-lang#88546 (Emit proper errors when on missing closure braces)
 - rust-lang#88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`)
 - rust-lang#88632 (Fix issues with Markdown summary options)
 - rust-lang#88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields)
 - rust-lang#88667 (Tweak `write_fmt` doc.)
 - rust-lang#88720 (Rustdoc coverage fields count)
 - rust-lang#88732 (RustWrapper: avoid deleted unclear attribute methods)
 - rust-lang#88742 (Fix table in docblocks)
 - rust-lang#88776 (Workaround blink/chromium grid layout limitation of 1000 rows)
 - rust-lang#88807 (Fix typo in docs for iterators)
 - rust-lang#88812 (Fix typo `option` -> `options`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 000dbd2 into rust-lang:master Sep 11, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 11, 2021
@m-ou-se m-ou-se deleted the proc-macro-span-shrink branch September 11, 2021 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macros Area: Procedural macros S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants