External Publication
Visit Post

Pre-RFC: &[T: Trait] -> &dyn [Trait]

Rust Internals [Unofficial] April 21, 2026
Source

I suppose the generic parameter would need to be similar to a lifetime, used solely to constrain that two dyn trait objects use the same type, without any introspection as to what that type is. (Otherwise, different types could act differently, and you’d need monomorphization.) That being the case, as you say, using the same syntax as generic type parameters seems like a bad idea, since it can’t actually be a generic type parameter. I think even the : Trait part seems less than ideal.

Maybe introduce the parameter as dyn T or something, and have the corresponding trait objects be called dyn<T> MyTrait, dyn<T> OtherTrait? Is it important that only trait objects of the same type be unified?

Bikeshedding the name, regardless of syntax: I think “generic dyn parameter” sounds good.

Discussion in the ATmosphere

Loading comments...