generated from rust-lang/initiative-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
bugSomething isn't workingSomething isn't working
Description
When using
rustc 1.86.0-nightly (419b3e2d3 2025-01-15)
What I tried to do
Return an impl Trait
with an associated type and rely on the leakage of auto traits like Send
and Sync
on the associated type.
Simplified example:
trait Inner {}
trait Outer {
type I: Inner;
fn get_inner(&self) -> Self::I;
}
impl Inner for () {}
impl Outer for () {
type I = ();
fn get_inner(&self) -> Self::I {
()
}
}
fn outer1() -> impl Outer {
()
}
fn outer2() -> impl Outer<I = impl Inner> {
()
}
fn requires_send(_: impl Send) {}
fn main() {
// uncommenting the following does not compile!
// requires_send(outer1().get_inner());
// this does compile!
requires_send(outer2().get_inner());
}
What happened
The version using outer2
compiles fine and does the leakage, while the version with outer1
does not leak and therefore the associated type does not implement Send
.
What I expected
I would have expected that both versions behave the same with regards to auto trait leakage. Maybe this is intended behavior, but it was surprising to me and I also couldn't find any documentation about this behavior.
PS: I first posted this on the user forum: https://users.rust-lang.org/t/impl-trait-return-value-with-associated-type-that-should-be-send-sync/124089 where it got suggested that I post an issue here.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working