Compile error with my macro in unit test


This is should be simple enough for me to fix on my own, but I am having a mental block figuring out why my unit tests code cannot compile because my custom macro cannot be found.

here’s my project structure:

├── Cargo.toml
├── src
│   ├──
│   ├── processors
│   │   ├──
│   │   ├──
│   │   └──
│   └── utils
│       ├──
│       ├──
│       ├──
│       ├──
│       ├──
│       └──

in file utils\ I have a macro like this:

macro_rules! string {
    ($s: expr) => {

I also modified, utils\ to include module

#[macro_use] pub mod macros;

I have a test mod in file processors\, like this:

mod process_for_individual_test_results_tests {

    use super::ProcessIndividualTestResults;
    #[macro_use] use utils::macros;
    fn small_failures_section_success(){
        let mut lines: Vec<String> = Vec::new();
        lines.push(string!("        failures:"));


and when I run my tests I get this compile error:

error: cannot find macro `string!` in this scope
   --> src/processors/
162 |         lines.push(string!("        failures:"));
    |                    ^^^^^^
    = help: have you added the `#[macro_use]` on the module/import?

Any ideas what I am missing?



#[macro_use] doesn’t work on use. (huh, that should probably produce better diagnostics: I opened an issue)

#[macro_use] can only be used on extern crate name; and mod name;. Furthermore, these items must be declared in the right order, so that anything that defines macros comes before the stuff that uses them.


// wrong
mod processors;

mod utils;

// correct
mod utils;

mod processors;


Wow. That is it. I did not realize the order mattered one bit. Thank you.