Hi rustceans!

I have an idea that’d be pretty useful for several cases (some of them are my unimplemented ideas). Do any of you consider this valuable? Please let me know and help me design this feature!

Summary

Allow defining an associated type that doesn’t have other name besides Type::Associated .

An example will make it more obvious:

impl Foo for Bar { type Baz = struct { some_field: String }; type Enum = enum { Variant0, Variant1 }; }

Since there doesn’t exist a name without Foo:: prefix, one must access these types using Foo::Baz and Foo::Enum . This avoids conflict. In case two traits with same name of associated type are in scope, one can use <Foo as Bar>::Baz to disambiguate - this is also recommended way to do it in generated code. The type is still first-class, so you can do with it whatever you can with other types - including reexporting it via use Foo::Bar as Alias; or type Alias = Foo::Bar;

Rationale

This change allows one to namespace types using names of other types. This is particularly useful when auto-generating code using custom derive or other mechanism. Without this change, the type name must be somehow generated, risking conflicts with other types.

Alternatives