Skip to content

regression on nightly-2024-03-16 #122618

Open
@xxchan

Description

@xxchan

Code

I tried this code:

[dependencies]
futures = "0.3.30"
futures-async-stream = "0.2.10"
#![feature(coroutines)]
#![feature(impl_trait_in_assoc_type)]
use futures::Stream;
use futures_async_stream::try_stream;
use std::future::Future;
pub trait IterItem: Send + 'static {
    type ItemRef<'a>: Send + 'a;
}

type StorageError = ();
type StorageResult<T> = Result<T, StorageError>;

pub trait StateStoreIter<T: IterItem>: Send {
    fn try_next(
        &mut self,
    ) -> impl Future<Output = StorageResult<Option<T::ItemRef<'_>>>> + Send + '_;
}

#[try_stream(ok = O, error = StorageError)]
async fn into_stream_inner<
    T: IterItem,
    I: StateStoreIter<T>,
    O: Send,
    F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send,
>(
    mut iter: I,
    f: F,
) {
    while let Some(item) = iter.try_next().await? {
        yield f(item)?;
    }
}

pub trait StateStoreIterExt<T: IterItem>: StateStoreIter<T> + Sized {
    type ItemStream<O: Send, F: Send>: Stream<Item = StorageResult<O>> + Send;

    fn into_stream<O: Send, F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send>(
        self,
        f: F,
    ) -> Self::ItemStream<O, F>;
}

impl<T: IterItem, I: StateStoreIter<T>> StateStoreIterExt<T> for I {
    type ItemStream<O: Send, F: Send> = impl Stream<Item = StorageResult<O>> + Send;

    fn into_stream<O: Send, F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send>(
        self,
        f: F,
    ) -> Self::ItemStream<O, F> {
        into_stream_inner(self, f)
    }
}

fn main() {
    println!("Hello, world!");
}

Version it worked on

It compiles on nightly-2024-03-14

Version with regression

ICE on nightly-2024-03-15 #122508

Compile error on nightly-2024-03-16:

error[E0277]: expected a `Fn(<T as IterItem>::ItemRef<'a>)` closure, found `F`
  --> src/main.rs:50:9
   |
50 |         into_stream_inner(self, f)
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn(<T as IterItem>::ItemRef<'a>)` closure, found `F`
   |
note: required by a bound in `into_stream_inner`
  --> src/main.rs:24:8
   |
20 | async fn into_stream_inner<
   |          ----------------- required by a bound in this function
...
24 |     F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `into_stream_inner`
help: consider further restricting this bound
   |
44 |     type ItemStream<O: Send, F: Send + for<'a> std::ops::Fn<(<T as IterItem>::ItemRef<'a>,)>> = impl Stream<Item = StorageResult<O>> + Send;
   |                                      +++++++++++++++++++++++++++++++++++++++++++++++++++++++

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesC-bugCategory: This is a bug.F-coroutines`#![feature(coroutines)]`F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]`P-mediumMedium priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions