regression on nightly-2024-03-16
Open
Nobody has claimed this yet.
A-coroutines
C-bug
F-coroutines
F-impl_trait_in_assoc_type
P-medium
regression-untriaged
S-has-mcve
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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 https://github.com/rust-lang/rust/issues/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;
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied Rust example with futures 0.3.30 and futures-async-stream 0.2.10 on nightly-2024-03-14, nightly-2024-03-15, and nightly-2024-03-16, noting the ICE and subsequent E0277 error. Read the related issue #122508 and investigate the compiler regression affecting the bounds at src/main.rs:50; done means the example compiles again on the affected nightly without regressing the earlier behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100