Skip to content

Commit 9d61b4e

Browse files
committed
Fix SpanlessEq for GenericArg::Const
1 parent 0ebd501 commit 9d61b4e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

clippy_utils/src/hir_utils.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ impl HirEqInterExpr<'_, '_, '_> {
168168
}
169169
}
170170

171+
pub fn eq_body(&mut self, left: BodyId, right: BodyId) -> bool {
172+
let cx = self.inner.cx;
173+
let eval_const = |body| constant_context(cx, cx.tcx.typeck_body(body)).expr(&cx.tcx.hir().body(body).value);
174+
eval_const(left) == eval_const(right)
175+
}
176+
171177
#[allow(clippy::similar_names)]
172178
pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
173179
if !self.inner.allow_side_effects && differing_macro_contexts(left.span, right.span) {
@@ -243,12 +249,7 @@ impl HirEqInterExpr<'_, '_, '_> {
243249
self.inner.allow_side_effects && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
244250
},
245251
(&ExprKind::Repeat(le, ref ll_id), &ExprKind::Repeat(re, ref rl_id)) => {
246-
let mut celcx = constant_context(self.inner.cx, self.inner.cx.tcx.typeck_body(ll_id.body));
247-
let ll = celcx.expr(&self.inner.cx.tcx.hir().body(ll_id.body).value);
248-
let mut celcx = constant_context(self.inner.cx, self.inner.cx.tcx.typeck_body(rl_id.body));
249-
let rl = celcx.expr(&self.inner.cx.tcx.hir().body(rl_id.body).value);
250-
251-
self.eq_expr(le, re) && ll == rl
252+
self.eq_expr(le, re) && self.eq_body(ll_id.body, rl_id.body)
252253
},
253254
(&ExprKind::Ret(ref l), &ExprKind::Ret(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
254255
(&ExprKind::Path(ref l), &ExprKind::Path(ref r)) => self.eq_qpath(l, r),
@@ -284,6 +285,7 @@ impl HirEqInterExpr<'_, '_, '_> {
284285

285286
fn eq_generic_arg(&mut self, left: &GenericArg<'_>, right: &GenericArg<'_>) -> bool {
286287
match (left, right) {
288+
(GenericArg::Const(l), GenericArg::Const(r)) => self.eq_body(l.value.body, r.value.body),
287289
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
288290
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
289291
_ => false,
@@ -384,10 +386,7 @@ impl HirEqInterExpr<'_, '_, '_> {
384386
match (&left.kind, &right.kind) {
385387
(&TyKind::Slice(l_vec), &TyKind::Slice(r_vec)) => self.eq_ty(l_vec, r_vec),
386388
(&TyKind::Array(lt, ref ll_id), &TyKind::Array(rt, ref rl_id)) => {
387-
let cx = self.inner.cx;
388-
let eval_const =
389-
|body| constant_context(cx, cx.tcx.typeck_body(body)).expr(&cx.tcx.hir().body(body).value);
390-
self.eq_ty(lt, rt) && eval_const(ll_id.body) == eval_const(rl_id.body)
389+
self.eq_ty(lt, rt) && self.eq_body(ll_id.body, rl_id.body)
391390
},
392391
(&TyKind::Ptr(ref l_mut), &TyKind::Ptr(ref r_mut)) => {
393392
l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty)
@@ -837,6 +836,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
837836
_ => {
838837
for seg in path.segments {
839838
self.hash_name(seg.ident.name);
839+
self.hash_generic_args(seg.args().args);
840840
}
841841
},
842842
}

0 commit comments

Comments
 (0)