What is "curious inner-module" hack?

While reading this, I came across this concept :crying_cat_face: , I couldn't find a single normal description, can anyone tell me something?

I'm not sure, but from this description:

We introduce a special macro metavar $crate which expands to ::foo when a macro was imported through crate ident foo, and to nothing when it was defined in the crate where it is being expanded. $crate::bar::baz will be an absolute path either way.

I'm guessing the hack was something like having a root module with the same name as your crate, so ::foo written in the macro would refer to that module when used within the crate, while that same ::foo referred to the crate itself when used from outside.

Also, 2018 edition changed the meaning of such paths:
https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html#the-crate-keyword-refers-to-the-current-crate

The prefix :: previously referred to either the crate root or an external crate; it now unambiguously refers to an external crate. For instance, ::foo::bar always refers to the name bar inside the external crate foo.

3 Likes

Thank you!!!, I didn't even think about it, that's the only explanation

example from old version of std :

the usage of underline function of println! macro (also reexported from mod std):

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.