Skip to content

proc_macro_attribute literals are tokenized as errors #16233

Closed
@eidloi

Description

@eidloi

rust-analyzer version: v0.3.1791 (stable), v0.4.1793 (Pre-release)

rustc version: rustc 1.74.1 (a28077b28 2023-12-04)

relevant settings: n/a

Imagine a macro in the format of:

#[simple_interaction_for("test")]
struct Test {
    pub test: &'static str,
}

Where the macro implementation is printing the attribute tokens for simplicity:

#[proc_macro_attribute]
pub fn simple_interaction_for(attr: TokenStream, item: TokenStream) -> TokenStream {
    eprintln!("input: {:#?}", attr);
 
    item
}

Expected output:

This is from cargo expand, it generates the expected output and the project builds without errors.

input: TokenStream [
    Literal {
        kind: Str,
        symbol: "test",
        suffix: None,
        span: #0 bytes(159..165),
    },
]

Actual output:

Printed in the Output of VSCode (Rust Analyzer Language Server)

input: TokenStream [
    Literal {
        kind: Err,
        symbol: "\"test\"",
        suffix: None,
        span: 16,
    },
]

The same happens with other literals as well.

Note:

Weirdly enough initially it worked correctly on a few tries (just changing the literal in the annotation prints it again and again), but then got into the error state and never recovered. Re-installing the plugin or switching to the pre-release version didn't help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions