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

Using postfix snippets on expressions containing '\\' results in it getting unescaped #11897

Closed
liquidev opened this issue Apr 4, 2022 · 2 comments · Fixed by #12646
Closed
Labels
A-completion autocompletion C-bug Category: bug

Comments

@liquidev
Copy link

liquidev commented Apr 4, 2022

rust-analyzer version: 2022-03-28

rustc version: rustc 1.61.0-nightly (c5cf08d37 2022-03-30)

Example:

fn main() {
  let x = '\\'.ok|
}

(where | is the cursor)
Accepting the suggestion will result in this code:

fn main() {
  let x = Ok('\')|
}

which is invalid syntax.

It also seems that this happens with strings. Other escapes are intact, it's only \\ that gets mangled.

Also of note is that the escape may be nested in some deeper expression. For instance:

match x {
  true => '\\',
  false => 'a',
}.ok|
@Veykril Veykril added A-completion autocompletion C-bug Category: bug labels Apr 4, 2022
@Jesse-Bakker
Copy link
Contributor

This is caused by the fact that \, $ and } are special tokens in a snippet, which should be escaped. RA returns these in the postfix completion snippet unescaped, causing them to disappear.

@logistic-bot
Copy link

This also happens in this situation, using rust-analyzer 46d7ee68f 2022-04-04 stable:

enum Test {
    Item1,
    Item2,
}

fn main() {
    let t = Test::Item2;

    match t {
        Test::Item1 => println!("\""),
    }
}

with the caret on the end of match t, and applying the suggestion fill match arms, results in the following code:

    match t {
        Test::Item1 => println!("""),
        Test::Item2 => todo!(),
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants