You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
101arrowz opened this issue
May 29, 2022
· 3 comments
Labels
A-GATsArea: Generic associated types (GATs)C-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.
Here's some code with generic associated types and impl Trait:
#![feature(generic_associated_types)]use std::future::{Future, ready,Ready};pubtraitExample{typeValue<'a>:Future<Output = &'a str>whereSelf:'a;fnexample(&mutself) -> Self::Value<'_>;}pubstructExImpl<'a>(&'a str);implExampleforExImpl<'_>{typeValue<'a> = Ready<&'a str>whereSelf:'a;fnexample(&mutself) -> Self::Value<'_>{ready(self.0)}}asyncfncallee(mutex:implExample){// Note that if you don't use a separate function, no errors appeardbg!(ex.example().await);}#[tokio::main]asyncfnmain(){
tokio::spawn(asyncmove{let ex = ExImpl("hello");callee(ex).await;});}
Compiling playground v0.0.1 (/playground)
error[[E0477]]: the type `ExImpl<'_>` does not fulfill the required lifetime
--> src/main.rs:24:5
|
24 | tokio::spawn(async move {
| ^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0477`.
error: could not compile `playground` due to previous error
Clearly ExImpl("hello") has a static lifetime and yet borrowck still complains that the lifetime isn't static. Interestingly, if we inline the contents of callee (i.e. never write impl Example) there are no issues.
This is also a diagnostic issue: not only is the error in the wrong place, it doesn't provide any suggestions to fix and doesn't point out what lifetime ex actually needs.
error[E0477]: the type `&Struct` does not fulfill the required lifetime
--> src/lib.rs:16:8
|
16 | fn method<F>(&self, f: F)
| ^^^^^^
For more information about this error, try `rustc --explain E0477`.
This is at least a diagnostics issue, since it doesn't say which lifetime "the required lifetime" is.
Removing the where Self: 'a bound fixes the reduced test case, but I think I needed it in the original.
A-GATsArea: Generic associated types (GATs)C-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.
Here's some code with generic associated types and
impl Trait
:Playground
Expected:
ex.example().await = "hello"
Current behavior:
Clearly
ExImpl("hello")
has a static lifetime and yet borrowck still complains that the lifetime isn't static. Interestingly, if we inline the contents ofcallee
(i.e. never writeimpl Example
) there are no issues.This is also a diagnostic issue: not only is the error in the wrong place, it doesn't provide any suggestions to fix and doesn't point out what lifetime
ex
actually needs.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: