rust
rust copied to clipboard
Allow dropping `dyn Trait` principal
trafficstars
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