-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GAT & TAIT with lifetime type parameters fail std::marker::Sized
requirement
#89008
Comments
This gives a different error. Minimized: #![feature(type_alias_impl_trait)]
#![feature(generic_associated_types)]
use std::future::Future;
use std::marker::PhantomData;
pub trait Stream {
type Item;
}
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 { Empty { _phantom: PhantomData } }
}
}
pub struct Empty<T> {
_phantom: PhantomData<T>,
}
impl<T> Stream for Empty<T> {
type Item = T;
}
fn main() {}
|
GATs issue triage: not blocking. Seems like a TAITs bug; not sure there's anything for GATs to change here. |
Compiles just fine now. |
@jackh726 I guess this issue can just be closed if there's a test already? |
I think test needs to be moved to correct place? |
Hello, first time contributing to rust. I was trying to resolve this issue and after looking at the test I am a little confused. To me it looks like the test code is failing correctly and I can't understand where the TAIT bug is. rust/src/test/ui/generic-associated-types/bugs/issue-89008.rs Lines 1 to 43 in ebdde35
rust/src/test/ui/generic-associated-types/bugs/issue-89008.stderr Lines 1 to 15 in ebdde35
Changing the impl<T> Stream for Empty<T> {
type Item = T;
} makes the code compile. I am sorry if I am missing something here. If the test is correct then would moving the test to I also don't think #88908 relates to this test. |
Yeah, I messed up my minimization. The test should just use the original MCVE in the OP. And that is indeed fixed. |
For clarity: this can be closed when the current known-bug test is moved to the main directory for GAT tests and changed to use the OP MCVE. |
…h726 Replaced wrong test with the correct mcve Closes rust-lang#89008. The old test was wrong and the compiler was [correctly raising an error](rust-lang#89008 (comment)). The bug in the issue was resolved at some point but due to the wrong test the issue was never closed. This pr replaces that test with the correct MCVE (made by `@jackh726).` The error raised by the bug changed between when the bug was posted (2021-09-08) and when the MCVE [was posted](rust-lang#89008 (comment)) (2021-10-23). I ran them both through `nightly-2021-09-08` and they produce identical error messages. They also produce identical but different from before error messages when ran through `nightly-2021-10-23`. <details> <summary>Error message with <code>nightly-2021-09-08</code></summary> The code with the original bug report: ``` 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 `test-234234` due to previous error ``` MVCE: ``` error[E0277]: the size for values of type `Repr` cannot be known at compilation time --> src/main.rs:30:43 | 30 | 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 `test-234234` due to previous error ``` </details> <details> <summary>Error message with <code>nightly-2021-10-23</code></summary> The code with the original bug report: ``` error[E0271]: type mismatch resolving `<impl futures::Future as futures::Future>::Output == impl futures::Stream` --> src/main.rs:23:43 | 19 | type LineStream<'a, Repr> = impl Stream<Item = Repr>; | ------------------------ the expected opaque type ... 23 | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found struct `futures::stream::Empty` | = note: expected opaque type `impl futures::Stream` found struct `futures::stream::Empty<_>` error: could not find defining uses --> src/main.rs:19:33 | 19 | type LineStream<'a, Repr> = impl Stream<Item = Repr>; | ^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0271`. error: could not compile `test-234234` due to 2 previous errors ``` MCVE: ``` error[E0271]: type mismatch resolving `<impl Future as Future>::Output == impl Stream` --> src/main.rs:30:43 | 28 | type LineStream<'a, Repr> = impl Stream<Item = Repr>; | ------------------------ the expected opaque type 29 | type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>>; 30 | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found struct `Empty` | = note: expected opaque type `impl Stream` found struct `Empty<_>` error: could not find defining uses --> src/main.rs:28:33 | 28 | type LineStream<'a, Repr> = impl Stream<Item = Repr>; | ^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0271`. error: could not compile `test-234234` due to 2 previous errors ``` </details>
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):
In contrast, the following code, without lifetime type parameters compiles without any error.
Meta
cargo version --verbose
:The text was updated successfully, but these errors were encountered: