-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Inconsistent tokens between the same struct defined inside vs outside of function #49604
Comments
Possibly related to #47941 -- the tokens of |
I've confirmed that all the As to why there are different spans here, it looks like this is due to #43081. For recursive items we don't save off a token stream to return later, so the spans will all be "wrong". For example if you change the procedural macro to look like: #![feature(proc_macro)]
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_derive(Repro, attributes(repro))]
pub fn derive_repro(input: TokenStream) -> TokenStream {
input.into_iter()
.next()
.unwrap()
.span()
.error("test")
.emit();
TokenStream::empty()
} and then you also remove the doc comments, you'll get:
Note how the first error has a filename/line number, while the second has only a bogus one. Should this be closed in favor of #43081? |
If I understand correctly the explanation in #49596 (comment), with #49597 the |
I assigned myself and will try to reproduce after your changes land, and close if I cannot. |
The following script reproduces the issue as of rustc 1.26.0-nightly (06fa27d 2018-04-01).
The
repro
crate defines two identical structs,S1
at the top level outside of a function andS2
inside of a function. Therepro_derive
crate prints the Debug representation of the first four input token trees. For both structs the first four token trees are#
,[doc = "..."]
,#
,[doc = "..."]
.Pay attention to the tokens corresponding to the
=
signs that come after "doc". ForS1
(defined outside of function), the first and second=
tokens both saykind: Tree
.But in
S2
(defined within a function), the first=
token iskind: Tree
while the second=
token iskind: JointTree
. It would be good to understand what is causing the inconsistency between the tokenization ofS1
vsS2
.Repro script
@alexcrichton
The text was updated successfully, but these errors were encountered: