Closed
Description
Playing around with (the not yet stable) GAT and TAIT features I stumbled over the below problem, where type parameters to nested TAIT/GAT with lifetime parameters cause a "this type parameter needs to be std::marker::Sized" compiler error.
The following code fails to compile with below compiler error (Playground):
#![feature(type_alias_impl_trait)]
#![feature(generic_associated_types)]
extern crate futures;
use futures::Stream;
use std::future::Future;
trait X {
type LineStream<'a, Repr>: Stream<Item = Repr> where Self: 'a;
type LineStreamFut<'a,Repr>: Future<Output = Self::LineStream<'a, Repr>> where Self: 'a;
fn line_stream<'a,Repr>(&'a self) -> Self::LineStreamFut<'a,Repr>;
}
struct Y;
impl X for Y {
type LineStream<'a, Repr> = impl Stream<Item = Repr>;
type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>> ;
fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
async {futures::stream::empty()}
}
}
fn main() {}
warning: the cargo feature `edition2021` has been stabilized in the 1.56 release and is no longer necessary to be listed in the manifest
See https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-edition-field for more information about using this feature.
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `Repr` cannot be known at compilation time
--> src/main.rs:23:43
|
23 | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| this type parameter needs to be `std::marker::Sized`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error
In contrast, the following code, without lifetime type parameters compiles without any error.
#![feature(type_alias_impl_trait)]
#![feature(generic_associated_types)]
extern crate futures;
use futures::Stream;
use std::future::Future;
trait X {
type LineStream<Repr>: Stream<Item = Repr>;
type LineStreamFut<Repr>: Future<Output = Self::LineStream<Repr>>;
fn line_stream<Repr>(&self) -> Self::LineStreamFut<Repr>;
}
struct Y;
impl X for Y {
type LineStream<Repr> = impl Stream<Item = Repr>;
type LineStreamFut<Repr> = impl Future<Output = Self::LineStream<Repr>> ;
fn line_stream<Repr>(&self) -> Self::LineStreamFut<Repr> {
async {futures::stream::empty()}
}
}
fn main() {}
Meta
cargo version --verbose
:
cargo 1.56.0-nightly (e515c3277 2021-09-08)
release: 1.56.0
commit-hash: e515c3277bf0681bfc79a9e763861bfe26bb05db
commit-date: 2021-09-08
Metadata
Metadata
Assignees
Labels
Area: Generic associated types (GATs)Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(generic_associated_types)]` a.k.a. GATs`#[feature(type_alias_impl_trait)]`Issues using the `generic_associated_types` feature that have been triagedStatus: This bug is tracked inside the repo by a `known-bug` test.
Type
Projects
Status
Done