You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Rust, variable identifiers in a `macro_rules!` body are resolved
in the scope of tht body - they cannot see through to the caller's body.
For example, the following code errors:
```rust
macro_rules! weird_ident {
() => { my_ident; }
}
fn main() {
let my_ident = 1;
weird_ident!();
}
```
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 `visit_number!` macro, you're currently writing an expression
involving `visitor`, and passing it to a procedural macro (`paste!`).
However, `visitor` comes from the body of the caller of `visit_number!`,
so this code will stop compiling once the compiler bug is fixed.
Fortunately, the identifier of `visitor` can be passed into
`visit_number!`. This modified code will with the current version of
Rust, as well as future version that causes the old code into an error.
Feel free to ask me about any questions you may have. For more details,
see rust-lang/rust#72622
0 commit comments