Allow dropping dyn Trait principal by Jules-Bertholet · Pull Request #126660 · rust-lang/rust (original) (raw)

Redux of #114679, fixes #126313

This allows the following examples to compile:

trait Trait: Send {} fn foo(x: &dyn Trait) -> &dyn Send { x }

trait Trait {} fn foo(x: &(dyn Trait + Send)) -> &dyn Send { x }

This makes the language more consistent, as we already allow:

trait Trait {} fn foo(x: &(dyn Trait + Send)) -> &dyn Trait { x }

The PR includes a test case, in tests/ui/traits/dyn-drop-principal.rs.

Documentation

dyn upcasting coercions, of any kind, are currently entirely undocumented in the reference. A future reference PR should address this.

@rustbot label T-lang T-types needs-fcp A-coercions A-trait-objects