1#![allow(unused_macro_rules)]
2
3extern crate rustc_ast;
4extern crate rustc_data_structures;
5extern crate rustc_span;
6extern crate thin_vec;
7
8use rustc_ast::ast::AngleBracketedArg;
9use rustc_ast::ast::AngleBracketedArgs;
10use rustc_ast::ast::AnonConst;
11use rustc_ast::ast::Arm;
12use rustc_ast::ast::AssocConstraint;
13use rustc_ast::ast::AssocConstraintKind;
14use rustc_ast::ast::AssocItemKind;
15use rustc_ast::ast::Async;
16use rustc_ast::ast::AttrArgs;
17use rustc_ast::ast::AttrArgsEq;
18use rustc_ast::ast::AttrId;
19use rustc_ast::ast::AttrItem;
20use rustc_ast::ast::AttrKind;
21use rustc_ast::ast::AttrStyle;
22use rustc_ast::ast::Attribute;
23use rustc_ast::ast::BareFnTy;
24use rustc_ast::ast::BinOpKind;
25use rustc_ast::ast::BindingAnnotation;
26use rustc_ast::ast::Block;
27use rustc_ast::ast::BlockCheckMode;
28use rustc_ast::ast::BorrowKind;
29use rustc_ast::ast::ByRef;
30use rustc_ast::ast::CaptureBy;
31use rustc_ast::ast::Closure;
32use rustc_ast::ast::ClosureBinder;
33use rustc_ast::ast::Const;
34use rustc_ast::ast::Crate;
35use rustc_ast::ast::Defaultness;
36use rustc_ast::ast::DelimArgs;
37use rustc_ast::ast::EnumDef;
38use rustc_ast::ast::Expr;
39use rustc_ast::ast::ExprField;
40use rustc_ast::ast::ExprKind;
41use rustc_ast::ast::Extern;
42use rustc_ast::ast::FieldDef;
43use rustc_ast::ast::FloatTy;
44use rustc_ast::ast::Fn;
45use rustc_ast::ast::FnDecl;
46use rustc_ast::ast::FnHeader;
47use rustc_ast::ast::FnRetTy;
48use rustc_ast::ast::FnSig;
49use rustc_ast::ast::ForeignItemKind;
50use rustc_ast::ast::ForeignMod;
51use rustc_ast::ast::GenericArg;
52use rustc_ast::ast::GenericArgs;
53use rustc_ast::ast::GenericBound;
54use rustc_ast::ast::GenericParam;
55use rustc_ast::ast::GenericParamKind;
56use rustc_ast::ast::Generics;
57use rustc_ast::ast::Impl;
58use rustc_ast::ast::ImplPolarity;
59use rustc_ast::ast::Inline;
60use rustc_ast::ast::InlineAsm;
61use rustc_ast::ast::InlineAsmOperand;
62use rustc_ast::ast::InlineAsmOptions;
63use rustc_ast::ast::InlineAsmRegOrRegClass;
64use rustc_ast::ast::InlineAsmSym;
65use rustc_ast::ast::InlineAsmTemplatePiece;
66use rustc_ast::ast::IntTy;
67use rustc_ast::ast::IsAuto;
68use rustc_ast::ast::Item;
69use rustc_ast::ast::ItemKind;
70use rustc_ast::ast::Label;
71use rustc_ast::ast::Lifetime;
72use rustc_ast::ast::LitFloatType;
73use rustc_ast::ast::LitIntType;
74use rustc_ast::ast::LitKind;
75use rustc_ast::ast::Local;
76use rustc_ast::ast::LocalKind;
77use rustc_ast::ast::MacCall;
78use rustc_ast::ast::MacCallStmt;
79use rustc_ast::ast::MacDelimiter;
80use rustc_ast::ast::MacStmtStyle;
81use rustc_ast::ast::MacroDef;
82use rustc_ast::ast::MetaItemLit;
83use rustc_ast::ast::MethodCall;
84use rustc_ast::ast::ModKind;
85use rustc_ast::ast::ModSpans;
86use rustc_ast::ast::Movability;
87use rustc_ast::ast::MutTy;
88use rustc_ast::ast::Mutability;
89use rustc_ast::ast::NodeId;
90use rustc_ast::ast::NormalAttr;
91use rustc_ast::ast::Param;
92use rustc_ast::ast::ParenthesizedArgs;
93use rustc_ast::ast::Pat;
94use rustc_ast::ast::PatField;
95use rustc_ast::ast::PatKind;
96use rustc_ast::ast::Path;
97use rustc_ast::ast::PathSegment;
98use rustc_ast::ast::PolyTraitRef;
99use rustc_ast::ast::QSelf;
100use rustc_ast::ast::RangeEnd;
101use rustc_ast::ast::RangeLimits;
102use rustc_ast::ast::RangeSyntax;
103use rustc_ast::ast::Stmt;
104use rustc_ast::ast::StmtKind;
105use rustc_ast::ast::StrLit;
106use rustc_ast::ast::StrStyle;
107use rustc_ast::ast::StructExpr;
108use rustc_ast::ast::StructRest;
109use rustc_ast::ast::Term;
110use rustc_ast::ast::Trait;
111use rustc_ast::ast::TraitBoundModifier;
112use rustc_ast::ast::TraitObjectSyntax;
113use rustc_ast::ast::TraitRef;
114use rustc_ast::ast::Ty;
115use rustc_ast::ast::TyAlias;
116use rustc_ast::ast::TyAliasWhereClause;
117use rustc_ast::ast::TyKind;
118use rustc_ast::ast::UintTy;
119use rustc_ast::ast::UnOp;
120use rustc_ast::ast::Unsafe;
121use rustc_ast::ast::UnsafeSource;
122use rustc_ast::ast::UseTree;
123use rustc_ast::ast::UseTreeKind;
124use rustc_ast::ast::Variant;
125use rustc_ast::ast::VariantData;
126use rustc_ast::ast::Visibility;
127use rustc_ast::ast::VisibilityKind;
128use rustc_ast::ast::WhereBoundPredicate;
129use rustc_ast::ast::WhereClause;
130use rustc_ast::ast::WhereEqPredicate;
131use rustc_ast::ast::WherePredicate;
132use rustc_ast::ast::WhereRegionPredicate;
133use rustc_ast::ptr::P;
134use rustc_ast::token::{self, CommentKind, Delimiter, Lit, Nonterminal, Token, TokenKind};
135use rustc_ast::tokenstream::{
136 AttrTokenStream, AttrTokenTree, AttributesData, DelimSpan, LazyAttrTokenStream, Spacing,
137 TokenStream, TokenTree,
138};
139use rustc_data_structures::sync::Lrc;
140use rustc_span::source_map::Spanned;
141use rustc_span::symbol::{sym, Ident};
142use rustc_span::{Span, Symbol, SyntaxContext, DUMMY_SP};
143use thin_vec::ThinVec;
144
145pub trait SpanlessEq {
146 fn eq(&self, other: &Self) -> bool;
147}
148
149impl<T: ?Sized + SpanlessEq> SpanlessEq for Box<T> {
150 fn eq(&self, other: &Self) -> bool {
151 SpanlessEq::eq(&**self, &**other)
152 }
153}
154
155impl<T: ?Sized + SpanlessEq> SpanlessEq for P<T> {
156 fn eq(&self, other: &Self) -> bool {
157 SpanlessEq::eq(&**self, &**other)
158 }
159}
160
161impl<T: ?Sized + SpanlessEq> SpanlessEq for Lrc<T> {
162 fn eq(&self, other: &Self) -> bool {
163 SpanlessEq::eq(&**self, &**other)
164 }
165}
166
167impl<T: SpanlessEq> SpanlessEq for Option<T> {
168 fn eq(&self, other: &Self) -> bool {
169 match (self, other) {
170 (None, None) => true,
171 (Some(this), Some(other)) => SpanlessEq::eq(this, other),
172 _ => false,
173 }
174 }
175}
176
177impl<T: SpanlessEq> SpanlessEq for [T] {
178 fn eq(&self, other: &Self) -> bool {
179 self.len() == other.len() && self.iter().zip(other).all(|(a, b)| SpanlessEq::eq(a, b))
180 }
181}
182
183impl<T: SpanlessEq> SpanlessEq for Vec<T> {
184 fn eq(&self, other: &Self) -> bool {
185 <[T] as SpanlessEq>::eq(self, other)
186 }
187}
188
189impl<T: SpanlessEq> SpanlessEq for ThinVec<T> {
190 fn eq(&self, other: &Self) -> bool {
191 self.len() == other.len()
192 && self
193 .iter()
194 .zip(other.iter())
195 .all(|(a, b)| SpanlessEq::eq(a, b))
196 }
197}
198
199impl<T: SpanlessEq> SpanlessEq for Spanned<T> {
200 fn eq(&self, other: &Self) -> bool {
201 SpanlessEq::eq(&self.node, &other.node)
202 }
203}
204
205impl<A: SpanlessEq, B: SpanlessEq> SpanlessEq for (A, B) {
206 fn eq(&self, other: &Self) -> bool {
207 SpanlessEq::eq(&self.0, &other.0) && SpanlessEq::eq(&self.1, &other.1)
208 }
209}
210
211impl<A: SpanlessEq, B: SpanlessEq, C: SpanlessEq> SpanlessEq for (A, B, C) {
212 fn eq(&self, other: &Self) -> bool {
213 SpanlessEq::eq(&self.0, &other.0)
214 && SpanlessEq::eq(&self.1, &other.1)
215 && SpanlessEq::eq(&self.2, &other.2)
216 }
217}
218
219macro_rules! spanless_eq_true {
220 ($name:ty) => {
221 impl SpanlessEq for $name {
222 fn eq(&self, _other: &Self) -> bool {
223 true
224 }
225 }
226 };
227}
228
229spanless_eq_true!(Span);
230spanless_eq_true!(DelimSpan);
231spanless_eq_true!(AttrId);
232spanless_eq_true!(NodeId);
233spanless_eq_true!(SyntaxContext);
234spanless_eq_true!(Spacing);
235
236macro_rules! spanless_eq_partial_eq {
237 ($name:ty) => {
238 impl SpanlessEq for $name {
239 fn eq(&self, other: &Self) -> bool {
240 PartialEq::eq(self, other)
241 }
242 }
243 };
244}
245
246spanless_eq_partial_eq!(bool);
247spanless_eq_partial_eq!(u8);
248spanless_eq_partial_eq!(u16);
249spanless_eq_partial_eq!(u128);
250spanless_eq_partial_eq!(usize);
251spanless_eq_partial_eq!(char);
252spanless_eq_partial_eq!(String);
253spanless_eq_partial_eq!(Symbol);
254spanless_eq_partial_eq!(CommentKind);
255spanless_eq_partial_eq!(Delimiter);
256spanless_eq_partial_eq!(InlineAsmOptions);
257spanless_eq_partial_eq!(token::LitKind);
258
259macro_rules! spanless_eq_struct {
260 {
261 $($name:ident)::+ $(<$param:ident>)?
262 $([$field:tt $this:ident $other:ident])*
263 $(![$ignore:tt])*;
264 } => {
265 impl $(<$param: SpanlessEq>)* SpanlessEq for $($name)::+ $(<$param>)* {
266 fn eq(&self, other: &Self) -> bool {
267 let $($name)::+ { $($field: $this,)* $($ignore: _,)* } = self;
268 let $($name)::+ { $($field: $other,)* $($ignore: _,)* } = other;
269 true $(&& SpanlessEq::eq($this, $other))*
270 }
271 }
272 };
273
274 {
275 $($name:ident)::+ $(<$param:ident>)?
276 $([$field:tt $this:ident $other:ident])*
277 $(![$ignore:tt])*;
278 !$next:tt
279 $($rest:tt)*
280 } => {
281 spanless_eq_struct! {
282 $($name)::+ $(<$param>)*
283 $([$field $this $other])*
284 $(![$ignore])*
285 ![$next];
286 $($rest)*
287 }
288 };
289
290 {
291 $($name:ident)::+ $(<$param:ident>)?
292 $([$field:tt $this:ident $other:ident])*
293 $(![$ignore:tt])*;
294 $next:tt
295 $($rest:tt)*
296 } => {
297 spanless_eq_struct! {
298 $($name)::+ $(<$param>)*
299 $([$field $this $other])*
300 [$next this other]
301 $(![$ignore])*;
302 $($rest)*
303 }
304 };
305}
306
307macro_rules! spanless_eq_enum {
308 {
309 $($name:ident)::+;
310 $([$($variant:ident)::+; $([$field:tt $this:ident $other:ident])* $(![$ignore:tt])*])*
311 } => {
312 impl SpanlessEq for $($name)::+ {
313 fn eq(&self, other: &Self) -> bool {
314 match self {
315 $(
316 $($variant)::+ { .. } => {}
317 )*
318 }
319 #[allow(unreachable_patterns)]
320 match (self, other) {
321 $(
322 (
323 $($variant)::+ { $($field: $this,)* $($ignore: _,)* },
324 $($variant)::+ { $($field: $other,)* $($ignore: _,)* },
325 ) => {
326 true $(&& SpanlessEq::eq($this, $other))*
327 }
328 )*
329 _ => false,
330 }
331 }
332 }
333 };
334
335 {
336 $($name:ident)::+;
337 $([$($variant:ident)::+; $($fields:tt)*])*
338 $next:ident [$([$($named:tt)*])* $(![$ignore:tt])*] (!$i:tt $($field:tt)*)
339 $($rest:tt)*
340 } => {
341 spanless_eq_enum! {
342 $($name)::+;
343 $([$($variant)::+; $($fields)*])*
344 $next [$([$($named)*])* $(![$ignore])* ![$i]] ($($field)*)
345 $($rest)*
346 }
347 };
348
349 {
350 $($name:ident)::+;
351 $([$($variant:ident)::+; $($fields:tt)*])*
352 $next:ident [$([$($named:tt)*])* $(![$ignore:tt])*] ($i:tt $($field:tt)*)
353 $($rest:tt)*
354 } => {
355 spanless_eq_enum! {
356 $($name)::+;
357 $([$($variant)::+; $($fields)*])*
358 $next [$([$($named)*])* [$i this other] $(![$ignore])*] ($($field)*)
359 $($rest)*
360 }
361 };
362
363 {
364 $($name:ident)::+;
365 $([$($variant:ident)::+; $($fields:tt)*])*
366 $next:ident [$($named:tt)*] ()
367 $($rest:tt)*
368 } => {
369 spanless_eq_enum! {
370 $($name)::+;
371 $([$($variant)::+; $($fields)*])*
372 [$($name)::+::$next; $($named)*]
373 $($rest)*
374 }
375 };
376
377 {
378 $($name:ident)::+;
379 $([$($variant:ident)::+; $($fields:tt)*])*
380 $next:ident ($($field:tt)*)
381 $($rest:tt)*
382 } => {
383 spanless_eq_enum! {
384 $($name)::+;
385 $([$($variant)::+; $($fields)*])*
386 $next [] ($($field)*)
387 $($rest)*
388 }
389 };
390
391 {
392 $($name:ident)::+;
393 $([$($variant:ident)::+; $($fields:tt)*])*
394 $next:ident
395 $($rest:tt)*
396 } => {
397 spanless_eq_enum! {
398 $($name)::+;
399 $([$($variant)::+; $($fields)*])*
400 [$($name)::+::$next;]
401 $($rest)*
402 }
403 };
404}
405
406spanless_eq_struct!(AngleBracketedArgs; span args);
407spanless_eq_struct!(AnonConst; id value);
408spanless_eq_struct!(Arm; attrs pat guard body span id is_placeholder);
409spanless_eq_struct!(AssocConstraint; id ident gen_args kind span);
410spanless_eq_struct!(AttrItem; path args tokens);
411spanless_eq_struct!(AttrTokenStream; 0);
412spanless_eq_struct!(Attribute; kind id style span);
413spanless_eq_struct!(AttributesData; attrs tokens);
414spanless_eq_struct!(BareFnTy; unsafety ext generic_params decl decl_span);
415spanless_eq_struct!(BindingAnnotation; 0 1);
416spanless_eq_struct!(Block; stmts id rules span tokens could_be_bare_literal);
417spanless_eq_struct!(Closure; binder capture_clause asyncness movability fn_decl body !fn_decl_span);
418spanless_eq_struct!(Crate; attrs items spans id is_placeholder);
419spanless_eq_struct!(DelimArgs; dspan delim tokens);
420spanless_eq_struct!(EnumDef; variants);
421spanless_eq_struct!(Expr; id kind span attrs !tokens);
422spanless_eq_struct!(ExprField; attrs id span ident expr is_shorthand is_placeholder);
423spanless_eq_struct!(FieldDef; attrs id span vis ident ty is_placeholder);
424spanless_eq_struct!(FnDecl; inputs output);
425spanless_eq_struct!(FnHeader; constness asyncness unsafety ext);
426spanless_eq_struct!(Fn; defaultness generics sig body);
427spanless_eq_struct!(FnSig; header decl span);
428spanless_eq_struct!(ForeignMod; unsafety abi items);
429spanless_eq_struct!(GenericParam; id ident attrs bounds is_placeholder kind !colon_span);
430spanless_eq_struct!(Generics; params where_clause span);
431spanless_eq_struct!(Impl; defaultness unsafety generics constness polarity of_trait self_ty items);
432spanless_eq_struct!(InlineAsm; template template_strs operands clobber_abis options line_spans);
433spanless_eq_struct!(InlineAsmSym; id qself path);
434spanless_eq_struct!(Item<K>; attrs id span vis ident kind !tokens);
435spanless_eq_struct!(Label; ident);
436spanless_eq_struct!(Lifetime; id ident);
437spanless_eq_struct!(Lit; kind symbol suffix);
438spanless_eq_struct!(Local; pat ty kind id span attrs !tokens);
439spanless_eq_struct!(MacCall; path args prior_type_ascription);
440spanless_eq_struct!(MacCallStmt; mac style attrs tokens);
441spanless_eq_struct!(MacroDef; body macro_rules);
442spanless_eq_struct!(MetaItemLit; token_lit kind span);
443spanless_eq_struct!(MethodCall; seg receiver args !span);
444spanless_eq_struct!(ModSpans; !inner_span !inject_use_span);
445spanless_eq_struct!(MutTy; ty mutbl);
446spanless_eq_struct!(NormalAttr; item tokens);
447spanless_eq_struct!(ParenthesizedArgs; span inputs inputs_span output);
448spanless_eq_struct!(Pat; id kind span tokens);
449spanless_eq_struct!(PatField; ident pat is_shorthand attrs id span is_placeholder);
450spanless_eq_struct!(Path; span segments tokens);
451spanless_eq_struct!(PathSegment; ident id args);
452spanless_eq_struct!(PolyTraitRef; bound_generic_params trait_ref span);
453spanless_eq_struct!(QSelf; ty path_span position);
454spanless_eq_struct!(Stmt; id kind span);
455spanless_eq_struct!(StrLit; style symbol suffix span symbol_unescaped);
456spanless_eq_struct!(StructExpr; qself path fields rest);
457spanless_eq_struct!(Token; kind span);
458spanless_eq_struct!(Trait; unsafety is_auto generics bounds items);
459spanless_eq_struct!(TraitRef; path ref_id);
460spanless_eq_struct!(Ty; id kind span tokens);
461spanless_eq_struct!(TyAlias; defaultness generics where_clauses !where_predicates_split bounds ty);
462spanless_eq_struct!(TyAliasWhereClause; !0 1);
463spanless_eq_struct!(UseTree; prefix kind span);
464spanless_eq_struct!(Variant; attrs id span !vis ident data disr_expr is_placeholder);
465spanless_eq_struct!(Visibility; kind span tokens);
466spanless_eq_struct!(WhereBoundPredicate; span bound_generic_params bounded_ty bounds);
467spanless_eq_struct!(WhereClause; has_where_token predicates span);
468spanless_eq_struct!(WhereEqPredicate; span lhs_ty rhs_ty);
469spanless_eq_struct!(WhereRegionPredicate; span lifetime bounds);
470spanless_eq_enum!(AngleBracketedArg; Arg(0) Constraint(0));
471spanless_eq_enum!(AssocItemKind; Const(0 1 2) Fn(0) Type(0) MacCall(0));
472spanless_eq_enum!(AssocConstraintKind; Equality(term) Bound(bounds));
473spanless_eq_enum!(Async; Yes(span closure_id return_impl_trait_id) No);
474spanless_eq_enum!(AttrArgs; Empty Delimited(0) Eq(0 1));
475spanless_eq_enum!(AttrArgsEq; Ast(0) Hir(0));
476spanless_eq_enum!(AttrStyle; Outer Inner);
477spanless_eq_enum!(AttrTokenTree; Token(0 1) Delimited(0 1 2) Attributes(0));
478spanless_eq_enum!(BinOpKind; Add Sub Mul Div Rem And Or BitXor BitAnd BitOr Shl Shr Eq Lt Le Ne Ge Gt);
479spanless_eq_enum!(BlockCheckMode; Default Unsafe(0));
480spanless_eq_enum!(BorrowKind; Ref Raw);
481spanless_eq_enum!(ByRef; Yes No);
482spanless_eq_enum!(CaptureBy; Value Ref);
483spanless_eq_enum!(ClosureBinder; NotPresent For(span generic_params));
484spanless_eq_enum!(Const; Yes(0) No);
485spanless_eq_enum!(Defaultness; Default(0) Final);
486spanless_eq_enum!(Extern; None Implicit(0) Explicit(0 1));
487spanless_eq_enum!(FloatTy; F32 F64);
488spanless_eq_enum!(FnRetTy; Default(0) Ty(0));
489spanless_eq_enum!(ForeignItemKind; Static(0 1 2) Fn(0) TyAlias(0) MacCall(0));
490spanless_eq_enum!(GenericArg; Lifetime(0) Type(0) Const(0));
491spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0));
492spanless_eq_enum!(GenericBound; Trait(0 1) Outlives(0));
493spanless_eq_enum!(GenericParamKind; Lifetime Type(default) Const(ty kw_span default));
494spanless_eq_enum!(ImplPolarity; Positive Negative(0));
495spanless_eq_enum!(Inline; Yes No);
496spanless_eq_enum!(InlineAsmRegOrRegClass; Reg(0) RegClass(0));
497spanless_eq_enum!(InlineAsmTemplatePiece; String(0) Placeholder(operand_idx modifier span));
498spanless_eq_enum!(IntTy; Isize I8 I16 I32 I64 I128);
499spanless_eq_enum!(IsAuto; Yes No);
500spanless_eq_enum!(LitFloatType; Suffixed(0) Unsuffixed);
501spanless_eq_enum!(LitIntType; Signed(0) Unsigned(0) Unsuffixed);
502spanless_eq_enum!(LocalKind; Decl Init(0) InitElse(0 1));
503spanless_eq_enum!(MacDelimiter; Parenthesis Bracket Brace);
504spanless_eq_enum!(MacStmtStyle; Semicolon Braces NoBraces);
505spanless_eq_enum!(ModKind; Loaded(0 1 2) Unloaded);
506spanless_eq_enum!(Movability; Static Movable);
507spanless_eq_enum!(Mutability; Mut Not);
508spanless_eq_enum!(RangeEnd; Included(0) Excluded);
509spanless_eq_enum!(RangeLimits; HalfOpen Closed);
510spanless_eq_enum!(StmtKind; Local(0) Item(0) Expr(0) Semi(0) Empty MacCall(0));
511spanless_eq_enum!(StrStyle; Cooked Raw(0));
512spanless_eq_enum!(StructRest; Base(0) Rest(0) None);
513spanless_eq_enum!(Term; Ty(0) Const(0));
514spanless_eq_enum!(TokenTree; Token(0 1) Delimited(0 1 2));
515spanless_eq_enum!(TraitBoundModifier; None Maybe MaybeConst MaybeConstMaybe);
516spanless_eq_enum!(TraitObjectSyntax; Dyn DynStar None);
517spanless_eq_enum!(UintTy; Usize U8 U16 U32 U64 U128);
518spanless_eq_enum!(UnOp; Deref Not Neg);
519spanless_eq_enum!(Unsafe; Yes(0) No);
520spanless_eq_enum!(UnsafeSource; CompilerGenerated UserProvided);
521spanless_eq_enum!(UseTreeKind; Simple(0) Nested(0) Glob);
522spanless_eq_enum!(VariantData; Struct(0 1) Tuple(0 1) Unit(0));
523spanless_eq_enum!(VisibilityKind; Public Restricted(path id shorthand) Inherited);
524spanless_eq_enum!(WherePredicate; BoundPredicate(0) RegionPredicate(0) EqPredicate(0));
525spanless_eq_enum!(ExprKind; Box(0) Array(0) ConstBlock(0) Call(0 1)
526 MethodCall(0) Tup(0) Binary(0 1 2) Unary(0 1) Lit(0) Cast(0 1) Type(0 1)
527 Let(0 1 2) If(0 1 2) While(0 1 2) ForLoop(0 1 2 3) Loop(0 1 2) Match(0 1)
528 Closure(0) Block(0 1) Async(0 1 2) Await(0) TryBlock(0) Assign(0 1 2)
529 AssignOp(0 1 2) Field(0 1) Index(0 1) Underscore Range(0 1 2) Path(0 1)
530 AddrOf(0 1 2) Break(0 1) Continue(0) Ret(0) InlineAsm(0) MacCall(0)
531 Struct(0) Repeat(0 1) Paren(0) Try(0) Yield(0) Yeet(0) IncludedBytes(0)
532 Err);
533spanless_eq_enum!(InlineAsmOperand; In(reg expr) Out(reg late expr)
534 InOut(reg late expr) SplitInOut(reg late in_expr out_expr) Const(anon_const)
535 Sym(sym));
536spanless_eq_enum!(ItemKind; ExternCrate(0) Use(0) Static(0 1 2) Const(0 1 2)
537 Fn(0) Mod(0 1) ForeignMod(0) GlobalAsm(0) TyAlias(0) Enum(0 1) Struct(0 1)
538 Union(0 1) Trait(0) TraitAlias(0 1) Impl(0) MacCall(0) MacroDef(0));
539spanless_eq_enum!(LitKind; Str(0 1) ByteStr(0) Byte(0) Char(0) Int(0 1)
540 Float(0 1) Bool(0) Err);
541spanless_eq_enum!(PatKind; Wild Ident(0 1 2) Struct(0 1 2 3) TupleStruct(0 1 2)
542 Or(0) Path(0 1) Tuple(0) Box(0) Ref(0 1) Lit(0) Range(0 1 2) Slice(0) Rest
543 Paren(0) MacCall(0));
544spanless_eq_enum!(TyKind; Slice(0) Array(0 1) Ptr(0) Rptr(0 1) BareFn(0) Never
545 Tup(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) Paren(0) Typeof(0) Infer
546 ImplicitSelf MacCall(0) Err CVarArgs);
547
548impl SpanlessEq for Ident {
549 fn eq(&self, other: &Self) -> bool {
550 self.as_str() == other.as_str()
551 }
552}
553
554impl SpanlessEq for RangeSyntax {
555 fn eq(&self, _other: &Self) -> bool {
556 match self {
557 RangeSyntax::DotDotDot | RangeSyntax::DotDotEq => true,
558 }
559 }
560}
561
562impl SpanlessEq for Param {
563 fn eq(&self, other: &Self) -> bool {
564 let Param {
565 attrs,
566 ty,
567 pat,
568 id,
569 span: _,
570 is_placeholder,
571 } = self;
572 let Param {
573 attrs: attrs2,
574 ty: ty2,
575 pat: pat2,
576 id: id2,
577 span: _,
578 is_placeholder: is_placeholder2,
579 } = other;
580 SpanlessEq::eq(id, id2)
581 && SpanlessEq::eq(is_placeholder, is_placeholder2)
582 && (matches!(ty.kind, TyKind::Err)
583 || matches!(ty2.kind, TyKind::Err)
584 || SpanlessEq::eq(attrs, attrs2)
585 && SpanlessEq::eq(ty, ty2)
586 && SpanlessEq::eq(pat, pat2))
587 }
588}
589
590impl SpanlessEq for TokenKind {
591 fn eq(&self, other: &Self) -> bool {
592 match (self, other) {
593 (TokenKind::Literal(this), TokenKind::Literal(other)) => SpanlessEq::eq(this, other),
594 (TokenKind::DotDotEq, _) | (TokenKind::DotDotDot, _) => match other {
595 TokenKind::DotDotEq | TokenKind::DotDotDot => true,
596 _ => false,
597 },
598 (TokenKind::Interpolated(this), TokenKind::Interpolated(other)) => {
599 match (this.as_ref(), other.as_ref()) {
600 (Nonterminal::NtExpr(this), Nonterminal::NtExpr(other)) => {
601 SpanlessEq::eq(this, other)
602 }
603 _ => this == other,
604 }
605 }
606 _ => self == other,
607 }
608 }
609}
610
611impl SpanlessEq for TokenStream {
612 fn eq(&self, other: &Self) -> bool {
613 let mut this_trees = self.trees();
614 let mut other_trees = other.trees();
615 loop {
616 let this = match this_trees.next() {
617 None => return other_trees.next().is_none(),
618 Some(tree) => tree,
619 };
620 let other = match other_trees.next() {
621 None => return false,
622 Some(tree) => tree,
623 };
624 if SpanlessEq::eq(this, other) {
625 continue;
626 }
627 if let (TokenTree::Token(this, _), TokenTree::Token(other, _)) = (this, other) {
628 if match (&this.kind, &other.kind) {
629 (TokenKind::Literal(this), TokenKind::Literal(other)) => {
630 SpanlessEq::eq(this, other)
631 }
632 (TokenKind::DocComment(_kind, style, symbol), TokenKind::Pound) => {
633 doc_comment(*style, *symbol, &mut other_trees)
634 }
635 (TokenKind::Pound, TokenKind::DocComment(_kind, style, symbol)) => {
636 doc_comment(*style, *symbol, &mut this_trees)
637 }
638 _ => false,
639 } {
640 continue;
641 }
642 }
643 return false;
644 }
645 }
646}
647
648fn doc_comment<'a>(
649 style: AttrStyle,
650 unescaped: Symbol,
651 trees: &mut impl Iterator<Item = &'a TokenTree>,
652) -> bool {
653 if match style {
654 AttrStyle::Outer => false,
655 AttrStyle::Inner => true,
656 } {
657 match trees.next() {
658 Some(TokenTree::Token(
659 Token {
660 kind: TokenKind::Not,
661 span: _,
662 },
663 _spacing,
664 )) => {}
665 _ => return false,
666 }
667 }
668 let stream = match trees.next() {
669 Some(TokenTree::Delimited(_span, Delimiter::Bracket, stream)) => stream,
670 _ => return false,
671 };
672 let mut trees = stream.trees();
673 match trees.next() {
674 Some(TokenTree::Token(
675 Token {
676 kind: TokenKind::Ident(symbol, false),
677 span: _,
678 },
679 _spacing,
680 )) if *symbol == sym::doc => {}
681 _ => return false,
682 }
683 match trees.next() {
684 Some(TokenTree::Token(
685 Token {
686 kind: TokenKind::Eq,
687 span: _,
688 },
689 _spacing,
690 )) => {}
691 _ => return false,
692 }
693 match trees.next() {
694 Some(TokenTree::Token(token, _spacing)) => {
695 is_escaped_literal_token(token, unescaped) && trees.next().is_none()
696 }
697 _ => false,
698 }
699}
700
701fn is_escaped_literal_token(token: &Token, unescaped: Symbol) -> bool {
702 match token {
703 Token {
704 kind: TokenKind::Literal(lit),
705 span: _,
706 } => match MetaItemLit::from_token_lit(*lit, DUMMY_SP) {
707 Ok(lit) => is_escaped_literal_meta_item_lit(&lit, unescaped),
708 Err(_) => false,
709 },
710 Token {
711 kind: TokenKind::Interpolated(nonterminal),
712 span: _,
713 } => match nonterminal.as_ref() {
714 Nonterminal::NtExpr(expr) => match &expr.kind {
715 ExprKind::Lit(lit) => is_escaped_lit(lit, unescaped),
716 _ => false,
717 },
718 _ => false,
719 },
720 _ => false,
721 }
722}
723
724fn is_escaped_literal_attr_args(value: &AttrArgsEq, unescaped: Symbol) -> bool {
725 match value {
726 AttrArgsEq::Ast(expr) => match &expr.kind {
727 ExprKind::Lit(lit) => is_escaped_lit(lit, unescaped),
728 _ => false,
729 },
730 AttrArgsEq::Hir(lit) => is_escaped_literal_meta_item_lit(lit, unescaped),
731 }
732}
733
734fn is_escaped_literal_meta_item_lit(lit: &MetaItemLit, unescaped: Symbol) -> bool {
735 match lit {
736 MetaItemLit {
737 token_lit:
738 Lit {
739 kind: token::LitKind::Str,
740 symbol: _,
741 suffix: None,
742 },
743 kind,
744 span: _,
745 } => is_escaped_lit_kind(kind, unescaped),
746 _ => false,
747 }
748}
749
750fn is_escaped_lit(lit: &Lit, unescaped: Symbol) -> bool {
751 match lit {
752 Lit {
753 kind: token::LitKind::Str,
754 symbol: _,
755 suffix: None,
756 } => match LitKind::from_token_lit(*lit) {
757 Ok(lit_kind) => is_escaped_lit_kind(&lit_kind, unescaped),
758 _ => false,
759 },
760 _ => false,
761 }
762}
763
764fn is_escaped_lit_kind(kind: &LitKind, unescaped: Symbol) -> bool {
765 match kind {
766 LitKind::Str(symbol, StrStyle::Cooked) => {
767 symbol.as_str().replace('\r', "") == unescaped.as_str().replace('\r', "")
768 }
769 _ => false,
770 }
771}
772
773impl SpanlessEq for LazyAttrTokenStream {
774 fn eq(&self, other: &Self) -> bool {
775 let this = self.to_attr_token_stream();
776 let other = other.to_attr_token_stream();
777 SpanlessEq::eq(&this, &other)
778 }
779}
780
781impl SpanlessEq for AttrKind {
782 fn eq(&self, other: &Self) -> bool {
783 match (self, other) {
784 (AttrKind::Normal(normal), AttrKind::Normal(normal2)) => {
785 SpanlessEq::eq(normal, normal2)
786 }
787 (AttrKind::DocComment(kind, symbol), AttrKind::DocComment(kind2, symbol2)) => {
788 SpanlessEq::eq(kind, kind2) && SpanlessEq::eq(symbol, symbol2)
789 }
790 (AttrKind::DocComment(kind, unescaped), AttrKind::Normal(normal2)) => {
791 match kind {
792 CommentKind::Line | CommentKind::Block => {}
793 }
794 let path = Path::from_ident(Ident::with_dummy_span(sym::doc));
795 SpanlessEq::eq(&path, &normal2.item.path)
796 && match &normal2.item.args {
797 AttrArgs::Empty | AttrArgs::Delimited(_) => false,
798 AttrArgs::Eq(_span, value) => {
799 is_escaped_literal_attr_args(value, *unescaped)
800 }
801 }
802 }
803 (AttrKind::Normal(_), AttrKind::DocComment(..)) => SpanlessEq::eq(other, self),
804 }
805 }
806}
807