Disclaimer: this is not a proposal to change, rust, not even at the edition boundary. That's just me writing down some thoughts I've just had
Surprisingly, one of the most complex aspects of rust to support in an IDE is a module and import system. The crux of the problem is that, in IDE, you want to skip over as much code as possible, and, ideally, should be able to run name resolution on a single file without looking much into other files.
The ideal case here is Java: every file starts with a package directive, so each top-level item gets an unambiguous fully-qualifed name, and it is possible to compute the set of FQNs, contributed by a single file, by looking just at this file.
The Rust is just the opposite of that to get the set of items declared in a crate, you more or less have to process all crate's files and modules simultaneously.
The rust module system is more convenient for the user, for the following reasons:
- modules are tree-shape, and not flat
- fine-grained visibility is also tree-shaped
- reexports allow for building nice façades
The core bit that hurts here is that combination of glob-imports and reexports makes different modules depend on each other in a difficult to disentangle ways. A nice change here which might simplify things, without hurting expressiveness/ergonomics much is
First, to make palin use
items into usual imports, which don't declare new items themselves.
Second, ban *
from pub use
items (which still act as-if redeclaring item at the given position).
With this setup, you mostly know the set of names that can be exported from module by just looking at the module's file.
Mostly, because macros can also declare top-level items, and you need expand them to figure this out... This might very well break, so some additional restrictions for top-level macros might be needed. Maybe it's just banning imports of top-level macros via *
? I don't know
Another thing which would help is an ability to build a module tree without expanding macros. An interesting (and probably ergonomic) way to achieve that is to require that module structure is fully inferred from the file system layout.