Skip to content

Commit

Permalink
Prepare PR #1656 to be merged
Browse files Browse the repository at this point in the history
  • Loading branch information
traviscross committed Oct 22, 2024
1 parent d062154 commit 11ef502
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ by other crates, either by path or by `#[macro_use]` as described above.
r[macro.decl.hygiene]

r[macro.decl.hygiene.intro]

Macros by example have _mixed-site hygiene_. It means that [loop labels], [block labels] and local variables are looked up at the macro definition site, and other symbols are looked up at the macro invocation site. For example:
Macros by example have _mixed-site hygiene_. This means that [loop labels], [block labels], and local variables are looked up at the macro definition site while other symbols are looked up at the macro invocation site. For example:

```rust
let x = 1;
Expand All @@ -427,7 +426,7 @@ fn func() {

macro_rules! check {
() => {
assert_eq!(x, 1); // Uses `x` from the declaration site.
assert_eq!(x, 1); // Uses `x` from the definition site.
func(); // Uses `func` from the invocation site.
};
}
Expand All @@ -441,7 +440,7 @@ macro_rules! check {

Labels and local variables defined in macro expansion are not shared between invocations, so this code doesn’t compile:

```rust,compile_fail
```rust,compile_fail,E0425
macro_rules! m {
(define) => {
let x = 1;
Expand All @@ -456,7 +455,6 @@ m!(refer);
```

r[macro.decl.hygiene.crate]

A special case is the `$crate` metavariable. It refers to the crate defining the macro, and can be used at the start of the path to look up items or macros which are not in scope at the invocation site.

<!-- ignore: requires external crates -->
Expand Down

0 comments on commit 11ef502

Please sign in to comment.