Debian Codegraph @

third_party/rust/syn/tests/common/eq.rs

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