Skip to content

Commit

Permalink
Improving macro expansion section (rust-lang#1875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur-Milchior authored Jan 29, 2024
1 parent 48fc9c1 commit e73ca04
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/macro-expansion.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,8 @@ macro_rules! foo { () => { println!(); } }
fn main() { foo!(); }
```

In this code, the AST nodes that are finally generated would have hierarchy:

```
root
expn_id_foo
expn_id_println
```
In this code, the AST nodes that are finally generated would have hierarchy
`root -> id(foo) -> id(println)`.

### The Macro Definition Hierarchy

Expand Down Expand Up @@ -397,8 +392,9 @@ macro foo($i: ident) { $i }
foo!(bar!(baz));
```

For the `baz` AST node in the final output, the first hierarchy is `ROOT ->
id(foo) -> id(bar) -> baz`, while the third hierarchy is `ROOT -> baz`.
For the `baz` AST node in the final output, the expansion-order hierarchy is
`ROOT -> id(foo) -> id(bar) -> baz`, while the call-site hierarchy is `ROOT ->
baz`.

### Macro Backtraces

Expand Down

0 comments on commit e73ca04

Please sign in to comment.