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

Span for FnArg::Receiver in proc_macro seems to point to first token not whole receiver #888

Closed
illicitonion opened this issue Aug 19, 2020 · 1 comment

Comments

@illicitonion
Copy link

See this repo for a repro.

I tried to point an error message at a function receiver. Parsing the code as a string, this seems to work fine. Parsing it from a TokenStream, in a proc_macro, the Span for the FnArg::Receiver appears to point to the first token of the receiver, rather than the whole thing:

error: Saw receiver with span #0 bytes(63..64)
 --> example/src/lib.rs:7:19
  |
7 |     fn by_mut_ref(&mut self) -> bool {
  |                   ^

error: Saw receiver with span #0 bytes(126..130)
  --> example/src/lib.rs:12:12
   |
12 |     fn own(self) -> bool {
   |            ^^^^

error: Saw receiver with span #0 bytes(188..191)
  --> example/src/lib.rs:17:16
   |
17 |     fn own_mut(mut self) -> bool {
   |                ^^^

error: Saw receiver with span #0 bytes(253..254)
  --> example/src/lib.rs:22:15
   |
22 |     fn by_ref(&self) -> bool {
   |               ^

If I parse the same code from a str, I get the spans I expect (or at least, :

bytes(21..30)
bytes(86..90)
@dtolnay
Copy link
Owner

dtolnay commented Aug 19, 2020

Hi @illicitonion, this matches the documented behavior -- please see https://docs.rs/syn/1.0.38/syn/spanned/index.html#limitations.

@dtolnay dtolnay closed this as completed Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants