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

[proc macros] confusing statement #1209

Closed
evgeniy-terekhin opened this issue May 8, 2022 · 3 comments · Fixed by #1219
Closed

[proc macros] confusing statement #1209

evgeniy-terekhin opened this issue May 8, 2022 · 3 comments · Fixed by #1219
Labels
A-proc-macro Area: proc-macros Easy We believe this would not be difficult to actually fix Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like.

Comments

@evgeniy-terekhin
Copy link

evgeniy-terekhin commented May 8, 2022

link: https://doc.rust-lang.org/reference/procedural-macros.html#the-proc_macro-crate

When token span's are mentioned there is this phrase.

All tokens have an associated Span. A Span is an opaque value that cannot be modified but can be manufactured. Spans represent an extent of source code within a program and are primarily used for error reporting. You can modify the Span of any token.

To me it seems like a contradiction. I would have submit a fix straight away but I am not sure how to express it correctly.

@bjorn3
Copy link
Member

bjorn3 commented May 8, 2022

You can change what span a token has, but you can't change for example the start or end character of a span, or change it's file. This means that if you want to change the span of a token, you either have to get it from another token, or you have to use Span::call_site() or Span::def_site() to get the span of the macro invocation cq the macro definition.

@evgeniy-terekhin
Copy link
Author

@bjorn3 thanks for the clarification. Maybe somthing like whar you wrote should be added to the reference to make the phrasing less confusing.

@ehuss ehuss added Easy We believe this would not be difficult to actually fix Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like. A-proc-macro Area: proc-macros labels May 9, 2022
@Havvy
Copy link
Contributor

Havvy commented May 11, 2022

It might be better to say that spans are immutable while the span a token has is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro Area: proc-macros Easy We believe this would not be difficult to actually fix Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants