Skip to content

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

Closed
@jneem

Description

@jneem

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions