[rust-dev] name resolution rule for enum variants?

Patrick Walton pcwalton at mozilla.com
Sat Jul 5 13:44:19 PDT 2014


On 7/5/14 1:43 PM, Phil Dawes wrote:
> Hello!
>
> I was surprised to find the following compile and run without any bother:
>
> #[deriving(Show)]
> pub enum MyEnum {
>      Path
> }
> fn main() {
>      let p = Path::new("/filepath/");
>      let p2 = Path;
>
>      println!("{}",p.as_str());
>      println!("{}",p2);
> }
>
> % ./run
> Some(/filepath)
> Path
>
> What is the name resolution rule that stops MyEnum's Path overriding the
> posix Path struct? I'm interested because racer gets this wrong at the
> moment.

Rust has two namespaces: a type namespace and a value namespace. 
(Modules are in the type namespace.) Structs are in the type namespace 
and enum variants are in the value namespace.

Patrick



More information about the Rust-dev mailing list