While auto trait impls of impl Trait types leak, the auto trait impls of their associated types do not:
#![feature(conservative_impl_trait)]
trait Foo {
type Bar;
}
fn require_bar_send<F>(_: F) where F: Foo, F::Bar: Send {}
fn foo() -> impl Foo {
struct Fooey;
impl Foo for Fooey {
type Bar = ();
}
Fooey
}
fn main() {
require_bar_send(foo()); // ERROR
}
This can be fixed by writing impl Foo<Bar=impl Send>, but this can get annoying quickly: async traits, whose methods each return a separate associated type implementing Future, need to have a Bar=impl Send for each method:
trait Foo {
type FooFut: Future<...>;
fn foo(&self) -> Self::FooFut;
type BarFut: Future<...>;
fn bar(&self) -> Self::BarFut;
type BazFut: Future<...>;
fn baz(&self) -> Self::BazFut;
}
fn foo() -> impl Foo<FooFut=impl Send, BarFut=impl Send, BazFut=impl Send> { ... }
This isn't a bug, but I'm interested in seeing if there're ways we can improve here-- should associated type auto traits leak? I can see that becoming a huge problem since you'd then want the associated types of associated types auto traits to leak, etc, but there's not an obvious solution to me. I really just want an "everything you care about here is thread-safe" button, but I don't know how to supply that easily.
While auto trait impls of
impl Traittypes leak, the auto trait impls of their associated types do not:This can be fixed by writing
impl Foo<Bar=impl Send>, but this can get annoying quickly: async traits, whose methods each return a separate associated type implementingFuture, need to have aBar=impl Sendfor each method:This isn't a bug, but I'm interested in seeing if there're ways we can improve here-- should associated type auto traits leak? I can see that becoming a huge problem since you'd then want the associated types of associated types auto traits to leak, etc, but there's not an obvious solution to me. I really just want an "everything you care about here is thread-safe" button, but I don't know how to supply that easily.