Revisiting modules, take 3

Wait, that's legal? I thought I always had to import items from the super-crate.

Oh wait, you assume this is at the crate root. (It just literally took me more than a minute to realize that this is the reason the example works.) So actually this is use ::io::{Read, Write} inside bar, which indeed makes perfect sense if you buy into this "everything is an item" thing. Which I will freely admit I like :slight_smile:


As already expressed previously, I like having a grammar of paths that covers all paths, making e.g. types in other nameable for error messages or for usage without use.

However, I don't like the fact that in this proposal, use module::Type and const x: module::Type = ... do not use the same rules to resolve module::Type. That's a step backwards compared to take 2. This is exactly the "relative vs. absolute path" problem, which to me in the single most confusing part about the current module system. use and export and other places that paths occur should be uniform in how they interpret any given path.

I also do not buy the motivation for the from syntactic sugar. From a UI perspective, I would then certainly expect to also be able to write e.g. from std::io use Read, Write; (as indeed other languages do, e.g. Coq -- and also Python, I believe?). However, such sugar is entirely redundant: We already have use std::io::{Read, Write}. Curly braces are currently needless limited, but they can be made to scale much better than from. I think it is much more consistent to be able to write e.g.

use ::std::{
  io::{Read, Write},
  cmp::min,
};

or even (with the "four roots")

use extern::{
  std::io::{Read, Write},
  regex,
};

rather than using from here.

I personally do not think "use is an item" is particularly hard to learn, and indeed it is beautiful, but I am also not extremely attached to the idea. If it confuses people, I don't mind that being changed. I suppose the hope is that export sounds more like this item being also available elsewhere, which is plausible. However, writing export foo:Foo will not actually make this item available to other crates, which one might expect from a command named "export". Furthermore, I am concerned that people will think that export is mandatory to export anything, i.e., that non-export things are in fact not exported.

Also, I find the role of use and export to be somewhat confusing -- from what I understand, export is (the new version of) use + being an item? IOW, export is like the current use (well, with changes to what paths are)? I expect the question "when do I use, when do I export, and what is even the difference between the two" will be a very common one.

1 Like