Skip to content

procedural macro + anyhow macro causes type-mismatch: expected Result<{unknown}, Error>, found () #12184

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
ivan opened this issue May 7, 2022 · 9 comments
Labels
A-macro macro expansion A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@ivan
Copy link
Contributor

ivan commented May 7, 2022

Rust nightly accepts this code, but rust-analyzer is confused by the combination of a procedural macro (futures_async_stream::try_stream) and an anyhow macro:

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

[dependencies]
anyhow = "1.0"
futures = "0.3"
futures-async-stream = "0.2"
#![feature(
    generators,
    proc_macro_hygiene,
    stmt_expr_attributes,
)]

use anyhow::{Error, bail};
use futures::stream::BoxStream;
use futures_async_stream::try_stream;

fn minimized_try_stream() -> BoxStream<'static, Result<String, Error>> {
    Box::pin(
        #[try_stream]
        async move {
            if false {
                bail!("bye");
            }
        }
    )
}

fn main() {
    let _ = minimized_try_stream();
}

(if true does the same.)

(also available at https://github.com/ludios/ra-proc-macro-type-issue)

expected Result<{unknown}, Error>, found () rust-analyzer(type-mismatch)

Screenshot 2022-05-07 001109

rust-analyzer version: 1f709d5 2022-05-05 nightly

rustc version: rustc 1.62.0-nightly (30f386087 2022-05-05)

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

@ivan
Copy link
Contributor Author

ivan commented May 7, 2022

I have found this workaround from #11815 useful:

    "rust-analyzer.diagnostics.disabled": [
        "type-mismatch"
    ],

update: now

    "rust-analyzer.diagnostics.disabled": [
        "E0308"
    ],

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution A-macro macro expansion C-bug Category: bug labels May 7, 2022
@cynecx
Copy link
Contributor

cynecx commented May 7, 2022

The attr proc-macro doesn't get expanded at all, that's what's causing the type mismatch.

@Veykril
Copy link
Member

Veykril commented May 7, 2022

Ye, we only support attributes on items currently

@flodiebold
Copy link
Member

Right, I don't think we expand attribute macros on expressions.

@gautamg795
Copy link

Rather than globally disabling the type-mismatch diagnostic, is there any sort of marker that can be placed inline at the point of macro usage to ignore this diagnostic?

@flodiebold
Copy link
Member

No, there isn't.

@gautamg795
Copy link

Is there any plan (i.e. a GitHub issue I could follow) for expanding attribute macros on expressions? Or any other suggestions that wouldn't require globally disabling the often-useful diagnostic?

@flodiebold
Copy link
Member

#12558

@Veykril
Copy link
Member

Veykril commented Dec 13, 2023

Closing as duplicate of the above issue

@Veykril Veykril closed this as completed Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

5 participants