Parsing Traces with Opaque Errors in Rust

Viewed 39

How does one read and understand Rust traces with Opaque errors?

Example Error

For example, consider the following typically long error. How do you infer the problem from the error output?

error[E0599]: the method `next` exists for struct `Pin<&mut impl futures::Future<Output = AsyncStream<Result<u32, Box<dyn StdError>>, Opaque(DefId(0:51 ~ armadillo_rust[2000]::query_all::{opaque#0}::{opaque#0}), ['_#6r])>>>`, but its trait bounds were not satisfied
   --> src/main.rs:198:31
    |
198 |     while let Some(x) = ticks.next().await {
    |                               ^^^^ method cannot be called on `Pin<&mut impl futures::Future<Output = AsyncStream<Result<u32, Box<dyn StdError>>, Opaque(DefId(0:51 ~ armadillo_rust[2000]::query_all::{opaque#0}::{opaque#0}), ['_#6r])>>>` due to unsatisfied trait bounds
    |
   ::: ../toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:408:1
    |
408 | pub struct Pin<P> {
    | -----------------
    | |
    | doesn't satisfy `_: StreamExt`
    | doesn't satisfy `_: futures::Stream`
    |
    = note: the following trait bounds were not satisfied:
            `Pin<&mut impl futures::Future<Output = AsyncStream<Result<u32, Box<dyn StdError>>, Opaque(DefId(0:51 ~ armadillo_rust[2000]::query_all::{opaque#0}::{opaque#0}), ['_#6r])>>>: futures::Stream`
            which is required by `Pin<&mut impl futures::Future<Output = AsyncStream<Result<u32, Box<dyn StdError>>, Opaque(DefId(0:51 ~ armadillo_rust[2000]::query_all::{opaque#0}::{opaque#0}), ['_#6r])>>>: StreamExt`
            `impl futures::Future<Output = AsyncStream<Result<u32, Box<dyn StdError>>, Opaque(DefId(0:51 ~ armadillo_rust[2000]::query_all::{opaque#0}::{opaque#0}), ['_#6r])>>: futures::Stream`
            which is required by `impl futures::Future<Output = AsyncStream<Result<u32, Box<dyn StdError>>, Opaque(DefId(0:51 ~ armadillo_rust[2000]::query_all::{opaque#0}::{opaque#0}), ['_#6r])>>: StreamExt`

Minimal, Working Example:

use futures::StreamExt;
use async_stream::AsyncStream;

async fn query_all<'a>(date: &'a str) -> AsyncStream<Result<u32, Box<dyn std::error::Error + 'a>>, impl futures::Future + 'a> {
    todo!();
}

#[tokio::main]
async fn main() {
    let ticks = query_all("2022-06-14");
    futures::pin_mut!(ticks);
    while let Some(x) = ticks.next().await {
        println!("{:?}", x);
    }
}

Naive Solution

The error seems to be saying two things:

  1. A pinned stream doesn't satisfy necessary bounds
  2. The return type of query_all fails to implement certain traits.

However, confusingly, the exact same types work in this minimal example:

#[tokio::main]
async fn main() {
    let ticks = stream! {
        yield Ok(0);
        yield Err("");
    };
    futures::pin_mut!(ticks);
    while let Some(x) = ticks.next().await {
        println!("{:?}", x);
    }
}

How am I misreading this and what is Rust really trying to say?

0 Answers
Related