From 8557a2e18c755ef269aa54b067cfc323e97d9a11 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 19 Jun 2016 02:00:11 +0000 Subject: [PATCH] Give `ast::ExprKind::Paren` no-op expressions the same node ids as their children. --- src/libsyntax/fold.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6789e7be058bf..ed6f09eed645f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1102,7 +1102,6 @@ pub fn noop_fold_pat(p: P, folder: &mut T) -> P { pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mut T) -> Expr { Expr { - id: folder.new_id(id), node: match node { ExprKind::Box(e) => { ExprKind::Box(folder.fold_expr(e)) @@ -1270,9 +1269,19 @@ pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mu fields.move_map(|x| folder.fold_field(x)), maybe_expr.map(|x| folder.fold_expr(x))) }, - ExprKind::Paren(ex) => ExprKind::Paren(folder.fold_expr(ex)), + ExprKind::Paren(ex) => { + let sub_expr = folder.fold_expr(ex); + return Expr { + // Nodes that are equal modulo `Paren` sugar no-ops should have the same ids. + id: sub_expr.id, + node: ExprKind::Paren(sub_expr), + span: folder.new_span(span), + attrs: fold_attrs(attrs.into(), folder).into(), + }; + } ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)), }, + id: folder.new_id(id), span: folder.new_span(span), attrs: fold_attrs(attrs.into(), folder).into(), }