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

return inside async blocks hints impl Future<Output = !> #17106

Open
janos-r opened this issue Apr 19, 2024 · 1 comment · May be fixed by #17174
Open

return inside async blocks hints impl Future<Output = !> #17106

janos-r opened this issue Apr 19, 2024 · 1 comment · May be fixed by #17174
Assignees
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@janos-r
Copy link

janos-r commented Apr 19, 2024

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
VSC: rust-analyzer version: 0.3.1924-standalone
rust-analyzer --version: rust-analyzer 1.77.0 (aedd173 2024-03-17)

rustc version: (eg. output of rustc -V)
rustc 1.77.0 (aedd173a2 2024-03-17)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
both VSCodium

Version: 1.87.2
Release: 24072
Commit: f7ed6417a7cfae92f98129384c13b505bb9cfc53
Date: 2024-03-12T18:30:28.994Z
Electron: 27.3.2
ElectronBuildId: undefined
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Linux x64 5.15.0-102-generic

and helix 24.3 (2cadec0b)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

#[allow(unused_variables)]
#[tokio::main]
async fn main() {
    // indicates impl Future<Output = i32>
    let a1 = async { 8 };
    let a2 = async {
        return 8; // indicates a impl Future<Output = !>
    };
    let a3 = async {
        loop {
            return 8;
        } // suddenly fine impl Future<Output = i32>
    };

    let t1 = tokio::spawn(async {
        return 8; // indicates a JoinHandle<!>
    });
    let t2 = tokio::task::spawn_blocking(|| {
        return 8; // this is as expected JoinHandle<i32>
    });
}

Despite hintng Future<Output = !> and JoinHandle<!> the futures actually return correctly the value. Just the hint is incorrect.
Btw I am not a fan of writing explicitly return within async blocks, but if the compiler supports it, the hints should be correct as well.

scrnshot with hints:
image

@janos-r janos-r added the C-bug Category: bug label Apr 19, 2024
@Veykril Veykril added the A-ty type system / type inference / traits / method resolution label Apr 19, 2024
@Kohei316
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants