Macros in nested modules?

Hello! I was attempting to make a toy OS per https://os.phil-opp.com/ and was cleaning up some of the modules. Now, through this I ran into the issue of with nested modules, one cannot import macros through the interface.

I created a test for this in a playground and I found that indeed one cannot import these macros.

So I guess my question goes twofold.

  1. Why does this not work?
  2. Are there any workarounds?

Macros have lexical scope (they don't exist before they appear in the source). You need to move the modules up to before the macro is used. Also, #[macro_export] is just for exporting macros from a crate.

1 Like

Thank you so much this fixed it right up.