Pass value_changed
to macro_rules!
macros
#1
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.
In Rust, variable identifiers in a
macro_rules!
body are resolvedin the scope of tht body - they cannot see through to the caller's body.
For example, the following code errors:
However, due to a compiler bug (rust-lang/rust#43081),
this kind of code current compiles when a procedural macro is invoked by
a
macro_rules!
macro. Eventually, this will cause a compilation error.In the
color!
andslider!
macro, you're currently writing an expressioninvolving
value_changed
, and passing it to a procedural macro (html!
).However,
value_changed
comes from the body of the caller ofcolor!
/slider!
,so this code will stop compiling once the compiler bug is fixed.
Fortunately, the identifier of
value_changed
can be passed intocolor!
andslider!
. This modified code will with the current version ofRust, as well as future version that causes the old code into an error.
I also ran
cargo update
to bump the dependencies in your Cargo.lock.This will allow your crate to continue to compile when the compiler bug is fixed,
as you are depending on some crates (e.g.
syn
) that have released updatesto address the issue.
Feel free to ask me about any questions you may have. For more details,
see rust-lang/rust#72622