@@ -54,7 +54,7 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
54
54
exts. insert ( named_extension. name , named_extension. ext ) ;
55
55
( ast:: expr_rec ( ~[ ] , None ) , s)
56
56
}
57
- Some ( expr_tt ( _) ) => {
57
+ Some ( normal_tt ( _) ) => {
58
58
cx. span_fatal ( pth. span ,
59
59
fmt ! ( "this tt-style macro should be \
60
60
invoked '%s!(...)'", * extname) )
@@ -78,7 +78,7 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
78
78
cx. span_fatal ( pth. span ,
79
79
fmt ! ( "macro undefined: '%s'" , * extname) )
80
80
}
81
- Some ( expr_tt ( { expander : exp, span : exp_sp} ) ) => {
81
+ Some ( normal_tt ( { expander : exp, span : exp_sp} ) ) => {
82
82
let expanded = match exp ( cx, mac. span , tts) {
83
83
mr_expr( e) => e,
84
84
mr_expr_or_item( expr_maker, _) => expr_maker ( ) ,
@@ -153,7 +153,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
153
153
} ;
154
154
match exts. find ( mname) {
155
155
None | Some ( normal( _) ) | Some ( macro_defining( _) )
156
- | Some ( expr_tt ( _) ) | Some ( item_tt( * ) ) => items,
156
+ | Some ( normal_tt ( _) ) | Some ( item_tt( * ) ) => items,
157
157
Some ( item_decorator( dec_fn) ) => {
158
158
dec_fn ( cx, attr. span , attr. node . value , items)
159
159
}
@@ -200,34 +200,49 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
200
200
match it. node {
201
201
item_mac ( { node : mac_invoc_tt( pth, tts) , _} ) => {
202
202
let extname = cx. parse_sess ( ) . interner . get ( pth. idents [ 0 ] ) ;
203
- match exts. find ( * extname) {
203
+ let ( expanded , ex_span ) = match exts. find ( * extname) {
204
204
None => {
205
205
cx. span_fatal ( pth. span ,
206
- fmt ! ( "macro undefined: '%s'" , * extname) )
206
+ fmt ! ( "macro undefined: '%s!'" , * extname) )
207
+ }
208
+ Some ( normal_tt( expand) ) => {
209
+ if it. ident != parse:: token:: special_idents:: invalid {
210
+ cx. span_fatal ( pth. span ,
211
+ fmt ! ( "macro %s! expects no ident argument, \
212
+ given '%s'", * extname,
213
+ * cx. parse_sess( ) . interner. get( it. ident) ) ) ;
214
+ }
215
+ ( expand. expander ( cx, it. span , tts) , expand. span )
207
216
}
208
217
Some ( item_tt( expand) ) => {
209
- let expanded = expand. expander ( cx, it. span , it. ident , tts) ;
210
- cx. bt_push ( ExpandedFrom ( { call_site: it. span ,
211
- callie : { name : * extname,
212
- span : expand. span } } ) ) ;
213
- let maybe_it = match expanded {
214
- mr_item( it) => fld. fold_item ( it) ,
215
- mr_expr( _) => cx. span_fatal ( pth. span ,
216
- ~"expr macro in item position: " +
217
- *extname),
218
- mr_expr_or_item(_, item_maker) =>
219
- option::chain(item_maker(), |i| {fld.fold_item(i)}),
220
- mr_def(mdef) => {
221
- exts.insert(mdef.name, mdef.ext);
222
- None
223
- }
224
- };
225
- cx.bt_pop();
226
- return maybe_it
218
+ if it. ident == parse:: token:: special_idents:: invalid {
219
+ cx. span_fatal ( pth. span ,
220
+ fmt ! ( "macro %s! expects an ident argument" ,
221
+ * extname) ) ;
222
+ }
223
+ ( expand. expander ( cx, it. span , it. ident , tts) , expand. span )
227
224
}
228
225
_ => cx. span_fatal (
229
226
it. span , fmt ! ( "%s! is not legal in item position" , * extname) )
230
- }
227
+ } ;
228
+
229
+ cx. bt_push ( ExpandedFrom ( { call_site: it. span ,
230
+ callie : { name : * extname,
231
+ span : ex_span} } ) ) ;
232
+ let maybe_it = match expanded {
233
+ mr_item( it) => fld. fold_item ( it) ,
234
+ mr_expr( _) => cx. span_fatal ( pth. span ,
235
+ ~"expr macro in item position: " +
236
+ *extname),
237
+ mr_expr_or_item(_, item_maker) =>
238
+ option::chain(item_maker(), |i| {fld.fold_item(i)}),
239
+ mr_def(mdef) => {
240
+ exts.insert(mdef.name, mdef.ext);
241
+ None
242
+ }
243
+ };
244
+ cx.bt_pop();
245
+ return maybe_it;
231
246
}
232
247
_ => cx.span_bug(it.span, ~" invalid item macro invocation")
233
248
}
0 commit comments