Relative paths and Rust 2018 `use` statements

I’d have to think about this more carefully, but my off-the-cuff reaction is that this loses a key invariant that made name resolution tractable, which is that we always know the “full path” that is being imported.

In particular, the challenge is when you have a module like this:

use foo::bar;
...
baz!(...);

and you know that the foo crate is available, you still have to wait until you expand baz! to know whether it is going to generate a mod foo that would have shadowed foo.

Now, sometimes we handle this with a kind of “time travel violation” rule, where we go ahead and resolve to the crate but come back with an error if a module arises later that shadows – but you said that the module would take precedence, so that is harder.

That said, i’m a bit out of date on how things work, @petrochenkov may be able to weigh in on the latest tricks.

(I’d love to create a formal model of the name resolution system, as an aside, analogous to Chalk…)

7 Likes