File tree Expand file tree Collapse file tree 4 files changed +107
-3
lines changed
hir_def/src/macro_expansion_tests/mbe Expand file tree Collapse file tree 4 files changed +107
-3
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ macro_rules! m1 { () => (Some(x) left overs) }
141
141
macro_rules! m2 { () => ($) }
142
142
143
143
fn main() {
144
- let Some(x) = ();
144
+ let Some(x)left overs = ();
145
145
let /* parse error: expected pattern */
146
146
$ = ();
147
147
}
Original file line number Diff line number Diff line change @@ -109,6 +109,32 @@ pub(crate) mod entry {
109
109
items:: mod_contents ( p, false ) ;
110
110
m. complete ( p, MACRO_ITEMS ) ;
111
111
}
112
+
113
+ pub ( crate ) fn pattern ( p : & mut Parser ) {
114
+ let m = p. start ( ) ;
115
+ patterns:: pattern_single ( p) ;
116
+ if p. at ( EOF ) {
117
+ m. abandon ( p) ;
118
+ return ;
119
+ }
120
+ while !p. at ( EOF ) {
121
+ p. bump_any ( ) ;
122
+ }
123
+ m. complete ( p, ERROR ) ;
124
+ }
125
+
126
+ pub ( crate ) fn type_ ( p : & mut Parser ) {
127
+ let m = p. start ( ) ;
128
+ types:: type_ ( p) ;
129
+ if p. at ( EOF ) {
130
+ m. abandon ( p) ;
131
+ return ;
132
+ }
133
+ while !p. at ( EOF ) {
134
+ p. bump_any ( ) ;
135
+ }
136
+ m. complete ( p, ERROR ) ;
137
+ }
112
138
}
113
139
}
114
140
Original file line number Diff line number Diff line change @@ -110,6 +110,8 @@ pub enum TopEntryPoint {
110
110
Pattern ,
111
111
Type ,
112
112
Expr ,
113
+ /// Edge case -- macros generally don't expand to attributes, with the
114
+ /// exception of `cfg_attr` which does!
113
115
MetaItem ,
114
116
}
115
117
@@ -119,9 +121,9 @@ impl TopEntryPoint {
119
121
TopEntryPoint :: SourceFile => grammar:: entry:: top:: source_file,
120
122
TopEntryPoint :: MacroStmts => grammar:: entry:: top:: macro_stmts,
121
123
TopEntryPoint :: MacroItems => grammar:: entry:: top:: macro_items,
124
+ TopEntryPoint :: Pattern => grammar:: entry:: top:: pattern,
125
+ TopEntryPoint :: Type => grammar:: entry:: top:: type_,
122
126
// FIXME
123
- TopEntryPoint :: Pattern => grammar:: entry:: prefix:: pat,
124
- TopEntryPoint :: Type => grammar:: entry:: prefix:: ty,
125
127
TopEntryPoint :: Expr => grammar:: entry:: prefix:: expr,
126
128
TopEntryPoint :: MetaItem => grammar:: entry:: prefix:: meta_item,
127
129
} ;
Original file line number Diff line number Diff line change @@ -146,6 +146,82 @@ fn macro_pattern() {
146
146
R_PAREN ")"
147
147
"# ] ] ,
148
148
) ;
149
+
150
+ check (
151
+ TopEntryPoint :: Pattern ,
152
+ "None leftover tokens" ,
153
+ expect ! [ [ r#"
154
+ ERROR
155
+ IDENT_PAT
156
+ NAME
157
+ IDENT "None"
158
+ WHITESPACE " "
159
+ IDENT "leftover"
160
+ WHITESPACE " "
161
+ IDENT "tokens"
162
+ "# ] ] ,
163
+ ) ;
164
+
165
+ check (
166
+ TopEntryPoint :: Pattern ,
167
+ "@err" ,
168
+ expect ! [ [ r#"
169
+ ERROR
170
+ ERROR
171
+ AT "@"
172
+ IDENT "err"
173
+ error 0: expected pattern
174
+ "# ] ] ,
175
+ ) ;
176
+ }
177
+
178
+ #[ test]
179
+ fn type_ ( ) {
180
+ check (
181
+ TopEntryPoint :: Type ,
182
+ "Option<!>" ,
183
+ expect ! [ [ r#"
184
+ PATH_TYPE
185
+ PATH
186
+ PATH_SEGMENT
187
+ NAME_REF
188
+ IDENT "Option"
189
+ GENERIC_ARG_LIST
190
+ L_ANGLE "<"
191
+ TYPE_ARG
192
+ NEVER_TYPE
193
+ BANG "!"
194
+ R_ANGLE ">"
195
+ "# ] ] ,
196
+ ) ;
197
+ check (
198
+ TopEntryPoint :: Type ,
199
+ "() () ()" ,
200
+ expect ! [ [ r#"
201
+ ERROR
202
+ TUPLE_TYPE
203
+ L_PAREN "("
204
+ R_PAREN ")"
205
+ WHITESPACE " "
206
+ L_PAREN "("
207
+ R_PAREN ")"
208
+ WHITESPACE " "
209
+ L_PAREN "("
210
+ R_PAREN ")"
211
+ "# ] ] ,
212
+ ) ;
213
+ check (
214
+ TopEntryPoint :: Type ,
215
+ "$$$" ,
216
+ expect ! [ [ r#"
217
+ ERROR
218
+ ERROR
219
+ DOLLAR "$"
220
+ DOLLAR "$"
221
+ DOLLAR "$"
222
+ error 0: expected type
223
+ "# ] ] ,
224
+ ) ;
149
225
}
150
226
151
227
#[ track_caller]
You can’t perform that action at this time.
0 commit comments