Make associated types Sized by default


Currently this program:

trait A {
    type T;
    fn foo(&self) -> <Self as A>::T;
    fn bar(&self) -> <Self as A>::T { }
fn main() {}

Fails to compile as: 5:49 error: cannot move a value of type T: the size of T cannot be statically determined [E0161]     fn bar(&self) -> <Self as A>::T { }

According to RFC 59 we should be able to fix it by (currently unimplemented)

trait A {
    type T : Sized;


  1. Shouldn’t associated types be Sized by default? As associated types are to be used to replace “output” type parameters, it is more convenient to be Sized.

  2. If associated types are Sized by default, what should be the syntax then if we want to allow unsized associated types? The generic spelling currently suggests something like

     type Sized? T;

Good catch – can you please file this as an issue on the github rust repository?


Thanks. Filed as

closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.