about summary refs log tree commit diff
path: root/tests/ui/macros/metavar-expressions/usage-errors.rs
blob: feff02e2ce4709b6f2e8b7af77147f3e6909085c (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Errors for the `count` and `length` metavariable expressions

#![feature(macro_metavar_expr)]

// `curly` = Right hand side curly brackets
// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function"
// `round` = Left hand side round brackets

macro_rules! curly__no_rhs_dollar__round {
    ( $( $i:ident ),* ) => { ${ count($i) } };
}
const _: u32 = curly__no_rhs_dollar__round!(a, b, c);

macro_rules! curly__no_rhs_dollar__no_round {
    ( $i:ident ) => { ${ count($i) } };
    //~^ ERROR `count` can not be placed inside the innermost repetition
}
curly__no_rhs_dollar__no_round!(a);

macro_rules! curly__rhs_dollar__no_round {
    ( $i:ident ) => { ${ count($i) } };
    //~^ ERROR `count` can not be placed inside the innermost repetition
}
curly__rhs_dollar__no_round !(a);

#[rustfmt::skip] // autoformatters can break a few of the error traces
macro_rules! no_curly__no_rhs_dollar__round {
    ( $( $i:ident ),* ) => { count(i) };
    //~^ ERROR missing `fn` or `struct` for function or struct definition
}
no_curly__no_rhs_dollar__round !(a, b, c);

#[rustfmt::skip] // autoformatters can break a few of the error traces
macro_rules! no_curly__no_rhs_dollar__no_round {
    ( $i:ident ) => { count(i) };
    //~^ ERROR missing `fn` or `struct` for function or struct definition
}
no_curly__no_rhs_dollar__no_round !(a);

#[rustfmt::skip] // autoformatters can break a few of the error traces
macro_rules! no_curly__rhs_dollar__round {
    ( $( $i:ident ),* ) => { count($i) };
    //~^ ERROR variable `i` is still repeating at this depth
}
no_curly__rhs_dollar__round! (a);

#[rustfmt::skip] // autoformatters can break a few of the error traces
macro_rules! no_curly__rhs_dollar__no_round {
    ( $i:ident ) => { count($i) };
    //~^ ERROR cannot find function `count` in this scope
}
const _: u32 = no_curly__rhs_dollar__no_round! (a);
//~^ ERROR cannot find value `a` in this scope

fn main() {}