Skip to content

Turn block into a closure in test macro#1

Closed
Aaron1011 wants to merge 1 commit into
bartlomieju:mainfrom
Aaron1011:fix/block-entries-doc
Closed

Turn block into a closure in test macro#1
Aaron1011 wants to merge 1 commit into
bartlomieju:mainfrom
Aaron1011:fix/block-entries-doc

Conversation

@Aaron1011
Copy link
Copy Markdown

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
Copy Markdown
Owner

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

@Aaron1011
Copy link
Copy Markdown
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