RFC 0532: self-in-use

lang (syntax | resolve)

Summary

This RFC proposes the mod keyword used to refer the immediate parent namespace in use items (use a::b::{mod, c}) to be changed to self.

Motivation

While this looks fine:

use a::b::{mod, c};

pub mod a {
    pub mod b {
        pub type c = ();
    }
}

This looks strange, since we are not really importing a module:

use Foo::{mod, Bar, Baz};

enum Foo { Bar, Baz }

RFC #168 was written when there was no namespaced enum, therefore the choice of the keyword was suboptimal.

Detailed design

This RFC simply proposes to use self in place of mod. This should amount to one line change to the parser, possibly with a renaming of relevant AST node (PathListMod).

Drawbacks

self is already used to denote a relative path in the use item. While they can be clearly distinguished (any use of self proposed in this RFC will appear inside braces), this can cause some confusion to beginners.

Alternatives

Don't do this. Simply accept that mod also acts as a general term for namespaces.

Allow enum to be used in place of mod when the parent item is enum. This clearly expresses the intent and it doesn't reuse self. However, this is not very future-proof for several reasons.

Unresolved questions

None.