summaryrefslogtreecommitdiffstats
path: root/tests/ui/macros/meta-variable-misuse.rs
blob: 99a2f940176bd12ded58a02e99c257c7e5edbf05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// run-pass
#![deny(meta_variable_misuse)]

macro_rules! foo {
    ($($m:ident $($f:ident $v:tt)+),*) => {
        $($(macro_rules! $f { () => { $v } })+)*
        $(macro_rules! $m { () => { $(fn $f() -> i32 { $v })+ } })*
    }
}

foo!(m a 1 b 2, n c 3);
m!();
n!();

macro_rules! no_shadow {
    ($x:tt) => { macro_rules! bar { ($x:tt) => { 42 }; } };
}
no_shadow!(z);

macro_rules! make_plus {
    ($n: ident $x:expr) => { macro_rules! $n { ($y:expr) => { $x + $y }; } };
}
make_plus!(add3 3);

fn main() {
    assert_eq!(a!(), 1);
    assert_eq!(b!(), 2);
    assert_eq!(c!(), 3);
    assert_eq!(a(), 1);
    assert_eq!(b(), 2);
    assert_eq!(c(), 3);
    assert_eq!(bar!(z:tt), 42);
    assert_eq!(add3!(9), 12);
}