Skip to content

RA thinks that a called #[tokio::main] function returns a Future #12450

Closed
@kennethuil

Description

@kennethuil

rust-analyzer version: f94fa62 2022-05-30 stable

rustc version: rustc 1.60.0 (7737e0b5c 2022-04-04)

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

Cargo.toml:

[package]
name = "ra-issue"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.18", features = ["rt", "rt-multi-thread", "net", "macros"] }

main.rs:

use std::error::Error;

fn main() {
    // do_something_async is a non-async function that blocks on the tokio runtime
    // It returns a plain Result
    // Rust Analyzer thinks do_something_async returns a Future and puts a red squiggle here
    // but it compiles without errors
    let x: Result<_,_> = do_something_async();
    println!("async result is {:?}",x);
}

#[tokio::main]
async fn do_something_async() -> Result<(), Box<dyn Error + Send + Sync>> {
    println!("async stuff goes here...");
    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions