Skip to content

Commit

Permalink
Fix broken links and Add a hack example before $$ occurs
Browse files Browse the repository at this point in the history
The hack example comes from rust-lang/rust#95860.
  • Loading branch information
zjp-CN authored and Veykril committed Apr 22, 2022
1 parent 244cd8e commit b077c4a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/decl-macros/minutiae/metavar-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This chapter will introduce them more in-depth together with usage examples.

- [`$$`](#dollar-dollar-)
- [`${count(ident, depth)}`](#countident-depth)
- [`${index(depth)}`](#index-depth)
- [`${length(depth)}`](#length-depth)
- [`${ignore(ident)}`](#ignore-ident)
- [`${index(depth)}`](#indexdepth)
- [`${length(depth)}`](#lengthdepth)
- [`${ignore(ident)}`](#ignoreident)

## Dollar Dollar (`$$`)

Expand All @@ -36,7 +36,7 @@ foo!();
```

The problem is obvious, the transcriber of foo sees a repetition and tries to repeat it when transcribing, but there is no `$any` metavariable in its scope causing it to fail.
With `$$` we can get around this as the transcriber of `foo` will no longer try to do the repetition.
With `$$` we can get around this as the transcriber of `foo` will no longer try to do the repetition.[^tt-$]

```rust
#![feature(macro_metavar_expr)]
Expand All @@ -54,6 +54,9 @@ bar!();
# fn main() {}
```

[^tt-$]: Before `$$` occurs, users must resort to a tricky and not so well-known hack to declare nested macros with repetitions
[via using `$tt` like this](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9ce18fc79ce17c77d20e74f3c46ee13c).

## `count(ident, depth)`

The `count` metavariable expression expands to the repetition count of the metavariable `$ident` at the given repetition depth.
Expand Down

0 comments on commit b077c4a

Please sign in to comment.