Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

Fix hygiene of test! macro #40

Closed
wants to merge 2 commits into from

Conversation

Aaron1011
Copy link

When writing a `macro_rules! macro, any variables declared within the
right-hand side of a macro will inacessible to code expanded from a
metavariable. For example, the following code produces an error:

macro_rules! use_it {
    ($code:block) => {
        let a = "25";
        $code
    }
}

fn main() {
    use_it!({
        let b = a;
    });
}

Since 'let b = a' cannot access the 'a' variable defined within 'use_it'.

Due to a bug in the Rust compiler, this type of code was sometimes
when a proc-macro expansion occured near a macro_rules! expansion.

In this crate, the test! macro defines a local variable it, which is
then accessed from the $steps:block metavaraible.

This code will stop compiling in a future version of Rust (specifically,
once PR rust-lang/rust#77153 is merged).

I've adjusted the test! macro to take in a $it:ident metavariable,
which is used as the name of the local variable. To reduce churn, I've
made this optional - only one use of the test! macro needed to be
updated.

ChriFo and others added 2 commits September 27, 2020 12:02
When writing a `macro_rules! macro, any variables declared within the
right-hand side of a macro will inacessible to code expanded from a
metavariable. For example, the following code produces an error:

```rust
macro_rules! use_it {
    ($code:block) => {
        let a = "25";
        $code
    }
}

fn main() {
    use_it!({
        let b = a;
    });
}
```

Since 'let b = a' cannot access the 'a' variable defined within 'use_it'.

Due to a bug in the Rust compiler, this type of code was sometimes
when a proc-macro expansion occured near a `macro_rules!` expansion.

In this crate, the `test!` macro defines a local variable `it`, which is
then accessed from the `$steps:block` metavaraible.

This code will stop compiling in a future version of Rust (specifically,
once PR rust-lang/rust#77153 is merged).

I've adjusted the `test!` macro to take in a `$it:ident` metavariable,
which is used as the name of the local variable. To reduce churn, I've
made this optional - only one use of the `test!` macro needed to be
updated.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants