]> git.lizzy.rs Git - rust.git/commitdiff
Give `ast::ExprKind::Paren` no-op expressions the same node ids as their children.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sun, 19 Jun 2016 02:00:11 +0000 (02:00 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Wed, 29 Jun 2016 11:06:28 +0000 (11:06 +0000)
src/libsyntax/fold.rs

index 6789e7be058bfcd7177991c3e2bb7c0b5a9c7176..ed6f09eed645f7741951542aaeea87665667266c 100644 (file)
@@ -1102,7 +1102,6 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
 
 pub fn noop_fold_expr<T: Folder>(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<T: Folder>(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(),
     }