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

Macro error with futures::try_join! #6835

Closed
lnicola opened this issue Dec 11, 2020 · 34 comments
Closed

Macro error with futures::try_join! #6835

lnicola opened this issue Dec 11, 2020 · 34 comments
Labels
A-macro macro expansion C-bug Category: bug S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@lnicola
Copy link
Member

lnicola commented Dec 11, 2020

Same as @jeromegn , I am still getting the error on the nightly version of rust-analyzer, in my case in a call to futures::try_join!.

Originally posted by @Victor-Savu in #6716 (comment)

@lnicola lnicola added the A-macro macro expansion label Dec 11, 2020
@peku33
Copy link

peku33 commented Dec 11, 2020

Same here.
This affect all futures macros, like select, join etc.

@edwin0cheng
Copy link
Member

Maybe related to #6811

@flodiebold
Copy link
Member

@Victor-Savu @peku33 Please check this again with the next nightly or current master.

@Victor-Savu
Copy link

Victor-Savu commented Dec 16, 2020

Unfortunately I can still reproduce the problem. Here is a minimal reproduction:

Extension version: 0.3.418-nightly

cargo.toml:

[package]
name = "rust-analyzer-error"
version = "0.1.0"
edition = "2018"

[dependencies]
tokio = { version = "0.2", features = ["macros"] }
futures = "0.3"

main.rs:

#[tokio::main]
async fn main() {
    futures::join!(
        async {
            println!("Hello, world!");
        },
        async {
            println!("Hello, world!");
        }
    );
}

I used join! instead of try_join! to keep the example as short as possible but the error is the similar:

could not resolve macro $crate::join_internal

@flodiebold
Copy link
Member

join_internal seems to be a proc_macro_hack macro; that's probably the problem.

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Dec 20, 2020
@peku33
Copy link

peku33 commented Jan 5, 2021

So this is a problem with rust-analyzer or futures?
At the moment one of the most popular crates with 3M recent downloads (futures) triggers this error for basic usage.

@flodiebold
Copy link
Member

Any error that rust-analyzer produces in code that compiles is a problem in rust-analyzer.

You can disable the diagnostic by adding macro-error to the rust-analyzer.diagnostics.disabled setting.

@lnicola
Copy link
Member Author

lnicola commented Jan 8, 2021

Triage: this still happens even after #7145.

@lnicola
Copy link
Member Author

lnicola commented Jan 8, 2021

Ah, it's a proc_macro_hack thing.

@lnicola lnicola added S-unactionable Issue requires feedback, design decisions or is blocked on other work and removed S-actionable Someone could pick this issue up and work on it right now labels Jan 8, 2021
lambdalisue added a commit to lambdalisue/dotfiles that referenced this issue Feb 19, 2021
@bionicles
Copy link

still getting this, any easy way to disable it temporarily?

@Victor-Savu
Copy link

@bionicles if you are using VSCode, create a file .vscode/settings.json at the root of your project folder containing:

{
    "rust-analyzer.diagnostics.disabled": [
        "macro-error"
    ]
}

@lolgeny
Copy link

lolgeny commented Apr 7, 2021

It's annoying that with futures::join, with this, rust-analyser can't infer types for the output. Is there any hacky fix to get that working?

@mountainfloating
Copy link

@bionicles if you are using VSCode, create a file .vscode/settings.json at the root of your project folder containing:

{
    "rust-analyzer.diagnostics.disabled": [
        "macro-error"
    ]
}

Doesn't work for me with futures::select!. Any other way i can disable this?

@jonas-schievink
Copy link
Contributor

The diagnostic is now called unresolved-macro-call

@Diggsey
Copy link

Diggsey commented Apr 21, 2021

This also occurs with Yew's html! macro.

@KyGost
Copy link

KyGost commented Apr 25, 2021

This occurs with fstrings's macros (seemably all?).
Disabling unresolved-macro-call provided a good temporary fix! Thanks.

@Ciantic
Copy link

Ciantic commented May 2, 2021

If the problem is proc_macro_hack, then I think futures needs to be just updated? I created an issue in futures ( rust-lang/futures-rs#2406 ) repo to remove the proc_macro_hack. After all the proc_macro_hack repo says:

Proc_macro_hack Note: As of Rust 1.45 this crate is superseded by native support for #[proc_macro] in expression position. Only consider using this crate if you care about supporting compilers between 1.31 and 1.45.

@Ciantic
Copy link

Ciantic commented May 5, 2021

It's now fixed in the futures package! try_join! and select! works now with the futures git repo.

I think this can be closed, though futures is not released yet, it will start to work in futures 0.4 and rust 1.45

@jonas-schievink
Copy link
Contributor

I'd rather keep it open. It will probably take years until the ecosystem uses futures 0.4

@taiki-e
Copy link
Member

taiki-e commented May 6, 2021

I will backport that patch to 0.3, so no need to wait for futures 0.4. (See the label of the PR that fixed the issue)

@taiki-e
Copy link
Member

taiki-e commented May 20, 2021

Released futures 0.3.15 which includes the fix for this issue.

@regexident
Copy link
Contributor

I recently started getting the same error with log's macros, such as log::debug!(…) on v0.2.599, for what it's worth.

Should I open a separate issue or is this reasonably related?

@jonas-schievink
Copy link
Contributor

Doesn't sound like the same issue

@neor164
Copy link

neor164 commented Oct 23, 2021

I've just ran into this issue recently with pyo3.
you can try it yourself with pyo3 numpy example project: https://github.com/PyO3/rust-numpy/tree/main/examples/simple-extension.

@m1ten
Copy link

m1ten commented Oct 25, 2021

I've just ran into this issue recently with pyo3.

I am experiencing the same thing, for now I just disabled rust-analyzer.procMacro.enable.

@sebaslopez01
Copy link

I've just ran into this issue recently with pyo3. you can try it yourself with pyo3 numpy example project: https://github.com/PyO3/rust-numpy/tree/main/examples/simple-extension.

Me too, I am also disabling it.

@Jason5Lee
Copy link

I got the problem in ifmt.

@aleokdev
Copy link

aleokdev commented Dec 29, 2021

I've ran into this issue with tokio::select! and the thiserror crate Error derive. Says it has entered into unreachable code.

@lnicola
Copy link
Member Author

lnicola commented Dec 30, 2021

@alexdevteam thiserror used to work. Which compiler version are you using, and can you prepare a small test case?

@ModProg
Copy link
Contributor

ModProg commented May 29, 2022

Got this error with serde_with::flattened_maybe as well, trying to resolve $crate::serde::Deserialize

@flodiebold flodiebold added the C-bug Category: bug label Jun 20, 2022
@huntc
Copy link

huntc commented Jun 21, 2022

In my particular case, I was getting the problem with Yew's macros. Other macros from other libraries like Embassy seemed to work.

To work-around my issue, my settings.json looks like:

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

@nerdai
Copy link

nerdai commented Jun 21, 2022

This also worked for me, but I was using a VS Workspace, for which settings.json is modified by opening the workspaces' code-workspace rather than adding a .vscode folder in the root dir of your code.

@gmelodie
Copy link

gmelodie commented Feb 7, 2023

In my particular case, I was getting the problem with Yew's macros. Other macros from other libraries like Embassy seemed to work.

To work-around my issue, my settings.json looks like:

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

For anyone using CoC with neovim:

  1. open nvim
  2. :CocConfig (it'll open CoC's config file)
  3. paste the above into this file
  4. Save and reopen nvim

@Veykril
Copy link
Member

Veykril commented Aug 29, 2023

I'll close this issue, a lot of comments in here are about very different issues making it difficult to figure out what the problem even is at this point. So we gain more from people opening new specific issues instead.

@Veykril Veykril closed this as completed Aug 29, 2023
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 S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests