]> git.proxmox.com Git - rustc.git/blame - src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / macros / rfc-3086-metavar-expr / syntax-errors.rs
CommitLineData
5e7ed085
FG
1#![feature(macro_metavar_expr)]
2
3// `curly` = Right hand side curly brackets
4// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function"
5// `round` = Left hand side round brackets
6
7macro_rules! curly__no_rhs_dollar__round {
8 ( $( $i:ident ),* ) => { ${ count(i) } };
9}
10
11macro_rules! curly__no_rhs_dollar__no_round {
12 ( $i:ident ) => { ${ count(i) } };
13 //~^ ERROR `count` can not be placed inside the inner-most repetition
14}
15
16macro_rules! curly__rhs_dollar__round {
17 ( $( $i:ident ),* ) => { ${ count($i) } };
18 //~^ ERROR expected identifier, found `$`
19 //~| ERROR expected expression, found `$`
20}
21
22macro_rules! curly__rhs_dollar__no_round {
23 ( $i:ident ) => { ${ count($i) } };
24 //~^ ERROR expected identifier, found `$`
25 //~| ERROR expected expression, found `$`
26}
27
28macro_rules! no_curly__no_rhs_dollar__round {
29 ( $( $i:ident ),* ) => { count(i) };
30 //~^ ERROR cannot find function `count` in this scope
31 //~| ERROR cannot find value `i` in this scope
32}
33
34macro_rules! no_curly__no_rhs_dollar__no_round {
35 ( $i:ident ) => { count(i) };
36 //~^ ERROR cannot find function `count` in this scope
37 //~| ERROR cannot find value `i` in this scope
38}
39
40macro_rules! no_curly__rhs_dollar__round {
41 ( $( $i:ident ),* ) => { count($i) };
42 //~^ ERROR variable 'i' is still repeating at this depth
43}
44
45macro_rules! no_curly__rhs_dollar__no_round {
46 ( $i:ident ) => { count($i) };
47 //~^ ERROR cannot find function `count` in this scope
48}
49
50// Other scenarios
51
52macro_rules! dollar_dollar_in_the_lhs {
53 ( $$ $a:ident ) => {
54 //~^ ERROR unexpected token: $
55 };
56}
57
58macro_rules! extra_garbage_after_metavar {
59 ( $( $i:ident ),* ) => {
60 ${count() a b c}
61 //~^ ERROR unexpected token: a
62 //~| ERROR expected expression, found `$`
63 ${count(i a b c)}
64 //~^ ERROR unexpected token: a
65 ${count(i, 1 a b c)}
66 //~^ ERROR unexpected token: a
67 ${count(i) a b c}
68 //~^ ERROR unexpected token: a
69
70 ${ignore(i) a b c}
71 //~^ ERROR unexpected token: a
72 ${ignore(i a b c)}
73 //~^ ERROR unexpected token: a
74
75 ${index() a b c}
76 //~^ ERROR unexpected token: a
77 ${index(1 a b c)}
78 //~^ ERROR unexpected token: a
79
80 ${index() a b c}
81 //~^ ERROR unexpected token: a
82 ${index(1 a b c)}
83 //~^ ERROR unexpected token: a
84 };
85}
86
87const IDX: usize = 1;
88macro_rules! metavar_depth_is_not_literal {
89 ( $( $i:ident ),* ) => { ${ index(IDX) } };
90 //~^ ERROR meta-variable expression depth must be a literal
91 //~| ERROR expected expression, found `$`
92}
93
94macro_rules! metavar_in_the_lhs {
95 ( ${ length() } ) => {
96 //~^ ERROR unexpected token: {
97 //~| ERROR expected one of: `*`, `+`, or `?`
98 };
99}
100
101macro_rules! metavar_token_without_ident {
102 ( $( $i:ident ),* ) => { ${ ignore() } };
103 //~^ ERROR expected identifier
104 //~| ERROR expected expression, found `$`
105}
106
107macro_rules! metavar_with_literal_suffix {
108 ( $( $i:ident ),* ) => { ${ index(1u32) } };
109 //~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions
110 //~| ERROR expected expression, found `$`
111}
112
113macro_rules! metavar_without_parens {
114 ( $( $i:ident ),* ) => { ${ count{i} } };
115 //~^ ERROR meta-variable expression parameter must be wrapped in parentheses
116 //~| ERROR expected expression, found `$`
117}
118
119macro_rules! open_brackets_without_tokens {
120 ( $( $i:ident ),* ) => { ${ {} } };
121 //~^ ERROR expected expression, found `$`
122 //~| ERROR expected identifier
123}
124
125macro_rules! unknown_count_ident {
126 ( $( $i:ident )* ) => {
127 ${count(foo)}
128 //~^ ERROR variable `foo` is not recognized in meta-variable expression
129 };
130}
131
132macro_rules! unknown_ignore_ident {
133 ( $( $i:ident )* ) => {
134 ${ignore(bar)}
135 //~^ ERROR variable `bar` is not recognized in meta-variable expression
136 };
137}
138
139macro_rules! unknown_metavar {
140 ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } };
141 //~^ ERROR unrecognized meta-variable expression
142 //~| ERROR expected expression
143}
144
145fn main() {
146 curly__no_rhs_dollar__round!(a, b, c);
147 curly__no_rhs_dollar__no_round!(a);
148 curly__rhs_dollar__round!(a, b, c);
149 curly__rhs_dollar__no_round!(a);
150 no_curly__no_rhs_dollar__round!(a, b, c);
151 no_curly__no_rhs_dollar__no_round!(a);
152 no_curly__rhs_dollar__round!(a, b, c);
153 no_curly__rhs_dollar__no_round!(a);
154 //~^ ERROR cannot find value `a` in this scope
155
156 extra_garbage_after_metavar!(a);
157 metavar_depth_is_not_literal!(a);
158 metavar_token_without_ident!(a);
159 metavar_with_literal_suffix!(a);
160 metavar_without_parens!(a);
161 open_brackets_without_tokens!(a);
162 unknown_count_ident!(a);
163 unknown_ignore_ident!(a);
164 unknown_metavar!(a);
165}