Closed
Description
Following code is not accepted ATM (play):
pub trait A {}
pub struct B {
a: Box<dyn A>,
}
impl B {
pub async fn new(a: Box<dyn A>, x: &(), y: &()) -> B {
B { a }
}
}
Error:
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> src/main.rs:10:56
|
10 | pub async fn new(a: Box<dyn A>, x: &(), y: &()) -> B {
| ^
|
note: hidden type `impl std::future::Future` captures the scope of call-site for function at 10:58
--> src/main.rs:10:58
|
10 | pub async fn new(a: Box<dyn A>, x: &(), y: &()) -> B {
| __________________________________________________________^
11 | | B { a }
12 | | }
| |_____^
However, the following code is accepted:
pub trait A {}
pub struct B<A> {
a: A,
}
impl<X: A> B<X> {
pub async fn new(a: X, x: &(), y: &()) -> B<X> {
B { a }
}
}
I know one can workaround this by using impl trait
with explicit lifetimes, but this is an ergonomics issue.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done