Skip to content

Commit 8557a2e

Browse files
committed
Give ast::ExprKind::Paren no-op expressions the same node ids as their children.
1 parent a9d25f8 commit 8557a2e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/libsyntax/fold.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
11021102

11031103
pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mut T) -> Expr {
11041104
Expr {
1105-
id: folder.new_id(id),
11061105
node: match node {
11071106
ExprKind::Box(e) => {
11081107
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
12701269
fields.move_map(|x| folder.fold_field(x)),
12711270
maybe_expr.map(|x| folder.fold_expr(x)))
12721271
},
1273-
ExprKind::Paren(ex) => ExprKind::Paren(folder.fold_expr(ex)),
1272+
ExprKind::Paren(ex) => {
1273+
let sub_expr = folder.fold_expr(ex);
1274+
return Expr {
1275+
// Nodes that are equal modulo `Paren` sugar no-ops should have the same ids.
1276+
id: sub_expr.id,
1277+
node: ExprKind::Paren(sub_expr),
1278+
span: folder.new_span(span),
1279+
attrs: fold_attrs(attrs.into(), folder).into(),
1280+
};
1281+
}
12741282
ExprKind::Try(ex) => ExprKind::Try(folder.fold_expr(ex)),
12751283
},
1284+
id: folder.new_id(id),
12761285
span: folder.new_span(span),
12771286
attrs: fold_attrs(attrs.into(), folder).into(),
12781287
}

0 commit comments

Comments
 (0)