You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/macros-by-example.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -439,6 +439,30 @@ m!(define);
439
439
m!(refer);
440
440
```
441
441
442
+
And local variables has higher priority than items:
443
+
444
+
```rust
445
+
// example 1:
446
+
letf0=||42;
447
+
fnf0() ->i32 { 8 }
448
+
449
+
macro_rules!m0 {
450
+
() => { f0() }
451
+
}
452
+
453
+
assert_eq!(m0!(), 42);
454
+
455
+
// example 2:
456
+
fnf1() ->i32 { 8 }
457
+
letf1=||42;
458
+
459
+
macro_rules!m1 {
460
+
() => { f1() }
461
+
}
462
+
463
+
assert_eq!(m1!(), 42);
464
+
```
465
+
442
466
r[macro.decl.hygiene.crate]
443
467
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.
0 commit comments