Variable `x` is still repeating at this depth

This is the macro:

macro_rules! execute_migrations {
    ($($version:literal),+) => {{
        debug!("Migrating FICD: {}", $version); // this line says the error in the title, x being $version
        let expr = include_str!(concat!(
            "../../../resources/release/migrations/fidc_",
            $version,
            "_up.sql"
        ));
        connection.execute_batch(expr).map_err(|e| {
            OperationError::new(
                CommonExitCodes::FIDCMigrationError as i32,
                "An error occured while migrating the file id cache database.",
                Some(e),
            )
        })
    }?};
}

I have several files under resources/release/migrations directory conveniently named fidc_0001_up.sql where 0001 is the serial version of the migration.

I use rusqlite and its execute_batch method in order to run my migrations.

I intend to use this macro as below:

execute_migrations!("0001", "0002", "0003"); // and so on

It will write the compilation logic for fidc_*_up.sql files.

Is there something I don't understand with repetition in macros?


Environment

  • Rust 1.57.0 (2021 Edition)

you are trying to debug! version variable however it can only be used in a repeating context such as
$( debug!($version); )+

Solved like this:

macro_rules! execute_migrations {
    ($connection:expr, $($version:literal),+) => {
        $(
            {
                debug!("Migrating FICD: {}", $version);
                let expr = include_str!(concat!(
                    "../../../resources/release/migrations/fidc_",
                    $version,
                    "_up.sql"
                ));
                $connection.execute_batch(expr).map_err(|e| {
                    OperationError::new(
                        CommonExitCodes::FIDCMigrationError as i32,
                        "An error occured while migrating the file id cache database.",
                        Some(e),
                    )
                })
            }?;
        )+
    };
}

Thank you.

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.