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-2.0.119 / tests / common / eq.rs

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