pre-RFC: inline mod


@aturon has collected a bunch of data


It’s my understanding that items which want to be reexported for use outside the crate would be tagged with pub and ones for use in the crate would be pub(crate) or pub(super), which means that the example isn’t flawed, it just needs to take advantage of some other features which were recently added.

@petrochenkov provided feedback about how to specify this to avoid defining it as a textual replacement (I never wanted it to be actual textual replacement, for what it’s worth. The point of the pre-RFC is to improve on the idea through feedback). I’ll be updated the text to reflect those changes.

Using the word inline is purely a bikeshed discussion. I’m not tied to the word used in any way, but unless you have a concrete suggesting, just saying that inline is confusing isn’t as helpful.

And the only goal of this RFC is to make the facade pattern more usable.


Forgive me for my naivity, but why can’t we just solve this with a plain old macro that does the desugaring? Something like

inline! {
    mod foo;
    mod bar;

that would desugar like the proposed way.


Because the macro cannot know what’s inside of foo and bar. macro_rules! macros can only reorder/rewrite tokens. You need at least proc_macros for this (see the former post), but even that does not work atm.


The rewrite in question would just add pub use ident::*; for each mod ident;. Why does that need to know about what is inside?


Actually … true. I always had the picture in my mind that inline would work transitively and flatten the submodules’ hierarchy. But that’s not what has been proposed.


I’d probably prefer #[facade] and that’s already documented as an alternative in the RFC, but then again, I don’t understand macros well enough to know how to implement that currently.


I tried to implement an experimental prototype which can be found in the facade_attr repo. It would be nice to know if it works as intended by the pre-RFC. I implemented an optional pseudo hiding of the annotated module based on name mangling.

I also discovered something interesting which I did not know before: Before the macro handler is invoked the submodule which is referenced by mod submodule is fully inlined by the compiler, i.e., it is transformed to mod submodule { ... content of ... }. So the macro handle can access all of the contents of the submodule.


Won’t this invite more usage of (or be equivalent to) use ...::*, which hurdles finding where a symbol goes from when not using IDE?

I expect * to be avoided in production code just like from ... import * avoided in Python.