@@ -93,18 +93,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
93
93
// Assert that we drop any macro attributes on the floor here
94
94
drop ( attrs) ;
95
95
96
- let expanded_expr = match expand_mac_invoc ( mac, span, fld) {
97
- Some ( expr) => expr,
98
- None => {
99
- return DummyResult :: raw_expr ( span) ;
100
- }
101
- } ;
102
-
103
- // Keep going, outside-in.
104
- let fully_expanded = fld. fold_expr ( expanded_expr) ;
105
- fld. cx . bt_pop ( ) ;
106
-
107
- fully_expanded
96
+ expand_mac_invoc ( mac, span, fld)
108
97
}
109
98
110
99
ast:: ExprKind :: InPlace ( placer, value_expr) => {
@@ -215,8 +204,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
215
204
}
216
205
217
206
/// Expand a (not-ident-style) macro invocation. Returns the result of expansion.
218
- fn expand_mac_invoc < T : MacroGenerable > ( mac : ast:: Mac , span : Span , fld : & mut MacroExpander )
219
- -> Option < T > {
207
+ fn expand_mac_invoc < T : MacroGenerable > ( mac : ast:: Mac , span : Span , fld : & mut MacroExpander ) -> T {
220
208
// it would almost certainly be cleaner to pass the whole
221
209
// macro invocation in, rather than pulling it apart and
222
210
// marking the tts and the ctxt separately. This also goes
@@ -229,7 +217,7 @@ fn expand_mac_invoc<T: MacroGenerable>(mac: ast::Mac, span: Span, fld: &mut Macr
229
217
"expected macro name without module \
230
218
separators") ;
231
219
// let compilation continue
232
- return None ;
220
+ return T :: dummy ( span ) ;
233
221
}
234
222
let extname = pth. segments [ 0 ] . identifier . name ;
235
223
match fld. cx . syntax_env . find ( extname) {
@@ -242,7 +230,7 @@ fn expand_mac_invoc<T: MacroGenerable>(mac: ast::Mac, span: Span, fld: &mut Macr
242
230
err. emit ( ) ;
243
231
244
232
// let compilation continue
245
- None
233
+ T :: dummy ( span )
246
234
}
247
235
Some ( rc) => match * rc {
248
236
NormalTT ( ref expandfun, exp_span, allow_internal_unstable) => {
@@ -275,17 +263,20 @@ fn expand_mac_invoc<T: MacroGenerable>(mac: ast::Mac, span: Span, fld: &mut Macr
275
263
let msg = format ! ( "non-{kind} macro in {kind} position: {name}" ,
276
264
name = extname, kind = T :: kind_name( ) ) ;
277
265
fld. cx . span_err ( pth. span , & msg) ;
278
- return None ;
266
+ return T :: dummy ( span ) ;
279
267
}
280
268
} ;
281
- Some ( parsed. fold_with ( & mut Marker { mark : fm } ) )
269
+ let marked = parsed. fold_with ( & mut Marker { mark : fm } ) ;
270
+ let fully_expanded = marked. fold_with ( fld) ;
271
+ fld. cx . bt_pop ( ) ;
272
+ fully_expanded
282
273
}
283
274
_ => {
284
275
fld. cx . span_err (
285
276
pth. span ,
286
277
& format ! ( "'{}' is not a tt-style macro" ,
287
278
extname) ) ;
288
- None
279
+ T :: dummy ( span )
289
280
}
290
281
}
291
282
}
@@ -543,21 +534,9 @@ fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
543
534
// Assert that we drop any macro attributes on the floor here
544
535
drop ( attrs) ;
545
536
546
- let maybe_new_items : Option < SmallVector < ast:: Stmt > > =
537
+ let mut fully_expanded : SmallVector < ast:: Stmt > =
547
538
expand_mac_invoc ( mac. unwrap ( ) , stmt. span , fld) ;
548
539
549
- let mut fully_expanded = match maybe_new_items {
550
- Some ( stmts) => {
551
- // Keep going, outside-in.
552
- let new_items = stmts. into_iter ( ) . flat_map ( |s| {
553
- fld. fold_stmt ( s) . into_iter ( )
554
- } ) . collect ( ) ;
555
- fld. cx . bt_pop ( ) ;
556
- new_items
557
- }
558
- None => SmallVector :: zero ( )
559
- } ;
560
-
561
540
// If this is a macro invocation with a semicolon, then apply that
562
541
// semicolon to the final statement produced by expansion.
563
542
if style == MacStmtStyle :: Semicolon {
@@ -1096,21 +1075,7 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
1096
1075
} ) ,
1097
1076
ast:: ImplItemKind :: Macro ( mac) => {
1098
1077
check_attributes ( & ii. attrs , fld) ;
1099
-
1100
- let maybe_new_items: Option < SmallVector < ast:: ImplItem > > =
1101
- expand_mac_invoc ( mac, ii. span , fld) ;
1102
-
1103
- match maybe_new_items {
1104
- Some ( impl_items) => {
1105
- // expand again if necessary
1106
- let new_items = impl_items. into_iter ( ) . flat_map ( |ii| {
1107
- expand_impl_item ( ii, fld) . into_iter ( )
1108
- } ) . collect ( ) ;
1109
- fld. cx . bt_pop ( ) ;
1110
- new_items
1111
- }
1112
- None => SmallVector :: zero ( )
1113
- }
1078
+ expand_mac_invoc ( mac, ii. span , fld)
1114
1079
}
1115
1080
_ => fold:: noop_fold_impl_item ( ii, fld)
1116
1081
}
@@ -1154,22 +1119,7 @@ pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
1154
1119
let t = match t. node . clone ( ) {
1155
1120
ast:: TyKind :: Mac ( mac) => {
1156
1121
if fld. cx . ecfg . features . unwrap ( ) . type_macros {
1157
- let expanded_ty = match expand_mac_invoc ( mac, t. span , fld) {
1158
- Some ( ty) => ty,
1159
- None => {
1160
- return DummyResult :: raw_ty ( t. span ) ;
1161
- }
1162
- } ;
1163
-
1164
- // Keep going, outside-in.
1165
- let fully_expanded = fld. fold_ty ( expanded_ty) ;
1166
- fld. cx . bt_pop ( ) ;
1167
-
1168
- fully_expanded. map ( |t| ast:: Ty {
1169
- id : ast:: DUMMY_NODE_ID ,
1170
- node : t. node ,
1171
- span : t. span ,
1172
- } )
1122
+ expand_mac_invoc ( mac, t. span , fld)
1173
1123
} else {
1174
1124
feature_gate:: emit_feature_err (
1175
1125
& fld. cx . parse_sess . span_diagnostic ,
0 commit comments