Skip to content

Commit c299ce4

Browse files
committed
local variables has higher priority than item
1 parent 3279c0e commit c299ce4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/macros-by-example.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,30 @@ m!(define);
439439
m!(refer);
440440
```
441441

442+
And local variables has higher priority than items:
443+
444+
```rust
445+
// example 1:
446+
let f0 = || 42;
447+
fn f0() -> i32 { 8 }
448+
449+
macro_rules! m0 {
450+
() => { f0() }
451+
}
452+
453+
assert_eq!(m0!(), 42);
454+
455+
// example 2:
456+
fn f1() -> i32 { 8 }
457+
let f1 = || 42;
458+
459+
macro_rules! m1 {
460+
() => { f1() }
461+
}
462+
463+
assert_eq!(m1!(), 42);
464+
```
465+
442466
r[macro.decl.hygiene.crate]
443467
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.
444468

0 commit comments

Comments
 (0)