Skip to content

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

Closed
@ivan

Description

@ivan

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionA-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions