-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
macros: improve Span
's expansion information
#40597
Conversation
0d99228
to
c8a8919
Compare
01a7ef2
to
dba83c6
Compare
@@ -22,7 +22,7 @@ macro_rules! indirect_line { () => ( line!() ) } | |||
|
|||
pub fn main() { | |||
assert_eq!(line!(), 24); | |||
assert_eq!(column!(), 4); | |||
assert_eq!(column!(), 15); |
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.
c.f. #40649; technically a [breaking-change]
☔ The latest upstream changes (presumably #40346) made this pull request unmergeable. Please resolve the merge conflicts. |
e7e0177
to
72a3d9e
Compare
☔ The latest upstream changes (presumably #40693) made this pull request unmergeable. Please resolve the merge conflicts. |
72a3d9e
to
061faa7
Compare
☔ The latest upstream changes (presumably #40043) made this pull request unmergeable. Please resolve the merge conflicts. |
061faa7
to
a30cfc0
Compare
☔ The latest upstream changes (presumably #40752) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
r=me, assuming losing the command line span thing is fine.
This seems a good step in the right direction. I worry a bit that to
is still too easy to create malformed spans, but it is def. better than mk_sp.
// Generic span to be used for code originating from the command line | ||
pub const COMMAND_LINE_SP: Span = Span { lo: BytePos(0), | ||
hi: BytePos(0), | ||
expn_id: COMMAND_LINE_EXPN }; |
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.
What do we do now for code from the command line?
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.
Same as before -- DUMMY_SP
. The only place COMMAND_LINE_SP
was used was here, which only happens when naming a legacy plugin crate through a debugging command line option.
81adb79
to
8c49446
Compare
@bors r=nrc |
📌 Commit 8c49446 has been approved by |
3618a0b
to
8ba347e
Compare
@bors r=nrc |
📌 Commit 8ba347e has been approved by |
⌛ Testing commit 8ba347e with merge 2731d4d... |
💔 Test failed - status-appveyor |
8ba347e
to
cfad0fe
Compare
cfad0fe
to
8fde04b
Compare
macros: improve `Span`'s expansion information This PR improves `Span`'s expansion information. More specifically: - It refactors AST node span construction to preserve expansion information. - Today, we only use the underlying tokens' `BytePos`s, throwing away the `ExpnId`s. - This improves the accuracy of AST nodes' expansion information, fixing #30506. - It refactors `span.expn_id: ExpnId` to `span.ctxt: SyntaxContext` and removes `ExpnId`. - This gives all tokens as much hygiene information as `Ident`s. - This is groundwork for procedural macros 2.0 `TokenStream` API. - This is also groundwork for declarative macros 2.0, which will need this hygiene information for some non-`Ident` tokens. - It simplifies processing of spans' expansion information throughout the compiler. - It fixes #40649. - It fixes #39450 and fixes part of #23480. r? @nrc
@bors r=nrc |
📌 Commit 8fde04b has been approved by |
☀️ Test successful - status-appveyor, status-travis |
I'm seeing the following, which may be related to this: warning: {warning message from a syntax extension}
--> /a/nice/big/file/path/here.rs:10:21
|
| and so on...
|
= note: this error originates in a macro outside of the current crate The issue is that the "note:` refers to the warning as an "error". It should say: "this warning originates from a macro outside of the current crate". |
This PR improves
Span
's expansion information. More specifically:BytePos
s, throwing away theExpnId
s.span.expn_id: ExpnId
tospan.ctxt: SyntaxContext
and removesExpnId
.Ident
s.TokenStream
API.Ident
tokens.panic!
reports can be wrong in macro invocations #40649.Span
values #23480.r? @nrc