Allow "constructing" type aliases?


Basically, for type Foo = i32 implicitly create a function fn Foo(x: i32) -> i32 { x }, as if it was a newtype.

This would allow:

  • making the intent clearer in some cases where using newtypes is cumbersome, e.g. when working with a library that doesn’t use a newtype
  • future-proofing for when you maybe are moving toward a newtype

I’m not particularly convinced this is a good idea (therefore no pre-RFC), but just had the idea and wanted to throw it out there in case it has some merit.



I’m pretty sure that’d be a breaking change, since this code, while bad style, is currently legal:

type Foo = i32;
fn Foo() -> Foo { 4 }

closed #3

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