File: syntax-errors.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (168 lines) | stat: -rw-r--r-- 4,756 bytes parent folder | download | duplicates (5)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#![feature(macro_metavar_expr_concat)]

macro_rules! wrong_concat_declarations {
    ($ex:expr) => {
        ${concat()}
        //~^ ERROR expected identifier

        ${concat(aaaa)}
        //~^ ERROR `concat` must have at least two elements

        ${concat(aaaa,)}
        //~^ ERROR expected identifier

        ${concat(_, aaaa)}

        ${concat(aaaa aaaa)}
        //~^ ERROR expected comma

        ${concat($ex)}
        //~^ ERROR `concat` must have at least two elements

        ${concat($ex, aaaa)}
        //~^ ERROR metavariables of `${concat(..)}` must be of type

        ${concat($ex, aaaa 123)}
        //~^ ERROR expected comma

        ${concat($ex, aaaa,)}
        //~^ ERROR expected identifier
    };
}

macro_rules! dollar_sign_without_referenced_ident {
    ($ident:ident) => {
        const ${concat(FOO, $foo)}: i32 = 2;
        //~^ ERROR variable `foo` is not recognized in meta-variable expression
    };
}

macro_rules! starting_number {
    ($ident:ident) => {{
        let ${concat("1", $ident)}: () = ();
        //~^ ERROR `${concat(..)}` is not generating a valid identifier
    }};
}

macro_rules! starting_valid_unicode {
    ($ident:ident) => {{
        let ${concat("Ý", $ident)}: () = ();
    }};
}

macro_rules! starting_invalid_unicode {
    ($ident:ident) => {{
        let ${concat("\u{00BD}", $ident)}: () = ();
        //~^ ERROR `${concat(..)}` is not generating a valid identifier
    }};
}

macro_rules! ending_number {
    ($ident:ident) => {{
        let ${concat($ident, "1")}: () = ();
    }};
}

macro_rules! ending_valid_unicode {
    ($ident:ident) => {{
        let ${concat($ident, "Ý")}: () = ();
    }};
}

macro_rules! ending_invalid_unicode {
    ($ident:ident) => {{
        let ${concat($ident, "\u{00BD}")}: () = ();
        //~^ ERROR `${concat(..)}` is not generating a valid identifier
    }};
}

macro_rules! empty {
    () => {{
        let ${concat("", "")}: () = ();
        //~^ ERROR `${concat(..)}` is not generating a valid identifier
    }};
}

macro_rules! unsupported_literals {
    ($ident:ident) => {{
        let ${concat(_a, 'b')}: () = ();
        //~^ ERROR expected identifier or string literal
        //~| ERROR expected pattern
        let ${concat(_a, 1)}: () = ();
        //~^ ERROR expected identifier or string literal

        let ${concat($ident, 'b')}: () = ();
        //~^ ERROR expected identifier or string literal
        let ${concat($ident, 1)}: () = ();
        //~^ ERROR expected identifier or string literal
    }};
}

macro_rules! bad_literal_string {
    ($literal:literal) => {
        const ${concat(_foo, $literal)}: () = ();
        //~^ ERROR `${concat(..)}` is not generating a valid identifier
        //~| ERROR `${concat(..)}` is not generating a valid identifier
        //~| ERROR `${concat(..)}` is not generating a valid identifier
        //~| ERROR `${concat(..)}` is not generating a valid identifier
        //~| ERROR `${concat(..)}` is not generating a valid identifier
        //~| ERROR `${concat(..)}` is not generating a valid identifier
        //~| ERROR `${concat(..)}` is not generating a valid identifier
    }
}

macro_rules! bad_literal_non_string {
    ($literal:literal) => {
        const ${concat(_foo, $literal)}: () = ();
        //~^ ERROR metavariables of `${concat(..)}` must be of type
        //~| ERROR metavariables of `${concat(..)}` must be of type
        //~| ERROR metavariables of `${concat(..)}` must be of type
        //~| ERROR metavariables of `${concat(..)}` must be of type
        //~| ERROR metavariables of `${concat(..)}` must be of type
    }
}

macro_rules! bad_tt_literal {
    ($tt:tt) => {
        const ${concat(_foo, $tt)}: () = ();
        //~^ ERROR metavariables of `${concat(..)}` must be of type
        //~| ERROR metavariables of `${concat(..)}` must be of type
        //~| ERROR metavariables of `${concat(..)}` must be of type
    }
}

fn main() {
    wrong_concat_declarations!(1);

    dollar_sign_without_referenced_ident!(VAR);

    starting_number!(_abc);
    starting_valid_unicode!(_abc);
    starting_invalid_unicode!(_abc);

    ending_number!(_abc);
    ending_valid_unicode!(_abc);
    ending_invalid_unicode!(_abc);
    unsupported_literals!(_abc);

    empty!();

    bad_literal_string!("\u{00BD}");
    bad_literal_string!("\x41");
    bad_literal_string!("🤷");
    bad_literal_string!("d[-_-]b");

    bad_literal_string!("-1");
    bad_literal_string!("1.0");
    bad_literal_string!("'1'");

    bad_literal_non_string!(1);
    bad_literal_non_string!(-1);
    bad_literal_non_string!(1.0);
    bad_literal_non_string!('1');
    bad_literal_non_string!(false);

    bad_tt_literal!(1);
    bad_tt_literal!(1.0);
    bad_tt_literal!('1');
}