Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn block into a closure in test macro #1

Closed
wants to merge 1 commit into from

Conversation

Aaron1011
Copy link

The doc_test! macro defines two local variables (entries and doc),
which are then accessed from the provided block.

However, this only compiled due to a bug in rustc: substituted
metavariables cannot refer to names defined within the macro body. For
example, the following ode does not compile:

macro_rules! foo {
    ($block:expr) => {
        let mut bar = false;
        $block
    }
}

fn main() {
    foo!({bar = true});
}

In this case, the doc_test! macro was incorrectly allowed to compile
due to the presence of the #[tokio::test] macro on the enclosing
function. When the underlying compiler bug is fixed in
rust-lang/rust#75800,
this macro will stop compiling.

I've adjusted the macro to take in a closure instead of a block. This
closure is invoked with the entries and doc variables, allowing it
to compile with both old and new compilers.

If you have any questions about this change, feel free to ask me.

The `doc_test!` macro defines two local variables (`entries` and `doc`),
which are then accessed from the provided `block`.

However, this only compiled due to a bug in rustc: substituted
metavariables cannot refer to names defined within the macro body. For
example, the following ode does not compile:

```rust
macro_rules! foo {
    ($block:expr) => {
        let mut bar = false;
        $block
    }
}

fn main() {
    foo!({bar = true});
}
```

In this case, the `doc_test!` macro was incorrectly allowed to compile
due to the presence of the `#[tokio::test]` macro on the enclosing
function. When the underlying compiler bug is fixed in
rust-lang/rust#75800,
this macro will stop compiling.

I've adjusted the macro to take in a closure instead of a block. This
closure is invoked with the `entries` and `doc` variables, allowing it
to compile with both old and new compilers.

If you have any questions about this change, feel free to ask me.
@bartlomieju
Copy link
Owner

@Aaron1011 thanks for the PR, would you mind opening it in https://github.com/denoland/deno_doc?

@Aaron1011
Copy link
Author

@bartlomieju: I've opened denoland#27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants