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

Phil Dawes rustphil at phildawes.net
Sat Jul 5 14:06:16 PDT 2014


Thanks Patrick, that makes sense.

I need to think about how to code this into Racer. Can I assume that
anything preceding a :: in a path is from the type namespace?

(Is there somewhere other than the rustc source where I should be reading
about this?)

Thanks,

Phil



On Sat, Jul 5, 2014 at 9:44 PM, Patrick Walton <pcwalton at mozilla.com> wrote:

> 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
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140705/aaf88481/attachment.html>


More information about the Rust-dev mailing list