[rust-dev] Exporting macros: #[macro_escape] usage

Vladimir Matveev dpx.infinity at gmail.com
Sat Jan 11 00:15:39 PST 2014


Oh, thanks. It does work now. Are macro scoping rules documented
somewhere except the compiler source code?

2014/1/11 Chris Morgan <chris.morganiser at gmail.com>:
> The macro is being defined after the module is defined. You need to move the
> macro definition before the "pub mod submod;" line. Also due to the scoping
> rules of macros, you don't need #[macro_escape] there---it's a child, so it
> gets the macro. Only siblings, parents, uncles, aunts, cousins, &c. would
> need it.
>
> On Jan 11, 2014 9:46 AM, "Vladimir Matveev" <dpx.infinity at gmail.com> wrote:
>>
>> Hi,
>>
>> As far as I understand, the current way to export macros is to
>> annotate the module with macro_rules definition with #[macro_escape]
>> annotation. But I just can't get it right, and my macro is not visible
>> in other module :(
>>
>> Here is what I have:
>>
>> ----- START -----
>> /lib.rs:
>> #[feature(macro_rules)];
>>
>> pub mod m1;
>>
>> --
>> /m1/mod.rs:
>> #[macro_escape];
>>
>> pub mod submod;
>>
>> macro_rules! example_rule(
>>     () => (mod test;)
>> )
>>
>> --
>> /m1/submod.rs:
>> use m1;
>>
>> example_rule!()
>> ----- END -----
>>
>> I have assumed that putting #[macro_escape] annotation to a module
>> makes all macros from that module available in all modules which
>> import this module, but apparently I'm wrong because the code above
>> does not work with 'macro undefined' error.
>>
>> Could please someone explain how #[macro_escape] works in detail? I
>> couldn't find any documentation on it, and looking through standard
>> libs was not helpful.
>>
>> Thanks,
>> Vladimir.
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev at mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev


More information about the Rust-dev mailing list