Revisiting Rust’s modules, part 2

Sigh, I wanted to comment on the whole post today, but didn’t have enough time again.

Regarding relative/absolute paths in imports, the problem may be potentially solved by importing from both modules. More precisely,

use a::b::c;

can be desugared into two “fused” imports

use ::a::b::c;
use self::a::b::c;

By “fused” I mean the same thing that is currently done by desugaring

use a::b::c;

into

use a::b::c::{type};
use a::b::c::{value};
use a::b::c::{macro};

I.e. the error is reported only if all imported entities are non-existent or private, but individual imports can silently fail.
I suspect this should be simpler to integrate into the current algorithm than similar alternatives like fall-back from global paths to local paths.
If this behavior is undesirable, the import can always be disambiguated by adding :: or self::.

This of course needs implementation experience, crater run, etc, but it may be a viable solution.

3 Likes