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

Group spans don't round-trip when run under rust-analyzer #14959

Closed
jneem opened this issue Jun 3, 2023 · 0 comments · Fixed by #14960
Closed

Group spans don't round-trip when run under rust-analyzer #14959

jneem opened this issue Jun 3, 2023 · 0 comments · Fixed by #14960
Labels
C-bug Category: bug

Comments

@jneem
Copy link
Contributor

jneem commented Jun 3, 2023

rust-analyzer version: 2023-05-29
rustc version: 1.69 (and 1.71 and 1.72 nightlies)

I originally filed this as a bug in syn, but dtolnay pointed out that the culprit is most likely rust-analyzer. (And shortly I'll post a draft PR that seems to fix this, although there are some things I'm unsure of)

I'd expect that a proc macro that does nothing but parse its input and convert it back to a token stream will be a no-op:

#[proc_macro_attribute]
pub fn foo(_args: TokenStream, input: TokenStream) -> TokenStream {
    dbg!(&input);
    let parsed_input = parse_macro_input!(input as ItemFn);
    dbg!(parsed_input.to_token_stream().into())
}

When I use this proc macro in some crate, and compile it with cargo check, it does indeed seem to round trip correctly. But when I run it with rust-analyzer diagnostics ., it does not: everything is identical between input and output except for the spans of Groups. For example, where the input has

    Group {
        delimiter: Parenthesis,
        stream: TokenStream [],
        span: 2,
    }

the output will have

   Group {
        delimiter: Parenthesis,
        stream: TokenStream [],
        span: 4294967295,
    }

I have a full example set up here

@jneem jneem added the C-bug Category: bug label Jun 3, 2023
bors added a commit that referenced this issue Jun 6, 2023
Add span to group.

This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me:

- I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](rust-lang/rust#109002), so I don't understand why it wasn't needed until now
- When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](rust-lang/rust@60e95e7). So I guess I don't really understand the relationship between the code there and the code here.
bors added a commit that referenced this issue Jun 9, 2023
Add span to group.

This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me:

- I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](rust-lang/rust#109002), so I don't understand why it wasn't needed until now
- When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](rust-lang/rust@60e95e7). So I guess I don't really understand the relationship between the code there and the code here.
bors added a commit that referenced this issue Jun 9, 2023
Add span to group.

This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me:

- I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](rust-lang/rust#109002), so I don't understand why it wasn't needed until now
- When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](rust-lang/rust@60e95e7). So I guess I don't really understand the relationship between the code there and the code here.
bors added a commit that referenced this issue Jun 10, 2023
Add span to group.

This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me:

- I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](rust-lang/rust#109002), so I don't understand why it wasn't needed until now
- When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](rust-lang/rust@60e95e7). So I guess I don't really understand the relationship between the code there and the code here.
@bors bors closed this as completed in 489eeab Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant