Skip to content

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

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

Closed
kennethuil opened this issue Jun 2, 2022 · 12 comments
Closed

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

kennethuil opened this issue Jun 2, 2022 · 12 comments
Labels
A-macro macro expansion C-bug Category: bug

Comments

@kennethuil
Copy link

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(())
}
@bjorn3
Copy link
Member

bjorn3 commented Jun 2, 2022

What is your rust-analyzer configuration? Do you have rust-analyzer.procMacro.enable set to true? (should be by default)

@kennethuil
Copy link
Author

"Proc Macro: Enable" is checked (in VSCode). So is "Proc Macro > Attributes: Enable". "Proc Macro: Ignored" is empty. settings.json has no settings overrides in it.

@bjorn3 bjorn3 added A-macro macro expansion C-bug Category: bug labels Jun 2, 2022
@flodiebold
Copy link
Member

The tokio::main macro implementation in tokio-macros has #[cfg(not(test))] on it. Probably adding tokio-macros to rust-analyzer.cargo.unsetTest will help, I haven't tried it yet though.

@kennethuil
Copy link
Author

kennethuil commented Jun 7, 2022

{
    "rust-analyzer.cargo.unsetTest": [
        "core",
        "tokio-macros",
        "tokio_macros"
    ]
}

did not have any effect on the flagged error.

@flodiebold
Copy link
Member

Adding both "tokio" and "tokio-macros" (with the -) does it, because the reexport in tokio is again cfg(test).

@flodiebold
Copy link
Member

Fixed by #12599

@paulkre
Copy link

paulkre commented Jul 6, 2022

When is this fix going to be released?

@bjorn3
Copy link
Member

bjorn3 commented Jul 6, 2022

It should already have been released. Every monday there is a new stable release.

@anistark
Copy link

Still getting this on VS Code.

@asllop
Copy link

asllop commented Feb 16, 2023

Still getting this on VS Code.

Try updating rust, it resolved the problem for me: rustup update

@wtto00
Copy link

wtto00 commented Oct 18, 2023

I still encountered this error, and I ignore it in VS Code:

"rust-analyzer.diagnostics.disabled": ["unresolved-proc-macro"]

@dtantsur
Copy link

dtantsur commented Oct 28, 2023

Yeah, I still see it rust.vim too. Just updated rust and rust-analyzer to 1.73.

UPD: fingers crossed, but I think cargo clean fixed that for me.

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

No branches or pull requests

8 participants