Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,30 @@ m!(define);
m!(refer);
```

And local variables has higher priority than items:

```rust
// example 1:
let f0 = || 42;
fn f0() -> i32 { 8 }

macro_rules! m0 {
() => { f0() }
}

assert_eq!(m0!(), 42);

// example 2:
fn f1() -> i32 { 8 }
let f1 = || 42;

macro_rules! m1 {
() => { f1() }
}

assert_eq!(m1!(), 42);
```

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.

Expand Down