1 //! Utilities for manipulating and extracting information from `rustc_ast::ast`.
3 //! - The `eq_foobar` functions test for semantic equality but ignores `NodeId`s and `Span`s.
5 #![allow(clippy::similar_names, clippy::wildcard_imports, clippy::enum_glob_use)]
7 use crate::utils::{both, over};
8 use rustc_ast::ast::{self, *};
10 use rustc_span::symbol::Ident;
13 /// Checks if each element in the first slice is contained within the latter as per `eq_fn`.
14 pub fn unordered_over<X>(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) -> bool {
15 left.len() == right.len() && left.iter().all(|l| right.iter().any(|r| eq_fn(l, r)))
18 pub fn eq_id(l: Ident, r: Ident) -> bool {
22 pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
24 match (&l.kind, &r.kind) {
25 (Paren(l), _) => eq_pat(l, r),
26 (_, Paren(r)) => eq_pat(l, r),
27 (Wild, Wild) | (Rest, Rest) => true,
28 (Lit(l), Lit(r)) => eq_expr(l, r),
29 (Ident(b1, i1, s1), Ident(b2, i2, s2)) => b1 == b2 && eq_id(*i1, *i2) && both(s1, s2, |l, r| eq_pat(l, r)),
30 (Range(lf, lt, le), Range(rf, rt, re)) => {
31 eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt) && eq_range_end(&le.node, &re.node)
34 | (Ref(l, Mutability::Not), Ref(r, Mutability::Not))
35 | (Ref(l, Mutability::Mut), Ref(r, Mutability::Mut)) => eq_pat(l, r),
36 (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, |l, r| eq_pat(l, r)),
37 (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
38 (TupleStruct(lp, lfs), TupleStruct(rp, rfs)) => eq_path(lp, rp) && over(lfs, rfs, |l, r| eq_pat(l, r)),
39 (Struct(lp, lfs, lr), Struct(rp, rfs, rr)) => {
40 lr == rr && eq_path(lp, rp) && unordered_over(lfs, rfs, |lf, rf| eq_field_pat(lf, rf))
42 (Or(ls), Or(rs)) => unordered_over(ls, rs, |l, r| eq_pat(l, r)),
43 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
48 pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool {
50 (RangeEnd::Excluded, RangeEnd::Excluded) => true,
51 (RangeEnd::Included(l), RangeEnd::Included(r)) => {
52 matches!(l, RangeSyntax::DotDotEq) == matches!(r, RangeSyntax::DotDotEq)
58 pub fn eq_field_pat(l: &FieldPat, r: &FieldPat) -> bool {
59 l.is_placeholder == r.is_placeholder
60 && eq_id(l.ident, r.ident)
61 && eq_pat(&l.pat, &r.pat)
62 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
65 pub fn eq_qself(l: &QSelf, r: &QSelf) -> bool {
66 l.position == r.position && eq_ty(&l.ty, &r.ty)
69 pub fn eq_path(l: &Path, r: &Path) -> bool {
70 over(&l.segments, &r.segments, |l, r| eq_path_seg(l, r))
73 pub fn eq_path_seg(l: &PathSegment, r: &PathSegment) -> bool {
74 eq_id(l.ident, r.ident) && both(&l.args, &r.args, |l, r| eq_generic_args(l, r))
77 pub fn eq_generic_args(l: &GenericArgs, r: &GenericArgs) -> bool {
79 (GenericArgs::AngleBracketed(l), GenericArgs::AngleBracketed(r)) => {
80 over(&l.args, &r.args, |l, r| eq_angle_arg(l, r))
82 (GenericArgs::Parenthesized(l), GenericArgs::Parenthesized(r)) => {
83 over(&l.inputs, &r.inputs, |l, r| eq_ty(l, r)) && eq_fn_ret_ty(&l.output, &r.output)
89 pub fn eq_angle_arg(l: &AngleBracketedArg, r: &AngleBracketedArg) -> bool {
91 (AngleBracketedArg::Arg(l), AngleBracketedArg::Arg(r)) => eq_generic_arg(l, r),
92 (AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_constraint(l, r),
97 pub fn eq_generic_arg(l: &GenericArg, r: &GenericArg) -> bool {
99 (GenericArg::Lifetime(l), GenericArg::Lifetime(r)) => eq_id(l.ident, r.ident),
100 (GenericArg::Type(l), GenericArg::Type(r)) => eq_ty(l, r),
101 (GenericArg::Const(l), GenericArg::Const(r)) => eq_expr(&l.value, &r.value),
106 pub fn eq_expr_opt(l: &Option<P<Expr>>, r: &Option<P<Expr>>) -> bool {
107 both(l, r, |l, r| eq_expr(l, r))
110 pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
112 if !over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) {
115 match (&l.kind, &r.kind) {
116 (Paren(l), _) => eq_expr(l, r),
117 (_, Paren(r)) => eq_expr(l, r),
119 (Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
120 (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
121 (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
122 (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
123 (MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
124 (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
125 (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
126 (Lit(l), Lit(r)) => l.kind == r.kind,
127 (Cast(l, lt), Cast(r, rt)) | (Type(l, lt), Type(r, rt)) => eq_expr(l, r) && eq_ty(lt, rt),
128 (Let(lp, le), Let(rp, re)) => eq_pat(lp, rp) && eq_expr(le, re),
129 (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re),
130 (While(lc, lt, ll), While(rc, rt, rl)) => eq_label(ll, rl) && eq_expr(lc, rc) && eq_block(lt, rt),
131 (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => {
132 eq_label(ll, rl) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt)
134 (Loop(lt, ll), Loop(rt, rl)) => eq_label(ll, rl) && eq_block(lt, rt),
135 (Block(lb, ll), Block(rb, rl)) => eq_label(ll, rl) && eq_block(lb, rb),
136 (TryBlock(l), TryBlock(r)) => eq_block(l, r),
137 (Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l, r),
138 (Break(ll, le), Break(rl, re)) => eq_label(ll, rl) && eq_expr_opt(le, re),
139 (Continue(ll), Continue(rl)) => eq_label(ll, rl),
140 (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2), Index(r1, r2)) => eq_expr(l1, r1) && eq_expr(l2, r2),
141 (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv),
142 (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp),
143 (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, |l, r| eq_arm(l, r)),
144 (Closure(lc, la, lm, lf, lb, _), Closure(rc, ra, rm, rf, rb, _)) => {
145 lc == rc && la.is_async() == ra.is_async() && lm == rm && eq_fn_decl(lf, rf) && eq_expr(lb, rb)
147 (Async(lc, _, lb), Async(rc, _, rb)) => lc == rc && eq_block(lb, rb),
148 (Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt),
149 (AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re),
150 (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
151 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
152 (Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => {
153 eq_path(lp, rp) && eq_expr_opt(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r))
159 pub fn eq_field(l: &Field, r: &Field) -> bool {
160 l.is_placeholder == r.is_placeholder
161 && eq_id(l.ident, r.ident)
162 && eq_expr(&l.expr, &r.expr)
163 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
166 pub fn eq_arm(l: &Arm, r: &Arm) -> bool {
167 l.is_placeholder == r.is_placeholder
168 && eq_pat(&l.pat, &r.pat)
169 && eq_expr(&l.body, &r.body)
170 && eq_expr_opt(&l.guard, &r.guard)
171 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
174 pub fn eq_label(l: &Option<Label>, r: &Option<Label>) -> bool {
175 both(l, r, |l, r| eq_id(l.ident, r.ident))
178 pub fn eq_block(l: &Block, r: &Block) -> bool {
179 l.rules == r.rules && over(&l.stmts, &r.stmts, |l, r| eq_stmt(l, r))
182 pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
184 match (&l.kind, &r.kind) {
185 (Local(l), Local(r)) => {
186 eq_pat(&l.pat, &r.pat)
187 && both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
188 && eq_expr_opt(&l.init, &r.init)
189 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
191 (Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
192 (Expr(l), Expr(r)) | (Semi(l), Semi(r)) => eq_expr(l, r),
193 (Empty, Empty) => true,
194 (MacCall(l), MacCall(r)) => l.1 == r.1 && eq_mac_call(&l.0, &r.0) && over(&l.2, &r.2, |l, r| eq_attr(l, r)),
199 pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> bool) -> bool {
200 eq_id(l.ident, r.ident)
201 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
202 && eq_vis(&l.vis, &r.vis)
203 && eq_kind(&l.kind, &r.kind)
206 pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
209 (ExternCrate(l), ExternCrate(r)) => l == r,
210 (Use(l), Use(r)) => eq_use_tree(l, r),
211 (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
212 (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
213 (Fn(ld, lf, lg, lb), Fn(rd, rf, rg, rb)) => {
214 eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
216 (Mod(l), Mod(r)) => l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind)),
217 (ForeignMod(l), ForeignMod(r)) => {
218 both(&l.abi, &r.abi, |l, r| eq_str_lit(l, r))
219 && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind))
221 (TyAlias(ld, lg, lb, lt), TyAlias(rd, rg, rb, rt)) => {
222 eq_defaultness(*ld, *rd)
223 && eq_generics(lg, rg)
224 && over(lb, rb, |l, r| eq_generic_bound(l, r))
225 && both(lt, rt, |l, r| eq_ty(l, r))
227 (Enum(le, lg), Enum(re, rg)) => {
228 over(&le.variants, &re.variants, |l, r| eq_variant(l, r)) && eq_generics(lg, rg)
230 (Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => {
231 eq_variant_data(lv, rv) && eq_generics(lg, rg)
233 (Trait(la, lu, lg, lb, li), Trait(ra, ru, rg, rb, ri)) => {
235 && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
236 && eq_generics(lg, rg)
237 && over(lb, rb, |l, r| eq_generic_bound(l, r))
238 && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind))
240 (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, |l, r| eq_generic_bound(l, r)),
263 matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
264 && matches!(lp, ImplPolarity::Positive) == matches!(rp, ImplPolarity::Positive)
265 && eq_defaultness(*ld, *rd)
266 && matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
267 && eq_generics(lg, rg)
268 && both(lot, rot, |l, r| eq_path(&l.path, &r.path))
270 && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind))
272 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
273 (MacroDef(l), MacroDef(r)) => l.macro_rules == r.macro_rules && eq_mac_args(&l.body, &r.body),
278 pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
279 use ForeignItemKind::*;
281 (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
282 (Fn(ld, lf, lg, lb), Fn(rd, rf, rg, rb)) => {
283 eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
285 (TyAlias(ld, lg, lb, lt), TyAlias(rd, rg, rb, rt)) => {
286 eq_defaultness(*ld, *rd)
287 && eq_generics(lg, rg)
288 && over(lb, rb, |l, r| eq_generic_bound(l, r))
289 && both(lt, rt, |l, r| eq_ty(l, r))
291 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
296 pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
297 use AssocItemKind::*;
299 (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
300 (Fn(ld, lf, lg, lb), Fn(rd, rf, rg, rb)) => {
301 eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
303 (TyAlias(ld, lg, lb, lt), TyAlias(rd, rg, rb, rt)) => {
304 eq_defaultness(*ld, *rd)
305 && eq_generics(lg, rg)
306 && over(lb, rb, |l, r| eq_generic_bound(l, r))
307 && both(lt, rt, |l, r| eq_ty(l, r))
309 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
314 pub fn eq_variant(l: &Variant, r: &Variant) -> bool {
315 l.is_placeholder == r.is_placeholder
316 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
317 && eq_vis(&l.vis, &r.vis)
318 && eq_id(l.ident, r.ident)
319 && eq_variant_data(&l.data, &r.data)
320 && both(&l.disr_expr, &r.disr_expr, |l, r| eq_expr(&l.value, &r.value))
323 pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool {
326 (Unit(_), Unit(_)) => true,
327 (Struct(l, _), Struct(r, _)) | (Tuple(l, _), Tuple(r, _)) => over(l, r, |l, r| eq_struct_field(l, r)),
332 pub fn eq_struct_field(l: &StructField, r: &StructField) -> bool {
333 l.is_placeholder == r.is_placeholder
334 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
335 && eq_vis(&l.vis, &r.vis)
336 && both(&l.ident, &r.ident, |l, r| eq_id(*l, *r))
337 && eq_ty(&l.ty, &r.ty)
340 pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool {
341 eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header)
344 pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
345 matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No)
346 && l.asyncness.is_async() == r.asyncness.is_async()
347 && matches!(l.constness, Const::No) == matches!(r.constness, Const::No)
348 && eq_ext(&l.ext, &r.ext)
351 pub fn eq_generics(l: &Generics, r: &Generics) -> bool {
352 over(&l.params, &r.params, |l, r| eq_generic_param(l, r))
353 && over(&l.where_clause.predicates, &r.where_clause.predicates, |l, r| {
354 eq_where_predicate(l, r)
358 pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
359 use WherePredicate::*;
361 (BoundPredicate(l), BoundPredicate(r)) => {
362 over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
363 eq_generic_param(l, r)
364 }) && eq_ty(&l.bounded_ty, &r.bounded_ty)
365 && over(&l.bounds, &r.bounds, |l, r| eq_generic_bound(l, r))
367 (RegionPredicate(l), RegionPredicate(r)) => {
368 eq_id(l.lifetime.ident, r.lifetime.ident) && over(&l.bounds, &r.bounds, |l, r| eq_generic_bound(l, r))
370 (EqPredicate(l), EqPredicate(r)) => eq_ty(&l.lhs_ty, &r.lhs_ty) && eq_ty(&l.rhs_ty, &r.rhs_ty),
375 pub fn eq_use_tree(l: &UseTree, r: &UseTree) -> bool {
376 eq_path(&l.prefix, &r.prefix) && eq_use_tree_kind(&l.kind, &r.kind)
379 pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
382 (Glob, Glob) => true,
383 (Simple(l, _, _), Simple(r, _, _)) => both(l, r, |l, r| eq_id(*l, *r)),
384 (Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
389 pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
391 (Defaultness::Final, Defaultness::Final) | (Defaultness::Default(_), Defaultness::Default(_)) => true,
396 pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
397 use VisibilityKind::*;
398 match (&l.node, &r.node) {
399 (Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
400 (Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
405 pub fn eq_fn_decl(l: &FnDecl, r: &FnDecl) -> bool {
406 eq_fn_ret_ty(&l.output, &r.output)
407 && over(&l.inputs, &r.inputs, |l, r| {
408 l.is_placeholder == r.is_placeholder
409 && eq_pat(&l.pat, &r.pat)
410 && eq_ty(&l.ty, &r.ty)
411 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
415 pub fn eq_fn_ret_ty(l: &FnRetTy, r: &FnRetTy) -> bool {
417 (FnRetTy::Default(_), FnRetTy::Default(_)) => true,
418 (FnRetTy::Ty(l), FnRetTy::Ty(r)) => eq_ty(l, r),
423 pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
425 match (&l.kind, &r.kind) {
426 (Paren(l), _) => eq_ty(l, r),
427 (_, Paren(r)) => eq_ty(l, r),
428 (Never, Never) | (Infer, Infer) | (ImplicitSelf, ImplicitSelf) | (Err, Err) | (CVarArgs, CVarArgs) => true,
429 (Slice(l), Slice(r)) => eq_ty(l, r),
430 (Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value),
431 (Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty),
432 (Rptr(ll, l), Rptr(rl, r)) => {
433 both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
435 (BareFn(l), BareFn(r)) => {
436 l.unsafety == r.unsafety
437 && eq_ext(&l.ext, &r.ext)
438 && over(&l.generic_params, &r.generic_params, |l, r| eq_generic_param(l, r))
439 && eq_fn_decl(&l.decl, &r.decl)
441 (Tup(l), Tup(r)) => over(l, r, |l, r| eq_ty(l, r)),
442 (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
443 (TraitObject(lg, ls), TraitObject(rg, rs)) => ls == rs && over(lg, rg, |l, r| eq_generic_bound(l, r)),
444 (ImplTrait(_, lg), ImplTrait(_, rg)) => over(lg, rg, |l, r| eq_generic_bound(l, r)),
445 (Typeof(l), Typeof(r)) => eq_expr(&l.value, &r.value),
446 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
451 pub fn eq_ext(l: &Extern, r: &Extern) -> bool {
454 (None, None) | (Implicit, Implicit) => true,
455 (Explicit(l), Explicit(r)) => eq_str_lit(l, r),
460 pub fn eq_str_lit(l: &StrLit, r: &StrLit) -> bool {
461 l.style == r.style && l.symbol == r.symbol && l.suffix == r.suffix
464 pub fn eq_poly_ref_trait(l: &PolyTraitRef, r: &PolyTraitRef) -> bool {
465 eq_path(&l.trait_ref.path, &r.trait_ref.path)
466 && over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
467 eq_generic_param(l, r)
471 pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
472 use GenericParamKind::*;
473 l.is_placeholder == r.is_placeholder
474 && eq_id(l.ident, r.ident)
475 && over(&l.bounds, &r.bounds, |l, r| eq_generic_bound(l, r))
476 && match (&l.kind, &r.kind) {
477 (Lifetime, Lifetime) => true,
478 (Type { default: l }, Type { default: r }) => both(l, r, |l, r| eq_ty(l, r)),
479 (Const { ty: l, kw_span: _ }, Const { ty: r, kw_span: _ }) => eq_ty(l, r),
482 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
485 pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
488 (Trait(ptr1, tbm1), Trait(ptr2, tbm2)) => tbm1 == tbm2 && eq_poly_ref_trait(ptr1, ptr2),
489 (Outlives(l), Outlives(r)) => eq_id(l.ident, r.ident),
494 pub fn eq_assoc_constraint(l: &AssocTyConstraint, r: &AssocTyConstraint) -> bool {
495 use AssocTyConstraintKind::*;
496 eq_id(l.ident, r.ident)
497 && match (&l.kind, &r.kind) {
498 (Equality { ty: l }, Equality { ty: r }) => eq_ty(l, r),
499 (Bound { bounds: l }, Bound { bounds: r }) => over(l, r, |l, r| eq_generic_bound(l, r)),
504 pub fn eq_mac_call(l: &MacCall, r: &MacCall) -> bool {
505 eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args)
508 pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool {
511 && match (&l.kind, &r.kind) {
512 (DocComment(l), DocComment(r)) => l == r,
513 (Normal(l), Normal(r)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args),
518 pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool {
521 (Empty, Empty) => true,
522 (Delimited(_, ld, lts), Delimited(_, rd, rts)) => ld == rd && lts.eq_unspanned(rts),
523 (Eq(_, lts), Eq(_, rts)) => lts.eq_unspanned(rts),