@@ -1201,50 +1201,62 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1201
1201
1202
1202
impl < ' a , ' b > Folder for InvocationCollector < ' a , ' b > {
1203
1203
fn fold_expr ( & mut self , expr : P < ast:: Expr > ) -> P < ast:: Expr > {
1204
- let mut expr = self . cfg . configure_expr ( expr) . into_inner ( ) ;
1205
- expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
1206
-
1207
- // ignore derives so they remain unused
1208
- let ( attr, expr, after_derive) = self . classify_nonitem ( expr) ;
1209
-
1210
- if attr. is_some ( ) {
1211
- // collect the invoc regardless of whether or not attributes are permitted here
1212
- // expansion will eat the attribute so it won't error later
1213
- attr. as_ref ( ) . map ( |a| self . cfg . maybe_emit_expr_attr_err ( a) ) ;
1214
-
1215
- // AstFragmentKind::Expr requires the macro to emit an expression
1216
- return self . collect_attr ( attr, vec ! [ ] , Annotatable :: Expr ( P ( expr) ) ,
1217
- AstFragmentKind :: Expr , after_derive) . make_expr ( ) ;
1218
- }
1204
+ let expr = self . cfg . configure_expr ( expr) ;
1205
+ expr. map ( |mut expr| {
1206
+ expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
1207
+
1208
+ // ignore derives so they remain unused
1209
+ let ( attr, expr, after_derive) = self . classify_nonitem ( expr) ;
1210
+
1211
+ if attr. is_some ( ) {
1212
+ // Collect the invoc regardless of whether or not attributes are permitted here
1213
+ // expansion will eat the attribute so it won't error later.
1214
+ attr. as_ref ( ) . map ( |a| self . cfg . maybe_emit_expr_attr_err ( a) ) ;
1215
+
1216
+ // AstFragmentKind::Expr requires the macro to emit an expression.
1217
+ return self . collect_attr ( attr, vec ! [ ] , Annotatable :: Expr ( P ( expr) ) ,
1218
+ AstFragmentKind :: Expr , after_derive)
1219
+ . make_expr ( )
1220
+ . into_inner ( )
1221
+ }
1219
1222
1220
- if let ast:: ExprKind :: Mac ( mac) = expr. node {
1221
- self . check_attributes ( & expr. attrs ) ;
1222
- self . collect_bang ( mac, expr. span , AstFragmentKind :: Expr ) . make_expr ( )
1223
- } else {
1224
- P ( noop_fold_expr ( expr, self ) )
1225
- }
1223
+ if let ast:: ExprKind :: Mac ( mac) = expr. node {
1224
+ self . check_attributes ( & expr. attrs ) ;
1225
+ self . collect_bang ( mac, expr. span , AstFragmentKind :: Expr )
1226
+ . make_expr ( )
1227
+ . into_inner ( )
1228
+ } else {
1229
+ noop_fold_expr ( expr, self )
1230
+ }
1231
+ } )
1226
1232
}
1227
1233
1228
1234
fn fold_opt_expr ( & mut self , expr : P < ast:: Expr > ) -> Option < P < ast:: Expr > > {
1229
- let mut expr = configure ! ( self , expr) . into_inner ( ) ;
1230
- expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
1235
+ let expr = configure ! ( self , expr) ;
1236
+ expr. filter_map ( |mut expr| {
1237
+ expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
1231
1238
1232
- // ignore derives so they remain unused
1233
- let ( attr, expr, after_derive) = self . classify_nonitem ( expr) ;
1239
+ // Ignore derives so they remain unused.
1240
+ let ( attr, expr, after_derive) = self . classify_nonitem ( expr) ;
1234
1241
1235
- if attr. is_some ( ) {
1236
- attr. as_ref ( ) . map ( |a| self . cfg . maybe_emit_expr_attr_err ( a) ) ;
1242
+ if attr. is_some ( ) {
1243
+ attr. as_ref ( ) . map ( |a| self . cfg . maybe_emit_expr_attr_err ( a) ) ;
1237
1244
1238
- return self . collect_attr ( attr, vec ! [ ] , Annotatable :: Expr ( P ( expr) ) ,
1239
- AstFragmentKind :: OptExpr , after_derive) . make_opt_expr ( ) ;
1240
- }
1245
+ return self . collect_attr ( attr, vec ! [ ] , Annotatable :: Expr ( P ( expr) ) ,
1246
+ AstFragmentKind :: OptExpr , after_derive)
1247
+ . make_opt_expr ( )
1248
+ . map ( |expr| expr. into_inner ( ) )
1249
+ }
1241
1250
1242
- if let ast:: ExprKind :: Mac ( mac) = expr. node {
1243
- self . check_attributes ( & expr. attrs ) ;
1244
- self . collect_bang ( mac, expr. span , AstFragmentKind :: OptExpr ) . make_opt_expr ( )
1245
- } else {
1246
- Some ( P ( noop_fold_expr ( expr, self ) ) )
1247
- }
1251
+ if let ast:: ExprKind :: Mac ( mac) = expr. node {
1252
+ self . check_attributes ( & expr. attrs ) ;
1253
+ self . collect_bang ( mac, expr. span , AstFragmentKind :: OptExpr )
1254
+ . make_opt_expr ( )
1255
+ . map ( |expr| expr. into_inner ( ) )
1256
+ } else {
1257
+ Some ( noop_fold_expr ( expr, self ) )
1258
+ }
1259
+ } )
1248
1260
}
1249
1261
1250
1262
fn fold_pat ( & mut self , pat : P < ast:: Pat > ) -> P < ast:: Pat > {
0 commit comments