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::{both, over};
9 use rustc_ast::{self as ast, *};
10 use rustc_span::symbol::Ident;
14 pub use ident_iter::IdentIter;
16 pub fn is_useless_with_eq_exprs(kind: BinOpKind) -> bool {
20 Sub | Div | Eq | Lt | Le | Gt | Ge | Ne | And | Or | BitXor | BitAnd | BitOr
24 /// Checks if each element in the first slice is contained within the latter as per `eq_fn`.
25 pub fn unordered_over<X>(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) -> bool {
26 left.len() == right.len() && left.iter().all(|l| right.iter().any(|r| eq_fn(l, r)))
29 pub fn eq_id(l: Ident, r: Ident) -> bool {
33 pub fn eq_pat(l: &Pat, r: &Pat) -> bool {
35 match (&l.kind, &r.kind) {
36 (Paren(l), _) => eq_pat(l, r),
37 (_, Paren(r)) => eq_pat(l, r),
38 (Wild, Wild) | (Rest, Rest) => true,
39 (Lit(l), Lit(r)) => eq_expr(l, r),
40 (Ident(b1, i1, s1), Ident(b2, i2, s2)) => b1 == b2 && eq_id(*i1, *i2) && both(s1, s2, |l, r| eq_pat(l, r)),
41 (Range(lf, lt, le), Range(rf, rt, re)) => {
42 eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt) && eq_range_end(&le.node, &re.node)
45 | (Ref(l, Mutability::Not), Ref(r, Mutability::Not))
46 | (Ref(l, Mutability::Mut), Ref(r, Mutability::Mut)) => eq_pat(l, r),
47 (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, |l, r| eq_pat(l, r)),
48 (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
49 (TupleStruct(lp, lfs), TupleStruct(rp, rfs)) => eq_path(lp, rp) && over(lfs, rfs, |l, r| eq_pat(l, r)),
50 (Struct(lp, lfs, lr), Struct(rp, rfs, rr)) => {
51 lr == rr && eq_path(lp, rp) && unordered_over(lfs, rfs, |lf, rf| eq_field_pat(lf, rf))
53 (Or(ls), Or(rs)) => unordered_over(ls, rs, |l, r| eq_pat(l, r)),
54 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
59 pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool {
61 (RangeEnd::Excluded, RangeEnd::Excluded) => true,
62 (RangeEnd::Included(l), RangeEnd::Included(r)) => {
63 matches!(l, RangeSyntax::DotDotEq) == matches!(r, RangeSyntax::DotDotEq)
69 pub fn eq_field_pat(l: &FieldPat, r: &FieldPat) -> bool {
70 l.is_placeholder == r.is_placeholder
71 && eq_id(l.ident, r.ident)
72 && eq_pat(&l.pat, &r.pat)
73 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
76 pub fn eq_qself(l: &QSelf, r: &QSelf) -> bool {
77 l.position == r.position && eq_ty(&l.ty, &r.ty)
80 pub fn eq_path(l: &Path, r: &Path) -> bool {
81 over(&l.segments, &r.segments, |l, r| eq_path_seg(l, r))
84 pub fn eq_path_seg(l: &PathSegment, r: &PathSegment) -> bool {
85 eq_id(l.ident, r.ident) && both(&l.args, &r.args, |l, r| eq_generic_args(l, r))
88 pub fn eq_generic_args(l: &GenericArgs, r: &GenericArgs) -> bool {
90 (GenericArgs::AngleBracketed(l), GenericArgs::AngleBracketed(r)) => {
91 over(&l.args, &r.args, |l, r| eq_angle_arg(l, r))
93 (GenericArgs::Parenthesized(l), GenericArgs::Parenthesized(r)) => {
94 over(&l.inputs, &r.inputs, |l, r| eq_ty(l, r)) && eq_fn_ret_ty(&l.output, &r.output)
100 pub fn eq_angle_arg(l: &AngleBracketedArg, r: &AngleBracketedArg) -> bool {
102 (AngleBracketedArg::Arg(l), AngleBracketedArg::Arg(r)) => eq_generic_arg(l, r),
103 (AngleBracketedArg::Constraint(l), AngleBracketedArg::Constraint(r)) => eq_assoc_constraint(l, r),
108 pub fn eq_generic_arg(l: &GenericArg, r: &GenericArg) -> bool {
110 (GenericArg::Lifetime(l), GenericArg::Lifetime(r)) => eq_id(l.ident, r.ident),
111 (GenericArg::Type(l), GenericArg::Type(r)) => eq_ty(l, r),
112 (GenericArg::Const(l), GenericArg::Const(r)) => eq_expr(&l.value, &r.value),
117 pub fn eq_expr_opt(l: &Option<P<Expr>>, r: &Option<P<Expr>>) -> bool {
118 both(l, r, |l, r| eq_expr(l, r))
121 pub fn eq_struct_rest(l: &StructRest, r: &StructRest) -> bool {
123 (StructRest::Base(lb), StructRest::Base(rb)) => eq_expr(lb, rb),
124 (StructRest::Rest(_), StructRest::Rest(_)) | (StructRest::None, StructRest::None) => true,
129 pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
131 if !over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) {
134 match (&l.kind, &r.kind) {
135 (Paren(l), _) => eq_expr(l, r),
136 (_, Paren(r)) => eq_expr(l, r),
138 (Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
139 (Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
140 (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
141 (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
142 (MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
143 (Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
144 (Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
145 (Lit(l), Lit(r)) => l.kind == r.kind,
146 (Cast(l, lt), Cast(r, rt)) | (Type(l, lt), Type(r, rt)) => eq_expr(l, r) && eq_ty(lt, rt),
147 (Let(lp, le), Let(rp, re)) => eq_pat(lp, rp) && eq_expr(le, re),
148 (If(lc, lt, le), If(rc, rt, re)) => eq_expr(lc, rc) && eq_block(lt, rt) && eq_expr_opt(le, re),
149 (While(lc, lt, ll), While(rc, rt, rl)) => eq_label(ll, rl) && eq_expr(lc, rc) && eq_block(lt, rt),
150 (ForLoop(lp, li, lt, ll), ForLoop(rp, ri, rt, rl)) => {
151 eq_label(ll, rl) && eq_pat(lp, rp) && eq_expr(li, ri) && eq_block(lt, rt)
153 (Loop(lt, ll), Loop(rt, rl)) => eq_label(ll, rl) && eq_block(lt, rt),
154 (Block(lb, ll), Block(rb, rl)) => eq_label(ll, rl) && eq_block(lb, rb),
155 (TryBlock(l), TryBlock(r)) => eq_block(l, r),
156 (Yield(l), Yield(r)) | (Ret(l), Ret(r)) => eq_expr_opt(l, r),
157 (Break(ll, le), Break(rl, re)) => eq_label(ll, rl) && eq_expr_opt(le, re),
158 (Continue(ll), Continue(rl)) => eq_label(ll, rl),
159 (Assign(l1, l2, _), Assign(r1, r2, _)) | (Index(l1, l2), Index(r1, r2)) => eq_expr(l1, r1) && eq_expr(l2, r2),
160 (AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv),
161 (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp),
162 (Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, |l, r| eq_arm(l, r)),
163 (Closure(lc, la, lm, lf, lb, _), Closure(rc, ra, rm, rf, rb, _)) => {
164 lc == rc && la.is_async() == ra.is_async() && lm == rm && eq_fn_decl(lf, rf) && eq_expr(lb, rb)
166 (Async(lc, _, lb), Async(rc, _, rb)) => lc == rc && eq_block(lb, rb),
167 (Range(lf, lt, ll), Range(rf, rt, rl)) => ll == rl && eq_expr_opt(lf, rf) && eq_expr_opt(lt, rt),
168 (AddrOf(lbk, lm, le), AddrOf(rbk, rm, re)) => lbk == rbk && lm == rm && eq_expr(le, re),
169 (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
170 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
171 (Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => {
172 eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r))
178 pub fn eq_field(l: &Field, r: &Field) -> bool {
179 l.is_placeholder == r.is_placeholder
180 && eq_id(l.ident, r.ident)
181 && eq_expr(&l.expr, &r.expr)
182 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
185 pub fn eq_arm(l: &Arm, r: &Arm) -> bool {
186 l.is_placeholder == r.is_placeholder
187 && eq_pat(&l.pat, &r.pat)
188 && eq_expr(&l.body, &r.body)
189 && eq_expr_opt(&l.guard, &r.guard)
190 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
193 pub fn eq_label(l: &Option<Label>, r: &Option<Label>) -> bool {
194 both(l, r, |l, r| eq_id(l.ident, r.ident))
197 pub fn eq_block(l: &Block, r: &Block) -> bool {
198 l.rules == r.rules && over(&l.stmts, &r.stmts, |l, r| eq_stmt(l, r))
201 pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
203 match (&l.kind, &r.kind) {
204 (Local(l), Local(r)) => {
205 eq_pat(&l.pat, &r.pat)
206 && both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
207 && eq_expr_opt(&l.init, &r.init)
208 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
210 (Item(l), Item(r)) => eq_item(l, r, eq_item_kind),
211 (Expr(l), Expr(r)) | (Semi(l), Semi(r)) => eq_expr(l, r),
212 (Empty, Empty) => true,
213 (MacCall(l), MacCall(r)) => {
214 l.style == r.style && eq_mac_call(&l.mac, &r.mac) && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
220 pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> bool) -> bool {
221 eq_id(l.ident, r.ident)
222 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
223 && eq_vis(&l.vis, &r.vis)
224 && eq_kind(&l.kind, &r.kind)
227 pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
230 (ExternCrate(l), ExternCrate(r)) => l == r,
231 (Use(l), Use(r)) => eq_use_tree(l, r),
232 (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
233 (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
234 (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
235 eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
237 (Mod(l), Mod(r)) => l.inline == r.inline && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_item_kind)),
238 (ForeignMod(l), ForeignMod(r)) => {
239 both(&l.abi, &r.abi, |l, r| eq_str_lit(l, r))
240 && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind))
242 (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => {
243 eq_defaultness(*ld, *rd)
244 && eq_generics(lg, rg)
245 && over(lb, rb, |l, r| eq_generic_bound(l, r))
246 && both(lt, rt, |l, r| eq_ty(l, r))
248 (Enum(le, lg), Enum(re, rg)) => {
249 over(&le.variants, &re.variants, |l, r| eq_variant(l, r)) && eq_generics(lg, rg)
251 (Struct(lv, lg), Struct(rv, rg)) | (Union(lv, lg), Union(rv, rg)) => {
252 eq_variant_data(lv, rv) && eq_generics(lg, rg)
254 (Trait(box TraitKind(la, lu, lg, lb, li)), Trait(box TraitKind(ra, ru, rg, rb, ri))) => {
256 && matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
257 && eq_generics(lg, rg)
258 && over(lb, rb, |l, r| eq_generic_bound(l, r))
259 && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind))
261 (TraitAlias(lg, lb), TraitAlias(rg, rb)) => eq_generics(lg, rg) && over(lb, rb, |l, r| eq_generic_bound(l, r)),
284 matches!(lu, Unsafe::No) == matches!(ru, Unsafe::No)
285 && matches!(lp, ImplPolarity::Positive) == matches!(rp, ImplPolarity::Positive)
286 && eq_defaultness(*ld, *rd)
287 && matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
288 && eq_generics(lg, rg)
289 && both(lot, rot, |l, r| eq_path(&l.path, &r.path))
291 && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind))
293 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
294 (MacroDef(l), MacroDef(r)) => l.macro_rules == r.macro_rules && eq_mac_args(&l.body, &r.body),
299 pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
300 use ForeignItemKind::*;
302 (Static(lt, lm, le), Static(rt, rm, re)) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
303 (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
304 eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
306 (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => {
307 eq_defaultness(*ld, *rd)
308 && eq_generics(lg, rg)
309 && over(lb, rb, |l, r| eq_generic_bound(l, r))
310 && both(lt, rt, |l, r| eq_ty(l, r))
312 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
317 pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
318 use AssocItemKind::*;
320 (Const(ld, lt, le), Const(rd, rt, re)) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
321 (Fn(box FnKind(ld, lf, lg, lb)), Fn(box FnKind(rd, rf, rg, rb))) => {
322 eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
324 (TyAlias(box TyAliasKind(ld, lg, lb, lt)), TyAlias(box TyAliasKind(rd, rg, rb, rt))) => {
325 eq_defaultness(*ld, *rd)
326 && eq_generics(lg, rg)
327 && over(lb, rb, |l, r| eq_generic_bound(l, r))
328 && both(lt, rt, |l, r| eq_ty(l, r))
330 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
335 pub fn eq_variant(l: &Variant, r: &Variant) -> bool {
336 l.is_placeholder == r.is_placeholder
337 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
338 && eq_vis(&l.vis, &r.vis)
339 && eq_id(l.ident, r.ident)
340 && eq_variant_data(&l.data, &r.data)
341 && both(&l.disr_expr, &r.disr_expr, |l, r| eq_expr(&l.value, &r.value))
344 pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool {
347 (Unit(_), Unit(_)) => true,
348 (Struct(l, _), Struct(r, _)) | (Tuple(l, _), Tuple(r, _)) => over(l, r, |l, r| eq_struct_field(l, r)),
353 pub fn eq_struct_field(l: &StructField, r: &StructField) -> bool {
354 l.is_placeholder == r.is_placeholder
355 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
356 && eq_vis(&l.vis, &r.vis)
357 && both(&l.ident, &r.ident, |l, r| eq_id(*l, *r))
358 && eq_ty(&l.ty, &r.ty)
361 pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool {
362 eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header)
365 pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
366 matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No)
367 && l.asyncness.is_async() == r.asyncness.is_async()
368 && matches!(l.constness, Const::No) == matches!(r.constness, Const::No)
369 && eq_ext(&l.ext, &r.ext)
372 pub fn eq_generics(l: &Generics, r: &Generics) -> bool {
373 over(&l.params, &r.params, |l, r| eq_generic_param(l, r))
374 && over(&l.where_clause.predicates, &r.where_clause.predicates, |l, r| {
375 eq_where_predicate(l, r)
379 pub fn eq_where_predicate(l: &WherePredicate, r: &WherePredicate) -> bool {
380 use WherePredicate::*;
382 (BoundPredicate(l), BoundPredicate(r)) => {
383 over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
384 eq_generic_param(l, r)
385 }) && eq_ty(&l.bounded_ty, &r.bounded_ty)
386 && over(&l.bounds, &r.bounds, |l, r| eq_generic_bound(l, r))
388 (RegionPredicate(l), RegionPredicate(r)) => {
389 eq_id(l.lifetime.ident, r.lifetime.ident) && over(&l.bounds, &r.bounds, |l, r| eq_generic_bound(l, r))
391 (EqPredicate(l), EqPredicate(r)) => eq_ty(&l.lhs_ty, &r.lhs_ty) && eq_ty(&l.rhs_ty, &r.rhs_ty),
396 pub fn eq_use_tree(l: &UseTree, r: &UseTree) -> bool {
397 eq_path(&l.prefix, &r.prefix) && eq_use_tree_kind(&l.kind, &r.kind)
400 pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
403 (Glob, Glob) => true,
404 (Simple(l, _, _), Simple(r, _, _)) => both(l, r, |l, r| eq_id(*l, *r)),
405 (Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
410 pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool {
411 eq_expr(&l.value, &r.value)
414 pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
417 (Defaultness::Final, Defaultness::Final) | (Defaultness::Default(_), Defaultness::Default(_))
421 pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
422 use VisibilityKind::*;
423 match (&l.kind, &r.kind) {
424 (Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
425 (Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
430 pub fn eq_fn_decl(l: &FnDecl, r: &FnDecl) -> bool {
431 eq_fn_ret_ty(&l.output, &r.output)
432 && over(&l.inputs, &r.inputs, |l, r| {
433 l.is_placeholder == r.is_placeholder
434 && eq_pat(&l.pat, &r.pat)
435 && eq_ty(&l.ty, &r.ty)
436 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
440 pub fn eq_fn_ret_ty(l: &FnRetTy, r: &FnRetTy) -> bool {
442 (FnRetTy::Default(_), FnRetTy::Default(_)) => true,
443 (FnRetTy::Ty(l), FnRetTy::Ty(r)) => eq_ty(l, r),
448 pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
450 match (&l.kind, &r.kind) {
451 (Paren(l), _) => eq_ty(l, r),
452 (_, Paren(r)) => eq_ty(l, r),
453 (Never, Never) | (Infer, Infer) | (ImplicitSelf, ImplicitSelf) | (Err, Err) | (CVarArgs, CVarArgs) => true,
454 (Slice(l), Slice(r)) => eq_ty(l, r),
455 (Array(le, ls), Array(re, rs)) => eq_ty(le, re) && eq_expr(&ls.value, &rs.value),
456 (Ptr(l), Ptr(r)) => l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty),
457 (Rptr(ll, l), Rptr(rl, r)) => {
458 both(ll, rl, |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
460 (BareFn(l), BareFn(r)) => {
461 l.unsafety == r.unsafety
462 && eq_ext(&l.ext, &r.ext)
463 && over(&l.generic_params, &r.generic_params, |l, r| eq_generic_param(l, r))
464 && eq_fn_decl(&l.decl, &r.decl)
466 (Tup(l), Tup(r)) => over(l, r, |l, r| eq_ty(l, r)),
467 (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
468 (TraitObject(lg, ls), TraitObject(rg, rs)) => ls == rs && over(lg, rg, |l, r| eq_generic_bound(l, r)),
469 (ImplTrait(_, lg), ImplTrait(_, rg)) => over(lg, rg, |l, r| eq_generic_bound(l, r)),
470 (Typeof(l), Typeof(r)) => eq_expr(&l.value, &r.value),
471 (MacCall(l), MacCall(r)) => eq_mac_call(l, r),
476 pub fn eq_ext(l: &Extern, r: &Extern) -> bool {
479 (None, None) | (Implicit, Implicit) => true,
480 (Explicit(l), Explicit(r)) => eq_str_lit(l, r),
485 pub fn eq_str_lit(l: &StrLit, r: &StrLit) -> bool {
486 l.style == r.style && l.symbol == r.symbol && l.suffix == r.suffix
489 pub fn eq_poly_ref_trait(l: &PolyTraitRef, r: &PolyTraitRef) -> bool {
490 eq_path(&l.trait_ref.path, &r.trait_ref.path)
491 && over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
492 eq_generic_param(l, r)
496 pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
497 use GenericParamKind::*;
498 l.is_placeholder == r.is_placeholder
499 && eq_id(l.ident, r.ident)
500 && over(&l.bounds, &r.bounds, |l, r| eq_generic_bound(l, r))
501 && match (&l.kind, &r.kind) {
502 (Lifetime, Lifetime) => true,
503 (Type { default: l }, Type { default: r }) => both(l, r, |l, r| eq_ty(l, r)),
515 ) => eq_ty(lt, rt) && both(ld, rd, |ld, rd| eq_anon_const(ld, rd)),
518 && over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))
521 pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
524 (Trait(ptr1, tbm1), Trait(ptr2, tbm2)) => tbm1 == tbm2 && eq_poly_ref_trait(ptr1, ptr2),
525 (Outlives(l), Outlives(r)) => eq_id(l.ident, r.ident),
530 pub fn eq_assoc_constraint(l: &AssocTyConstraint, r: &AssocTyConstraint) -> bool {
531 use AssocTyConstraintKind::*;
532 eq_id(l.ident, r.ident)
533 && match (&l.kind, &r.kind) {
534 (Equality { ty: l }, Equality { ty: r }) => eq_ty(l, r),
535 (Bound { bounds: l }, Bound { bounds: r }) => over(l, r, |l, r| eq_generic_bound(l, r)),
540 pub fn eq_mac_call(l: &MacCall, r: &MacCall) -> bool {
541 eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args)
544 pub fn eq_attr(l: &Attribute, r: &Attribute) -> bool {
547 && match (&l.kind, &r.kind) {
548 (DocComment(l1, l2), DocComment(r1, r2)) => l1 == r1 && l2 == r2,
549 (Normal(l, _), Normal(r, _)) => eq_path(&l.path, &r.path) && eq_mac_args(&l.args, &r.args),
554 pub fn eq_mac_args(l: &MacArgs, r: &MacArgs) -> bool {
557 (Empty, Empty) => true,
558 (Delimited(_, ld, lts), Delimited(_, rd, rts)) => ld == rd && lts.eq_unspanned(rts),
559 (Eq(_, lt), Eq(_, rt)) => lt.kind == rt.kind,