Rust type/values namespace status


Rust currently uses separate namespaces for types and values which allows some funny patterns, like “real constructors”.

But looks like this feature is completely undocumented. So what’s the status of this? Is this a part of the language definition, or an implementation detail which can be changed in the future?

And are there any relevant docs besides source code of librustc_resovle?


There are 4 namespaces actually! In addition to types and values, lifetimes have their own namespace. Loop labels technically use value namespace in the compiler, but they don’t intersect neither with values nor with lifetimes.

And there will be one more namespace soon, for macros. I’d say everything in this area is pretty stable and part of the language, except maybe the interaction between lifetimes and labels.[quote=“matklad, post:1, topic:3734”] And are there any relevant docs besides source code of librustc_resovle? [/quote]

Maybe or (note that both are not accepted at the moment), maybe some old RFCs.


So when I use foo::Bar; do I get the import for both namespaces? Is there any way to import just for one specific namespace?


You get the import for both, and you can’t pick only one.


In fact you can import something into only the type namespace using type Bar=foo::Bar;. This results in some interesting (read: confusing) behavior:


If you’re interested in some of the nitty-gritty around namespaces, RFC 1560 specifies some of the interesting behviour (although it is not the main part of the RFC).

To answer the OP, it is a stable part of the language and will not change in a backwards incompatible way (though there may be backwards compatible changes, such as adding the macro namespace). I’m not aware of any documentation specifically on this topic (other than the above RFC).

1 Like
closed #7

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