Vscode rust extension summon wrong command when test name is 'gen'

I wrote a test named 'gen' in Rust, and when I ran the test, I found that it was filtered out. After capturing the command, I found that it had added the characters "r#" before "gen". Testing with other names does not work, it can run normally.
My environment is ArchLinux 6.10.2-arch1-1.
wrong command:

I think it is a lsp issue.

cargo test --package Temp --bin Temp -- r#gen --exact --show-output

The bug works on my Windows 11 machine too.

That if your test function name is gen, it'll be

/path/to/cargo.exe test --package hello --bin hello -- r#gen --exact --show-output

or else it'll be

/path/to/cargo.exe test --package hello --bin hello -- other_name --exact --show-output

the difference is the extra r#, more than likely it's another bug from ra lol.

r# is the syntax for raw identifiers, which you use if you want your identifier to be a keyword in Rust. For example a variable or field named type is not possible as type is a keyword in Rust. Instead, you'd use the raw identifier r#type instead. That being said, I have no idea why this is happening in your case, gen is not a keyword in Rust and it is also strange to find it in the CLI.[1]

Testing locally I found out that cargo test can handle the other way around, i.e. match a function with a raw identifier to a query without it. For example, having a test

#[test]
fn r#match() {
    assert!(true);
}

is run with cargo test -- match or cargo test -- r#match. But a test

#[test]
fn gen() {
    assert!(true);
}

is not run with cargo test -- r#gen (as you've already deduced).


Edit: seems like gen will be a keyword in the 2024 edition. Looks like your IDE setup already treats it like a keyword, even though in earlier editions it is not yet one.


  1. See the edit I made below. ↩ī¸Ž

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.