- match node {
- StmtKind::Decl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl {
- DeclKind::Local(local) => {
- // take it apart:
- let rewritten_local = local.map(|Local {id, pat, ty, init, span, attrs}| {
- // expand the ty since TyKind::FixedLengthVec contains an Expr
- // and thus may have a macro use
- let expanded_ty = ty.map(|t| fld.fold_ty(t));
- // expand the pat (it might contain macro uses):
- let expanded_pat = fld.fold_pat(pat);
- // find the PatIdents in the pattern:
- // oh dear heaven... this is going to include the enum
- // names, as well... but that should be okay, as long as
- // the new names are gensyms for the old ones.
- // generate fresh names, push them to a new pending list
- let idents = pattern_bindings(&expanded_pat);
- let mut new_pending_renames =
- idents.iter().map(|ident| (*ident, fresh_name(*ident))).collect();
- // rewrite the pattern using the new names (the old
- // ones have already been applied):
- let rewritten_pat = {
- // nested binding to allow borrow to expire:
- let mut rename_fld = IdentRenamer{renames: &mut new_pending_renames};
- rename_fld.fold_pat(expanded_pat)
- };
- // add them to the existing pending renames:
- fld.cx.syntax_env.info().pending_renames
- .extend(new_pending_renames);
- Local {
- id: id,
- ty: expanded_ty,
- pat: rewritten_pat,
- // also, don't forget to expand the init:
- init: init.map(|e| fld.fold_expr(e)),
- span: span,
- attrs: fold::fold_thin_attrs(attrs, fld),
- }
- });
- SmallVector::one(Spanned {
- node: StmtKind::Decl(P(Spanned {
- node: DeclKind::Local(rewritten_local),
- span: span
- }),
- node_id),
- span: stmt_span
- })
- }
- _ => {
- noop_fold_stmt(Spanned {
- node: StmtKind::Decl(P(Spanned {
- node: decl,
- span: span
- }),
- node_id),
- span: stmt_span
- }, fld)
- }
- }),
- _ => {
- noop_fold_stmt(Spanned {
- node: node,
- span: stmt_span
- }, fld)
+ match stmt.node {
+ StmtKind::Local(local) => {
+ // take it apart:
+ let rewritten_local = local.map(|Local {id, pat, ty, init, span, attrs}| {
+ // expand the ty since TyKind::FixedLengthVec contains an Expr
+ // and thus may have a macro use
+ let expanded_ty = ty.map(|t| fld.fold_ty(t));
+ // expand the pat (it might contain macro uses):
+ let expanded_pat = fld.fold_pat(pat);
+ // find the PatIdents in the pattern:
+ // oh dear heaven... this is going to include the enum
+ // names, as well... but that should be okay, as long as
+ // the new names are gensyms for the old ones.
+ // generate fresh names, push them to a new pending list
+ let idents = pattern_bindings(&expanded_pat);
+ let mut new_pending_renames =
+ idents.iter().map(|ident| (*ident, fresh_name(*ident))).collect();
+ // rewrite the pattern using the new names (the old
+ // ones have already been applied):
+ let rewritten_pat = {
+ // nested binding to allow borrow to expire:
+ let mut rename_fld = IdentRenamer{renames: &mut new_pending_renames};
+ rename_fld.fold_pat(expanded_pat)
+ };
+ // add them to the existing pending renames:
+ fld.cx.syntax_env.info().pending_renames
+ .extend(new_pending_renames);
+ Local {
+ id: id,
+ ty: expanded_ty,
+ pat: rewritten_pat,
+ // also, don't forget to expand the init:
+ init: init.map(|e| fld.fold_expr(e)),
+ span: span,
+ attrs: fold::fold_thin_attrs(attrs, fld),
+ }
+ });
+ SmallVector::one(Stmt {
+ id: stmt.id,
+ node: StmtKind::Local(rewritten_local),
+ span: stmt.span,
+ })