rust-lang / rust-lang/rust-analyzer

Implicit drops aren't rendered in `async` functions

Open
#17,514 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-inlay-hints C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer version: 0.3.2011-standalone [/home/kristof/.vscode-server/extensions/rust-lang.rust-analyzer-0.3.2011-linux-x64/server/rust-analyzer]

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: VSCode v1.90.2 (user setup) / Rust Analyzer extension: v0.3.2011

relevant settings: "rust-analyzer.inlayHints.implicitDrops.enable": true,

repository link (if public, optional): https://github.com/kristof-mattei/async-no-implicit-drop.git

code snippet to reproduce:

#[tokio::main]
async fn main() {
    println!("Start: async_test");
    async_test().await;
    println!("End: async_test");
    println!();
    println!();
    println!("Start: non_async_test");
    non_async_test();
    println!("End: non_async_test");
}

#[allow(clippy::unused_async)]
async fn async_test() {
    {
        let drop_test = DropTest::new("async_test".into());

        drop_test.do_something();
    }
}

fn non_async_test() {
    {
        let drop_test = DropTest::new("non_async_test".into());

        drop_test.do_something();
    }
}

struct DropTest {
    from: String,
}

impl DropTest {
    fn new(from: String) -> Self {
        Self { from }
    }

    #[allow(clippy::unused_self)]
    fn do_something(&self) {
        println!("From: {}", self.from);
    }
}

impl Drop for DropTest {
    fn drop(&mut self) {
        println!("Dropped: {}", self.from);
    }
}

When enabling implicitDrops, they aren't rendered in async functions. Note that having a Drop function doesn't change the whether drop(drop_test) is rendered or not, I just put it there to prove that it was actually dropped.

Screenshot from Repo above in VSCode:

image

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

Start with the provided async_test and non_async_test reproduction and the rust-analyzer.inlayHints.implicitDrops.enable setting. Trace how implicit-drop inlay hints are computed for async functions, then verify that the async and non-async examples render consistent hints while preserving the observed drop behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.