Skip to content

Commit dfabba0

Browse files
committed
Remove eq_id util function.
1 parent 1a7127c commit dfabba0

File tree

5 files changed

+43
-44
lines changed

5 files changed

+43
-44
lines changed

clippy_lints/src/suspicious_operation_groupings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::ast_utils::{IdentIter, eq_id, is_useless_with_eq_exprs};
1+
use clippy_utils::ast_utils::{IdentIter, is_useless_with_eq_exprs};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::snippet_with_applicability;
44
use core::ops::{Add, AddAssign};
@@ -606,7 +606,7 @@ fn ident_difference_via_ident_iter_with_base_location<Iterable: Into<IdentIter>>
606606
loop {
607607
match (left_iterator.next(), right_iterator.next()) {
608608
(Some(left_ident), Some(right_ident)) => {
609-
if !eq_id(left_ident, right_ident) {
609+
if left_ident.name != right_ident.name {
610610
difference += IdentDifference::Single(base);
611611
if difference.is_complete() {
612612
return (difference, base);
@@ -636,7 +636,7 @@ fn suggestion_with_swapped_ident(
636636
applicability: &mut Applicability,
637637
) -> Option<String> {
638638
get_ident(expr, location).and_then(|current_ident| {
639-
if eq_id(current_ident, new_ident) {
639+
if current_ident.name == new_ident.name {
640640
// We never want to suggest a non-change
641641
return None;
642642
}

clippy_lints/src/unnested_or_patterns.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
22

33
use clippy_config::Conf;
4-
use clippy_utils::ast_utils::{eq_field_pat, eq_id, eq_maybe_qself, eq_pat, eq_path};
4+
use clippy_utils::ast_utils::{eq_field_pat, eq_maybe_qself, eq_pat, eq_path};
55
use clippy_utils::diagnostics::span_lint_and_then;
66
use clippy_utils::msrvs::{self, MsrvStack};
77
use clippy_utils::over;
@@ -263,7 +263,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<Box<Pat>>, focus_idx:
263263
Ident(b1, i1, Some(target)) => extend_with_matching(
264264
target, start, alternatives,
265265
// Binding names must match.
266-
|k| matches!(k, Ident(b2, i2, Some(_)) if b1 == b2 && eq_id(*i1, *i2)),
266+
|k| matches!(k, Ident(b2, i2, Some(_)) if b1 == b2 && i1.name == i2.name),
267267
|k| always_pat!(k, Ident(_, _, Some(p)) => p),
268268
),
269269
// Transform `[pre, x, post] | ... | [pre, y, post]` into `[pre, x | y, post]`.
@@ -329,7 +329,7 @@ fn extend_with_struct_pat(
329329
let pos = fps2.iter().position(|fp2| {
330330
// Avoid `Foo { bar } | Foo { bar }` => `Foo { bar | bar }`
331331
!(fp1.is_shorthand && fp2.is_shorthand)
332-
&& eq_id(fp1.ident, fp2.ident)
332+
&& fp1.ident.name == fp2.ident.name
333333
});
334334
pos_in_2.set(pos);
335335
pos.is_some()
File renamed without changes.

clippy_utils/src/ast_utils/mod.rs renamed to clippy_utils/src/ast/mod.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use crate::{both, over};
88
use rustc_ast::{self as ast, *};
9-
use rustc_span::symbol::Ident;
109
use std::mem;
1110

1211
pub mod ident_iter;
@@ -25,10 +24,6 @@ pub fn unordered_over<X, Y>(left: &[X], right: &[Y], mut eq_fn: impl FnMut(&X, &
2524
left.len() == right.len() && left.iter().all(|l| right.iter().any(|r| eq_fn(l, r)))
2625
}
2726

28-
pub fn eq_id(l: Ident, r: Ident) -> bool {
29-
l.name == r.name
30-
}
31-
3227
pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
3328
use PatKind::*;
3429
match (&l.kind, &r.kind) {
@@ -38,7 +33,7 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
3833
(Wild, Wild) | (Rest, Rest) => true,
3934
(Expr(l), Expr(r)) => eq_expr(l, r),
4035
(Ident(b1, i1, s1), Ident(b2, i2, s2)) => {
41-
b1 == b2 && eq_id(*i1, *i2) && both(s1.as_deref(), s2.as_deref(), eq_pat)
36+
b1 == b2 && i1.name == i2.name && both(s1.as_deref(), s2.as_deref(), eq_pat)
4237
},
4338
(Range(lf, lt, le), Range(rf, rt, re)) => {
4439
eq_expr_opt(lf.as_deref(), rf.as_deref())
@@ -79,7 +74,7 @@ pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool {
7974

8075
pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool {
8176
l.is_placeholder == r.is_placeholder
82-
&& eq_id(l.ident, r.ident)
77+
&& l.ident.name == r.ident.name
8378
&& eq_pat(&l.pat, &r.pat)
8479
&& over(&l.attrs, &r.attrs, eq_attr)
8580
}
@@ -101,7 +96,7 @@ pub fn eq_path(l: &Path, r: &Path) -> bool {
10196
}
10297

10398
pub fn eq_path_seg(l: &PathSegment, r: &PathSegment) -> bool {
104-
eq_id(l.ident, r.ident) && both(l.args.as_ref(), r.args.as_ref(), |l, r| eq_generic_args(l, r))
99+
l.ident.name == r.ident.name && both(l.args.as_ref(), r.args.as_ref(), |l, r| eq_generic_args(l, r))
105100
}
106101

107102
pub fn eq_generic_args(l: &GenericArgs, r: &GenericArgs) -> bool {
@@ -124,7 +119,7 @@ pub fn eq_angle_arg(l: &AngleBracketedArg, r: &AngleBracketedArg) -> bool {
124119

125120
pub fn eq_generic_arg(l: &GenericArg, r: &GenericArg) -> bool {
126121
match (l, r) {
127-
(GenericArg::Lifetime(l), GenericArg::Lifetime(r)) => eq_id(l.ident, r.ident),
122+
(GenericArg::Lifetime(l), GenericArg::Lifetime(r)) => l.ident.name == r.ident.name,
128123
(GenericArg::Type(l), GenericArg::Type(r)) => eq_ty(l, r),
129124
(GenericArg::Const(l), GenericArg::Const(r)) => eq_expr(&l.value, &r.value),
130125
_ => false,
@@ -213,7 +208,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
213208
eq_expr(l1, r1) && eq_expr(l2, r2)
214209
},
215210
(AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv),
216-
(Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp),
211+
(Field(lp, lf), Field(rp, rf)) => lf.name == rf.name && eq_expr(lp, rp),
217212
(Match(ls, la, lkind), Match(rs, ra, rkind)) => (lkind == rkind) && eq_expr(ls, rs) && over(la, ra, eq_arm),
218213
(
219214
Closure(box ast::Closure {
@@ -274,7 +269,7 @@ fn eq_coroutine_kind(a: Option<CoroutineKind>, b: Option<CoroutineKind>) -> bool
274269

275270
pub fn eq_field(l: &ExprField, r: &ExprField) -> bool {
276271
l.is_placeholder == r.is_placeholder
277-
&& eq_id(l.ident, r.ident)
272+
&& l.ident.name == r.ident.name
278273
&& eq_expr(&l.expr, &r.expr)
279274
&& over(&l.attrs, &r.attrs, eq_attr)
280275
}
@@ -288,7 +283,7 @@ pub fn eq_arm(l: &Arm, r: &Arm) -> bool {
288283
}
289284

290285
pub fn eq_label(l: Option<&Label>, r: Option<&Label>) -> bool {
291-
both(l, r, |l, r| eq_id(l.ident, r.ident))
286+
both(l, r, |l, r| l.ident.name == r.ident.name)
292287
}
293288

294289
pub fn eq_block(l: &Block, r: &Block) -> bool {
@@ -332,7 +327,7 @@ pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> b
332327
pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
333328
use ItemKind::*;
334329
match (l, r) {
335-
(ExternCrate(ls, li), ExternCrate(rs, ri)) => ls == rs && eq_id(*li, *ri),
330+
(ExternCrate(ls, li), ExternCrate(rs, ri)) => ls == rs && li.name == ri.name,
336331
(Use(l), Use(r)) => eq_use_tree(l, r),
337332
(
338333
Static(box StaticItem {
@@ -351,7 +346,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
351346
safety: rs,
352347
define_opaque: _,
353348
}),
354-
) => eq_id(*li, *ri) && lm == rm && ls == rs && eq_ty(lt, rt) && eq_expr_opt(le.as_deref(), re.as_deref()),
349+
) => li.name == ri.name && lm == rm && ls == rs && eq_ty(lt, rt) && eq_expr_opt(le.as_deref(), re.as_deref()),
355350
(
356351
Const(box ConstItem {
357352
defaultness: ld,
@@ -371,7 +366,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
371366
}),
372367
) => {
373368
eq_defaultness(*ld, *rd)
374-
&& eq_id(*li, *ri)
369+
&& li.name == ri.name
375370
&& eq_generics(lg, rg)
376371
&& eq_ty(lt, rt)
377372
&& eq_expr_opt(le.as_deref(), re.as_deref())
@@ -398,14 +393,14 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
398393
) => {
399394
eq_defaultness(*ld, *rd)
400395
&& eq_fn_sig(lf, rf)
401-
&& eq_id(*li, *ri)
396+
&& li.name == ri.name
402397
&& eq_generics(lg, rg)
403398
&& eq_opt_fn_contract(lc, rc)
404399
&& both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r))
405400
},
406401
(Mod(ls, li, lmk), Mod(rs, ri, rmk)) => {
407402
ls == rs
408-
&& eq_id(*li, *ri)
403+
&& li.name == ri.name
409404
&& match (lmk, rmk) {
410405
(ModKind::Loaded(litems, linline, _), ModKind::Loaded(ritems, rinline, _)) => {
411406
linline == rinline && over(litems, ritems, |l, r| eq_item(l, r, eq_item_kind))
@@ -440,10 +435,10 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
440435
&& both(lt.as_ref(), rt.as_ref(), |l, r| eq_ty(l, r))
441436
},
442437
(Enum(li, lg, le), Enum(ri, rg, re)) => {
443-
eq_id(*li, *ri) && eq_generics(lg, rg) && over(&le.variants, &re.variants, eq_variant)
438+
li.name == ri.name && eq_generics(lg, rg) && over(&le.variants, &re.variants, eq_variant)
444439
},
445440
(Struct(li, lg, lv), Struct(ri, rg, rv)) | (Union(li, lg, lv), Union(ri, rg, rv)) => {
446-
eq_id(*li, *ri) && eq_generics(lg, rg) && eq_variant_data(lv, rv)
441+
li.name == ri.name && eq_generics(lg, rg) && eq_variant_data(lv, rv)
447442
},
448443
(
449444
Trait(box ast::Trait {
@@ -468,13 +463,13 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
468463
matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
469464
&& la == ra
470465
&& matches!(lu, Safety::Default) == matches!(ru, Safety::Default)
471-
&& eq_id(*li, *ri)
466+
&& li.name == ri.name
472467
&& eq_generics(lg, rg)
473468
&& over(lb, rb, eq_generic_bound)
474469
&& over(lis, ris, |l, r| eq_item(l, r, eq_assoc_item_kind))
475470
},
476471
(TraitAlias(li, lg, lb), TraitAlias(ri, rg, rb)) => {
477-
eq_id(*li, *ri) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound)
472+
li.name == ri.name && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound)
478473
},
479474
(
480475
Impl(ast::Impl {
@@ -503,7 +498,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
503498
},
504499
(MacCall(l), MacCall(r)) => eq_mac_call(l, r),
505500
(MacroDef(li, ld), MacroDef(ri, rd)) => {
506-
eq_id(*li, *ri) && ld.macro_rules == rd.macro_rules && eq_delim_args(&ld.body, &rd.body)
501+
li.name == ri.name && ld.macro_rules == rd.macro_rules && eq_delim_args(&ld.body, &rd.body)
507502
},
508503
_ => false,
509504
}
@@ -529,7 +524,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
529524
safety: rs,
530525
define_opaque: _,
531526
}),
532-
) => eq_id(*li, *ri) && eq_ty(lt, rt) && lm == rm && eq_expr_opt(le.as_deref(), re.as_deref()) && ls == rs,
527+
) => li.name == ri.name && eq_ty(lt, rt) && lm == rm && eq_expr_opt(le.as_deref(), re.as_deref()) && ls == rs,
533528
(
534529
Fn(box ast::Fn {
535530
defaultness: ld,
@@ -552,7 +547,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
552547
) => {
553548
eq_defaultness(*ld, *rd)
554549
&& eq_fn_sig(lf, rf)
555-
&& eq_id(*li, *ri)
550+
&& li.name == ri.name
556551
&& eq_generics(lg, rg)
557552
&& eq_opt_fn_contract(lc, rc)
558553
&& both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r))
@@ -576,7 +571,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
576571
}),
577572
) => {
578573
eq_defaultness(*ld, *rd)
579-
&& eq_id(*li, *ri)
574+
&& li.name == ri.name
580575
&& eq_generics(lg, rg)
581576
&& over(lb, rb, eq_generic_bound)
582577
&& both(lt.as_ref(), rt.as_ref(), |l, r| eq_ty(l, r))
@@ -608,7 +603,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
608603
}),
609604
) => {
610605
eq_defaultness(*ld, *rd)
611-
&& eq_id(*li, *ri)
606+
&& li.name == ri.name
612607
&& eq_generics(lg, rg)
613608
&& eq_ty(lt, rt)
614609
&& eq_expr_opt(le.as_deref(), re.as_deref())
@@ -635,7 +630,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
635630
) => {
636631
eq_defaultness(*ld, *rd)
637632
&& eq_fn_sig(lf, rf)
638-
&& eq_id(*li, *ri)
633+
&& li.name == ri.name
639634
&& eq_generics(lg, rg)
640635
&& eq_opt_fn_contract(lc, rc)
641636
&& both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r))
@@ -659,7 +654,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
659654
}),
660655
) => {
661656
eq_defaultness(*ld, *rd)
662-
&& eq_id(*li, *ri)
657+
&& li.name == ri.name
663658
&& eq_generics(lg, rg)
664659
&& over(lb, rb, eq_generic_bound)
665660
&& both(lt.as_ref(), rt.as_ref(), |l, r| eq_ty(l, r))
@@ -673,7 +668,7 @@ pub fn eq_variant(l: &Variant, r: &Variant) -> bool {
673668
l.is_placeholder == r.is_placeholder
674669
&& over(&l.attrs, &r.attrs, eq_attr)
675670
&& eq_vis(&l.vis, &r.vis)
676-
&& eq_id(l.ident, r.ident)
671+
&& l.ident.name == r.ident.name
677672
&& eq_variant_data(&l.data, &r.data)
678673
&& both(l.disr_expr.as_ref(), r.disr_expr.as_ref(), |l, r| {
679674
eq_expr(&l.value, &r.value)
@@ -695,7 +690,7 @@ pub fn eq_struct_field(l: &FieldDef, r: &FieldDef) -> bool {
695690
l.is_placeholder == r.is_placeholder
696691
&& over(&l.attrs, &r.attrs, eq_attr)
697692
&& eq_vis(&l.vis, &r.vis)
698-
&& both(l.ident.as_ref(), r.ident.as_ref(), |l, r| eq_id(*l, *r))
693+
&& both(l.ident.as_ref(), r.ident.as_ref(), |l, r| l.name == r.name)
699694
&& eq_ty(&l.ty, &r.ty)
700695
}
701696

@@ -753,7 +748,7 @@ pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
753748
&& over(&l.bounds, &r.bounds, eq_generic_bound)
754749
},
755750
(RegionPredicate(l), RegionPredicate(r)) => {
756-
eq_id(l.lifetime.ident, r.lifetime.ident) && over(&l.bounds, &r.bounds, eq_generic_bound)
751+
l.lifetime.ident.name == r.lifetime.ident.name && over(&l.bounds, &r.bounds, eq_generic_bound)
757752
},
758753
(EqPredicate(l), EqPredicate(r)) => eq_ty(&l.lhs_ty, &r.lhs_ty) && eq_ty(&l.rhs_ty, &r.rhs_ty),
759754
_ => false,
@@ -772,7 +767,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
772767
use UseTreeKind::*;
773768
match (l, r) {
774769
(Glob, Glob) => true,
775-
(Simple(l), Simple(r)) => both(l.as_ref(), r.as_ref(), |l, r| eq_id(*l, *r)),
770+
(Simple(l), Simple(r)) => both(l.as_ref(), r.as_ref(), |l, r| l.name == r.name),
776771
(Nested { items: l, .. }, Nested { items: r, .. }) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
777772
_ => false,
778773
}
@@ -834,10 +829,14 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
834829
(Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value),
835830
(Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty),
836831
(Ref(ll, l), Ref(rl, r)) => {
837-
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
832+
both(ll.as_ref(), rl.as_ref(), |l, r| l.ident.name == r.ident.name)
833+
&& l.mutbl == r.mutbl
834+
&& eq_ty(&l.ty, &r.ty)
838835
},
839836
(PinnedRef(ll, l), PinnedRef(rl, r)) => {
840-
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
837+
both(ll.as_ref(), rl.as_ref(), |l, r| l.ident.name == r.ident.name)
838+
&& l.mutbl == r.mutbl
839+
&& eq_ty(&l.ty, &r.ty)
841840
},
842841
(FnPtr(l), FnPtr(r)) => {
843842
l.safety == r.safety
@@ -879,7 +878,7 @@ pub fn eq_poly_ref_trait(l: &PolyTraitRef, r: &PolyTraitRef) -> bool {
879878
pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
880879
use GenericParamKind::*;
881880
l.is_placeholder == r.is_placeholder
882-
&& eq_id(l.ident, r.ident)
881+
&& l.ident.name == r.ident.name
883882
&& over(&l.bounds, &r.bounds, eq_generic_bound)
884883
&& match (&l.kind, &r.kind) {
885884
(Lifetime, Lifetime) => true,
@@ -905,7 +904,7 @@ pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
905904
use GenericBound::*;
906905
match (l, r) {
907906
(Trait(ptr1), Trait(ptr2)) => eq_poly_ref_trait(ptr1, ptr2),
908-
(Outlives(l), Outlives(r)) => eq_id(l.ident, r.ident),
907+
(Outlives(l), Outlives(r)) => l.ident.name == r.ident.name,
909908
_ => false,
910909
}
911910
}
@@ -928,7 +927,7 @@ fn eq_term(l: &Term, r: &Term) -> bool {
928927

929928
pub fn eq_assoc_item_constraint(l: &AssocItemConstraint, r: &AssocItemConstraint) -> bool {
930929
use AssocItemConstraintKind::*;
931-
eq_id(l.ident, r.ident)
930+
l.ident.name == r.ident.name
932931
&& match (&l.kind, &r.kind) {
933932
(Equality { term: l }, Equality { term: r }) => eq_term(l, r),
934933
(Bound { bounds: l }, Bound { bounds: r }) => over(l, r, eq_generic_bound),

clippy_utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern crate rustc_span;
4949
extern crate rustc_trait_selection;
5050
extern crate smallvec;
5151

52-
pub mod ast_utils;
52+
pub mod ast;
5353
pub mod attrs;
5454
mod check_proc_macro;
5555
pub mod comparisons;

0 commit comments

Comments
 (0)