about summary refs log tree commit diff
path: root/tests/ui/macros/metavar-expressions/syntax-errors.rs
blob: 585ea4d5979ceb2b6033d93df9468c131ca78b46 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// General syntax errors that apply to all matavariable expressions
//
// We don't invoke the macros here to ensure code gets rejected at the definition rather than
// only when expanded.

#![feature(macro_metavar_expr)]

macro_rules! dollar_dollar_in_the_lhs {
    ( $$ $a:ident ) => {
        //~^ ERROR unexpected token: $
    };
}

macro_rules! metavar_in_the_lhs {
    ( ${ len() } ) => {
        //~^ ERROR unexpected token: {
        //~| ERROR expected one of: `*`, `+`, or `?`
    };
}

macro_rules! metavar_token_without_ident {
    ( $( $i:ident ),* ) => { ${ ignore() } };
    //~^ ERROR meta-variable expressions must be referenced using a dollar sign
}

macro_rules! metavar_with_literal_suffix {
    ( $( $i:ident ),* ) => { ${ index(1u32) } };
    //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions
}

macro_rules! mve_without_parens {
    ( $( $i:ident ),* ) => { ${ count } };
    //~^ ERROR expected `(`
}

#[rustfmt::skip]
macro_rules! empty_expression {
    () => { ${} };
    //~^ ERROR expected identifier or string literal
}

#[rustfmt::skip]
macro_rules! open_brackets_with_lit {
     () => { ${ "hi" } };
     //~^ ERROR expected identifier
 }

macro_rules! mvs_missing_paren {
    ( $( $i:ident ),* ) => { ${ count $i ($i) } };
    //~^ ERROR expected `(`
}

macro_rules! mve_wrong_delim {
    ( $( $i:ident ),* ) => { ${ count{i} } };
    //~^ ERROR expected `(`
}

macro_rules! invalid_metavar {
    () => { ${ignore($123)} }
    //~^ ERROR expected identifier, found `123`
}

#[rustfmt::skip]
macro_rules! open_brackets_with_group {
    ( $( $i:ident ),* ) => { ${ {} } };
    //~^ ERROR expected identifier
}

macro_rules! extra_garbage_after_metavar {
    ( $( $i:ident ),* ) => {
        ${count() a b c}
        //~^ ERROR unexpected trailing tokens
        ${count($i a b c)}
        //~^ ERROR unexpected trailing tokens
        ${count($i, 1 a b c)}
        //~^ ERROR unexpected trailing tokens
        ${count($i) a b c}
        //~^ ERROR unexpected trailing tokens

        ${ignore($i) a b c}
        //~^ ERROR unexpected trailing tokens
        ${ignore($i a b c)}
        //~^ ERROR unexpected trailing tokens

        ${index() a b c}
        //~^ ERROR unexpected trailing tokens
        ${index(1 a b c)}
        //~^ ERROR unexpected trailing tokens

        ${index() a b c}
        //~^ ERROR unexpected trailing tokens
        ${index(1 a b c)}
        //~^ ERROR unexpected trailing tokens
        ${index(1, a b c)}
        //~^ ERROR unexpected trailing tokens
    };
}

const IDX: usize = 1;
macro_rules! metavar_depth_is_not_literal {
    ( $( $i:ident ),* ) => { ${ index(IDX) } };
    //~^ ERROR meta-variable expression depth must be a literal
}

macro_rules! unknown_count_ident {
    ( $( $i:ident )* ) => {
        ${count(foo)}
        //~^ ERROR meta-variable expressions must be referenced using a dollar sign
    };
}

macro_rules! unknown_ignore_ident {
    ( $( $i:ident )* ) => {
        ${ignore(bar)}
        //~^ ERROR meta-variable expressions must be referenced using a dollar sign
    };
}

macro_rules! unknown_metavar {
    ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } };
    //~^ ERROR unrecognized metavariable expression
}

fn main() {}