rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.4k stars 12.59k forks source link

`trait Trait: Send`: upcasting from `dyn Trait` to `dyn Send` does not work #126313

Open lcnr opened 3 months ago

lcnr commented 3 months ago

The following compiles:

#![feature(trait_upcasting)]
trait Super {}
trait Trait: Super {}
fn foo(x: &dyn Trait) -> &dyn Super { x }

while this does not:

#![feature(trait_upcasting)]
trait Super {}
trait Trait: Send {}
fn foo(x: &dyn Trait) -> &dyn Send { x }

cc @compiler-errors I thought we actually had a PR for that at some point :thinking: I think that's actually not the case though. It wasn't part of #119338

compiler-errors commented 3 months ago

I had a separate PR to upcast dropping the principal but I think I never FCPd it because I was too lazy: https://github.com/rust-lang/rust/pull/114679#issuecomment-1904644704