Skip to content

Commit 6931532

Browse files
committed
Make SpanlessEq more consistent - part 1, issue rust-lang#10267
- Get rid of the wildcard `_ => false` in `SpanlessEq::eq_expr`. - Make sure that `SpanlessEq::eq_expr` branches remain in alphabetical order.
1 parent a7fecd6 commit 6931532

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

clippy_utils/src/hir_utils.rs

+40-12
Original file line numberDiff line numberDiff line change
@@ -229,47 +229,64 @@ impl HirEqInterExpr<'_, '_, '_> {
229229
(&ExprKind::AddrOf(lb, l_mut, le), &ExprKind::AddrOf(rb, r_mut, re)) => {
230230
lb == rb && l_mut == r_mut && self.eq_expr(le, re)
231231
},
232-
(&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
233-
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
234-
},
232+
(&ExprKind::AddrOf(..), _) => false,
233+
(&ExprKind::Array(l), &ExprKind::Array(r)) => self.eq_exprs(l, r),
234+
(&ExprKind::Array(_), _) => false,
235235
(&ExprKind::Assign(ll, lr, _), &ExprKind::Assign(rl, rr, _)) => {
236236
self.inner.allow_side_effects && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
237237
},
238+
(&ExprKind::Assign(..), _) => false,
238239
(&ExprKind::AssignOp(ref lo, ll, lr), &ExprKind::AssignOp(ref ro, rl, rr)) => {
239240
self.inner.allow_side_effects && lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
240241
},
241-
(&ExprKind::Block(l, _), &ExprKind::Block(r, _)) => self.eq_block(l, r),
242+
(&ExprKind::AssignOp(..), _) => false,
242243
(&ExprKind::Binary(l_op, ll, lr), &ExprKind::Binary(r_op, rl, rr)) => {
243244
l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
244245
|| swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
245246
l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
246247
})
247248
},
249+
(&ExprKind::Binary(..), _) => false,
250+
(&ExprKind::Block(l, _), &ExprKind::Block(r, _)) => self.eq_block(l, r),
251+
(&ExprKind::Block(..), _) => false,
252+
(&ExprKind::Box(l), &ExprKind::Box(r)) => self.eq_expr(l, r),
253+
(&ExprKind::Box(..), _) => false,
248254
(&ExprKind::Break(li, ref le), &ExprKind::Break(ri, ref re)) => {
249255
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
250256
&& both(le, re, |l, r| self.eq_expr(l, r))
251257
},
252-
(&ExprKind::Box(l), &ExprKind::Box(r)) => self.eq_expr(l, r),
253-
(&ExprKind::Call(l_fun, l_args), &ExprKind::Call(r_fun, r_args)) => {
254-
self.inner.allow_side_effects && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
255-
},
258+
(&ExprKind::Break(..), _) => false,
259+
(&ExprKind::Call(..), _) => false,
256260
(&ExprKind::Cast(lx, lt), &ExprKind::Cast(rx, rt)) | (&ExprKind::Type(lx, lt), &ExprKind::Type(rx, rt)) => {
257261
self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
258262
},
263+
(&ExprKind::Cast(..), _) => false,
264+
(&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
265+
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
266+
},
267+
(&ExprKind::Continue(..), _) => false,
268+
(&ExprKind::DropTemps(le), &ExprKind::DropTemps(re)) => self.eq_expr(le, re),
269+
(&ExprKind::DropTemps(..), _) => false,
259270
(&ExprKind::Field(l_f_exp, ref l_f_ident), &ExprKind::Field(r_f_exp, ref r_f_ident)) => {
260271
l_f_ident.name == r_f_ident.name && self.eq_expr(l_f_exp, r_f_exp)
261272
},
273+
(&ExprKind::Field(..), _) => false,
262274
(&ExprKind::Index(la, li), &ExprKind::Index(ra, ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri),
275+
(&ExprKind::Index(..), _) => false,
263276
(&ExprKind::If(lc, lt, ref le), &ExprKind::If(rc, rt, ref re)) => {
264277
self.eq_expr(lc, rc) && self.eq_expr(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r))
265278
},
279+
(&ExprKind::If(..), _) => false,
266280
(&ExprKind::Let(l), &ExprKind::Let(r)) => {
267281
self.eq_pat(l.pat, r.pat) && both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r)) && self.eq_expr(l.init, r.init)
268282
},
283+
(&ExprKind::Let(..), _) => false,
269284
(ExprKind::Lit(l), ExprKind::Lit(r)) => l.node == r.node,
285+
(ExprKind::Lit(..), _) => false,
270286
(&ExprKind::Loop(lb, ref ll, ref lls, _), &ExprKind::Loop(rb, ref rl, ref rls, _)) => {
271287
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
272288
},
289+
(&ExprKind::Loop(..), _) => false,
273290
(&ExprKind::Match(le, la, ref ls), &ExprKind::Match(re, ra, ref rs)) => {
274291
ls == rs
275292
&& self.eq_expr(le, re)
@@ -279,6 +296,7 @@ impl HirEqInterExpr<'_, '_, '_> {
279296
&& self.eq_expr(l.body, r.body)
280297
})
281298
},
299+
(&ExprKind::Match(..), _) => false,
282300
(
283301
&ExprKind::MethodCall(l_path, l_receiver, l_args, _),
284302
&ExprKind::MethodCall(r_path, r_receiver, r_args, _),
@@ -288,21 +306,31 @@ impl HirEqInterExpr<'_, '_, '_> {
288306
&& self.eq_expr(l_receiver, r_receiver)
289307
&& self.eq_exprs(l_args, r_args)
290308
},
309+
(&ExprKind::MethodCall(..), _) => false,
310+
(ExprKind::Path(l), ExprKind::Path(r)) => self.eq_qpath(l, r),
311+
(ExprKind::Path(..), _) => false,
291312
(&ExprKind::Repeat(le, ll), &ExprKind::Repeat(re, rl)) => {
292313
self.eq_expr(le, re) && self.eq_array_length(ll, rl)
293314
},
315+
(&ExprKind::Repeat(..), _) => false,
294316
(ExprKind::Ret(l), ExprKind::Ret(r)) => both(l, r, |l, r| self.eq_expr(l, r)),
295-
(ExprKind::Path(l), ExprKind::Path(r)) => self.eq_qpath(l, r),
317+
(ExprKind::Ret(..), _) => false,
296318
(&ExprKind::Struct(l_path, lf, ref lo), &ExprKind::Struct(r_path, rf, ref ro)) => {
297319
self.eq_qpath(l_path, r_path)
298320
&& both(lo, ro, |l, r| self.eq_expr(l, r))
299321
&& over(lf, rf, |l, r| self.eq_expr_field(l, r))
300322
},
323+
(&ExprKind::Struct(..), _) => false,
301324
(&ExprKind::Tup(l_tup), &ExprKind::Tup(r_tup)) => self.eq_exprs(l_tup, r_tup),
325+
(&ExprKind::Tup(..), _) => false,
302326
(&ExprKind::Unary(l_op, le), &ExprKind::Unary(r_op, re)) => l_op == r_op && self.eq_expr(le, re),
303-
(&ExprKind::Array(l), &ExprKind::Array(r)) => self.eq_exprs(l, r),
304-
(&ExprKind::DropTemps(le), &ExprKind::DropTemps(re)) => self.eq_expr(le, re),
305-
_ => false,
327+
(&ExprKind::Unary(..), _) => false,
328+
(&ExprKind::ConstBlock(_), _)
329+
| (&ExprKind::Closure(_), _)
330+
| (&ExprKind::InlineAsm(_), _)
331+
| (&ExprKind::Yield(..), _)
332+
| (&ExprKind::Type(..), _)
333+
| (&ExprKind::Err, _) => false,
306334
};
307335
(is_eq && (!self.should_ignore(left) || !self.should_ignore(right)))
308336
|| self.inner.expr_fallback.as_mut().map_or(false, |f| f(left, right))

0 commit comments

Comments
 (0)