Related modules should be grouped into a single module, which means that global paths should be rarely used. Using relative paths makes refactoring (e.g. renaming or moving modules around) easier. Global paths by default also causes a lot of confusion, and the language reference does not even clearly explain the default behavior of (non-prefixed) paths.
Therefore, I think that using global paths as the default is a bad idea. Global paths should be explicitly marked as global, but I am not sure about the best way to mark them. I am also not sure whether local paths should be explicitly marked. Paths referring to use declarations should remain unlabeled, since the use declarations already make the intention explicit.
There are two ways I know that global paths could be explicitly marked.
- My original proposal: Prefix every global path with
crate::, and deprecate the usage of the current
::prefix. This makes things explicit (probably the rust way), and makes the behavior guessable to anybody.
@P1start’s suggestion: Retain the current
::prefix, but make it mandatory. This mirrors the unix file system with
There are three ways to deal with local paths.
- My original proposal: Prefix every local path with the
self::prefix. This is the most explicit way. However, there are problems when referring to types and functions in the same module.
- My tweak: Prefix local paths for items in submodules with the
self::prefix, while making
self::optional for types and functions in the same module.
@P1start’s suggestion: Do not prefix local paths with anything (making them the default). This is the simplest way to do this, although more implicit. (The
self::prefix might also be deprecated)
Original post: I would like to propose using “crate::” for global (crate-level) paths, and deprecate paths not beginning with “super”, “self”, or “crate” unless a use declaration was used (also deprecate paths beginning with “::”). This would clear up some confusion for many people.
Also note that the reference seems to be unclear about behavior of paths that don’t begin with “super”, “self”, or “::”. http://doc.rust-lang.org/reference.html#paths