How to make `include!` Work with macros defined in external mailboxes?

When using serde in a stable state, as recommended by the corresponding post blog , you will need to use the built-in macro include! to pull out the file created by serde-codegen .

The file indicated here shows this in a more complex example, which can use rustc night, as well as rustc stable.

However, as the include documents suggest include! He does not behave hygienically.

What this means was not clear to me until I ran into the problem that the macros defined in the external box, yup-hyper-mock , were not detected at the included time. Some tests showed that even something like extern crate foo-bar-snoo-snoo; will not cause an error in the on time, indicating that it has not yet been evaluated at all.

The problem arises from include! trying to expand macros, and fails if they come from external mailboxes that have not yet been evaluated.

My attempt to define empty macros with the correct signature will result in the include! will work, but compilation will fail later, since include! will actually expand the macro immediately, which was empty during include.

Is there any way to do include! work with macros defined in external mailboxes? Alternatively, can you imagine a workaround to do my specific work case?

Personally, I think include! should not expand the macros at all, but leave it to the next compilation step, which the external mailboxes should contribute - maybe we are looking at an error in rustc , but I'm not sure about that.

How to play

Please note that both stable and nightly compilers show the same problems.

 git clone --branch syntex https://github.com/Byron/yup-oauth2 cd yup-oauth2 git reset --hard f59d97d # build and test fail because 'include!' runs before crates are pulled # in, but still expands macros cargo build cargo test 

Meta h1>

is stable

 yup-oauth2 git:(syntex) rustc --version --verbose rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14) binary: rustc commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e commit-date: 2015-05-13 build-date: 2015-05-14 host: x86_64-apple-darwin release: 1.0.0 

nightly

 yup-oauth2 git:(syntex) rustc --version --verbose rustc 1.2.0-nightly (2228ce10c 2015-06-09) binary: rustc commit-hash: 2228ce10c6d83c17b6346396aa7c7ef9082f1c04 commit-date: 2015-06-09 host: x86_64-apple-darwin release: 1.2.0-nightly 
+7
rust
source share

No one has answered this question yet.

See related questions:

17
Using $ crate in Rust procedural macros?
5
How to use a macro that is defined by another macro in the same box?
2
Access to external boxes from the module
2
How to pass an entire box to a procedural macro?
one
Confused about the external box
one
How to use a macro defined in another box?
0
Is it possible to override a function defined in an external box?
0
Rust cannot find an external box for an external box
0
Defining AdditiveGroup with an Algae Box
0
Unauthorized import when calling a macro defined in an external box

All Articles