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