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

Implicit drops aren't rendered in async functions #17514

Open
kristof-mattei opened this issue Jun 29, 2024 · 1 comment
Open

Implicit drops aren't rendered in async functions #17514

kristof-mattei opened this issue Jun 29, 2024 · 1 comment
Labels
A-inlay-hints inlay/inline hints C-bug Category: bug

Comments

@kristof-mattei
Copy link

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
@kristof-mattei kristof-mattei added the C-bug Category: bug label Jun 29, 2024
@Veykril Veykril added the A-inlay-hints inlay/inline hints label Jun 29, 2024
@ShoyuVanilla
Copy link
Contributor

This is because Rust Analyzer isn't lowering async blocks into places when building mir

Expr::Async { .. } => not_supported!("async block"),

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

No branches or pull requests

3 participants