pre-RFC: inline mod

@aturon has collected a bunch of data

1 Like

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.

1 Like

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.

2 Likes

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?

3 Likes

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 submodule.rs ... }. So the macro handle can access all of the contents of the submodule.

3 Likes

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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.