rust-lang / rust-lang/rust-analyzer

Invoking the dbg! macro snippet on a negated expression leaves the negation operator outside the dbg!()

Open
#11,439 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists A-completion S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Expected

Calling the postfix dbg completion on a negated expression will wrap the whole expression including the negation operator.

Observed

When the postfix dbg completion is requested, the original negation operator remains outside the freshly inserted dbg!() macro.

Repro

enum NestedStuff {
    Variants,
    Dont,
    Matter,
}

impl NestedStuff {
    fn random_method(self) -> bool {
        return true;
    }
}

fn some_func() {
    let my_enum = NestedStuff::Matter;
    if !my_enum.random_method().dbg$0 {  // choose the dbg snippet and have this line convert to 
 //`if !dbg!(my_enum.random_method()) {`
        println!("Hello");
    }
}
Version info
rustc -V
rustc 1.58.0 (02072b482 2022-01-11)

rust-analyzer --version
rust-analyzer ba3305480 2022-02-07 stable

using lsp-mode in doom emacs, if that's relevant.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the Rust example and the postfix dbg completion described in the report. Trace the completion entry point and its expression handling, then verify that a negated expression becomes !dbg!(my_enum.random_method()) rather than leaving ! outside the inserted macro.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.