interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / syn / tests / common / eq.rs

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