Skip to content

Commit eb0a493

Browse files
committed
Implement struct literal equality
1 parent 2abb775 commit eb0a493

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/utils/hir.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
117117
(&ExprPath(ref lqself, ref lsubpath), &ExprPath(ref rqself, ref rsubpath)) => {
118118
both(lqself, rqself, |l, r| self.eq_qself(l, r)) && self.eq_path(lsubpath, rsubpath)
119119
}
120+
(&ExprStruct(ref lpath, ref lf, ref lo), &ExprStruct(ref rpath, ref rf, ref ro)) => {
121+
self.eq_path(lpath, rpath) &&
122+
both(lo, ro, |l, r| self.eq_expr(l, r)) &&
123+
over(lf, rf, |l, r| self.eq_field(l, r))
124+
}
120125
(&ExprTup(ref ltup), &ExprTup(ref rtup)) => self.eq_exprs(ltup, rtup),
121126
(&ExprTupField(ref le, li), &ExprTupField(ref re, ri)) => li.node == ri.node && self.eq_expr(le, re),
122127
(&ExprUnary(lop, ref le), &ExprUnary(rop, ref re)) => lop == rop && self.eq_expr(le, re),
@@ -132,6 +137,10 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
132137
over(left, right, |l, r| self.eq_expr(l, r))
133138
}
134139

140+
fn eq_field(&self, left: &Field, right: &Field) -> bool {
141+
left.name.node == right.name.node && self.eq_expr(&left.expr, &right.expr)
142+
}
143+
135144
/// Check whether two patterns are the same.
136145
pub fn eq_pat(&self, left: &Pat, right: &Pat) -> bool {
137146
match (&left.node, &right.node) {

0 commit comments

Comments
 (0)