@@ -93,18 +93,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
9393 // Assert that we drop any macro attributes on the floor here
9494 drop ( attrs) ;
9595
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)
10897 }
10998
11099 ast:: ExprKind :: InPlace ( placer, value_expr) => {
@@ -215,8 +204,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
215204}
216205
217206/// 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 {
220208 // it would almost certainly be cleaner to pass the whole
221209 // macro invocation in, rather than pulling it apart and
222210 // 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
229217 "expected macro name without module \
230218 separators") ;
231219 // let compilation continue
232- return None ;
220+ return T :: dummy ( span ) ;
233221 }
234222 let extname = pth. segments [ 0 ] . identifier . name ;
235223 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
242230 err. emit ( ) ;
243231
244232 // let compilation continue
245- None
233+ T :: dummy ( span )
246234 }
247235 Some ( rc) => match * rc {
248236 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
275263 let msg = format ! ( "non-{kind} macro in {kind} position: {name}" ,
276264 name = extname, kind = T :: kind_name( ) ) ;
277265 fld. cx . span_err ( pth. span , & msg) ;
278- return None ;
266+ return T :: dummy ( span ) ;
279267 }
280268 } ;
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
282273 }
283274 _ => {
284275 fld. cx . span_err (
285276 pth. span ,
286277 & format ! ( "'{}' is not a tt-style macro" ,
287278 extname) ) ;
288- None
279+ T :: dummy ( span )
289280 }
290281 }
291282 }
@@ -543,21 +534,9 @@ fn expand_stmt(stmt: Stmt, fld: &mut MacroExpander) -> SmallVector<Stmt> {
543534 // Assert that we drop any macro attributes on the floor here
544535 drop ( attrs) ;
545536
546- let maybe_new_items : Option < SmallVector < ast:: Stmt > > =
537+ let mut fully_expanded : SmallVector < ast:: Stmt > =
547538 expand_mac_invoc ( mac. unwrap ( ) , stmt. span , fld) ;
548539
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-
561540 // If this is a macro invocation with a semicolon, then apply that
562541 // semicolon to the final statement produced by expansion.
563542 if style == MacStmtStyle :: Semicolon {
@@ -1096,21 +1075,7 @@ fn expand_impl_item(ii: ast::ImplItem, fld: &mut MacroExpander)
10961075 } ) ,
10971076 ast:: ImplItemKind :: Macro ( mac) => {
10981077 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)
11141079 }
11151080 _ => fold:: noop_fold_impl_item ( ii, fld)
11161081 }
@@ -1154,22 +1119,7 @@ pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
11541119 let t = match t. node . clone ( ) {
11551120 ast:: TyKind :: Mac ( mac) => {
11561121 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)
11731123 } else {
11741124 feature_gate:: emit_feature_err (
11751125 & fld. cx . parse_sess . span_diagnostic ,
0 commit comments