Turn block into a closure in test macro #27
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
doc_test!macro defines two local variables (entriesanddoc),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:
In this case, the
doc_test!macro was incorrectly allowed to compiledue to the presence of the
#[tokio::test]macro on the enclosingfunction. 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
entriesanddocvariables, allowing itto compile with both old and new compilers.
If you have any questions about this change, feel free to ask me.