Skip to content

Macro expansion: concat!() macro with single quotes escapes special characters while rustc does not #12921

Closed
@azerupi

Description

@azerupi

rust-analyzer version: rust-analyzer version: 0.3.1148-standalone (2b472f6 2022-07-31)

rustc version: rustc 1.60.0 (7737e0b5c 2022-04-04) and rustc 1.62.0-nightly (90ca44752 2022-04-11)

We discovered an inconsistency between rust-analyzer's expansion of concat! and rustc when using single quotes. So '\n' gets expanded to "\'\\n\'" instead of "\n". And '\0' gets expanded to \'\\0\' instead of \u{0}.

Examples to reproduce

Source code

fn main() {
    let s = concat!("Hello, World!", '\n');
}

rust-analyzer

fn main() {
    let s = "Hello, World!\'\\n\'";
}

cargo-expand

fn main() {
    let s = "Hello, World!\n";
}

Source code

fn main() {
    let s = concat!("Hello, World!", '\0');
}

rust-analyzer

fn main() {
    let s = "Hello, World!\'\\0\'";
}

cargo-expand

fn main() {
    let s = "Hello, World!\u{0}";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-bugCategory: bugS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions