Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/syn/tests/common/eq.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 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::AssignOpKind; 15 use rustc_ast::ast::AssocItemConstraint; 16 use rustc_ast::ast::AssocItemConstraintKind; 17 use rustc_ast::ast::AssocItemKind; 18 use rustc_ast::ast::AttrArgs; 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::BinOpKind; 25 use rustc_ast::ast::BindingMode; 26 use rustc_ast::ast::Block; 27 use rustc_ast::ast::BlockCheckMode; 28 use rustc_ast::ast::BorrowKind; 29 use rustc_ast::ast::BoundAsyncness; 30 use rustc_ast::ast::BoundConstness; 31 use rustc_ast::ast::BoundPolarity; 32 use rustc_ast::ast::ByRef; 33 use rustc_ast::ast::CaptureBy; 34 use rustc_ast::ast::Closure; 35 use rustc_ast::ast::ClosureBinder; 36 use rustc_ast::ast::Const; 37 use rustc_ast::ast::ConstBlockItem; 38 use rustc_ast::ast::ConstItem; 39 use rustc_ast::ast::CoroutineKind; 40 use rustc_ast::ast::CoroutineMarker; 41 use rustc_ast::ast::Crate; 42 use rustc_ast::ast::Defaultness; 43 use rustc_ast::ast::Delegation; 44 use rustc_ast::ast::DelegationMac; 45 use rustc_ast::ast::DelegationSource; 46 use rustc_ast::ast::DelegationSuffixes; 47 use rustc_ast::ast::DelimArgs; 48 use rustc_ast::ast::EiiDecl; 49 use rustc_ast::ast::EiiImpl; 50 use rustc_ast::ast::EnumDef; 51 use rustc_ast::ast::Expr; 52 use rustc_ast::ast::ExprField; 53 use rustc_ast::ast::ExprKind; 54 use rustc_ast::ast::Extern; 55 use rustc_ast::ast::FieldDef; 56 use rustc_ast::ast::FieldDefExtras; 57 use rustc_ast::ast::FloatTy; 58 use rustc_ast::ast::Fn; 59 use rustc_ast::ast::FnContract; 60 use rustc_ast::ast::FnDecl; 61 use rustc_ast::ast::FnHeader; 62 use rustc_ast::ast::FnPtrTy; 63 use rustc_ast::ast::FnRetTy; 64 use rustc_ast::ast::FnSig; 65 use rustc_ast::ast::ForLoop; 66 use rustc_ast::ast::ForLoopKind; 67 use rustc_ast::ast::ForeignItemKind; 68 use rustc_ast::ast::ForeignMod; 69 use rustc_ast::ast::FormatAlignment; 70 use rustc_ast::ast::FormatArgPosition; 71 use rustc_ast::ast::FormatArgPositionKind; 72 use rustc_ast::ast::FormatArgs; 73 use rustc_ast::ast::FormatArgsPiece; 74 use rustc_ast::ast::FormatArgument; 75 use rustc_ast::ast::FormatArgumentKind; 76 use rustc_ast::ast::FormatArguments; 77 use rustc_ast::ast::FormatCount; 78 use rustc_ast::ast::FormatDebugHex; 79 use rustc_ast::ast::FormatOptions; 80 use rustc_ast::ast::FormatPlaceholder; 81 use rustc_ast::ast::FormatSign; 82 use rustc_ast::ast::FormatTrait; 83 use rustc_ast::ast::GenericArg; 84 use rustc_ast::ast::GenericArgs; 85 use rustc_ast::ast::GenericBound; 86 use rustc_ast::ast::GenericParam; 87 use rustc_ast::ast::GenericParamKind; 88 use rustc_ast::ast::Generics; 89 use rustc_ast::ast::Guard; 90 use rustc_ast::ast::Impl; 91 use rustc_ast::ast::ImplPolarity; 92 use rustc_ast::ast::ImplRestriction; 93 use rustc_ast::ast::Inline; 94 use rustc_ast::ast::InlineAsm; 95 use rustc_ast::ast::InlineAsmOperand; 96 use rustc_ast::ast::InlineAsmOptions; 97 use rustc_ast::ast::InlineAsmRegOrRegClass; 98 use rustc_ast::ast::InlineAsmSym; 99 use rustc_ast::ast::InlineAsmTemplatePiece; 100 use rustc_ast::ast::IntTy; 101 use rustc_ast::ast::IsAuto; 102 use rustc_ast::ast::Item; 103 use rustc_ast::ast::ItemKind; 104 use rustc_ast::ast::Label; 105 use rustc_ast::ast::Lifetime; 106 use rustc_ast::ast::LitFloatType; 107 use rustc_ast::ast::LitIntType; 108 use rustc_ast::ast::LitKind; 109 use rustc_ast::ast::Local; 110 use rustc_ast::ast::LocalKind; 111 use rustc_ast::ast::MacCall; 112 use rustc_ast::ast::MacCallStmt; 113 use rustc_ast::ast::MacStmtStyle; 114 use rustc_ast::ast::MacroDef; 115 use rustc_ast::ast::MatchKind; 116 use rustc_ast::ast::MetaItem; 117 use rustc_ast::ast::MetaItemInner; 118 use rustc_ast::ast::MetaItemKind; 119 use rustc_ast::ast::MetaItemLit; 120 use rustc_ast::ast::MethodCall; 121 use rustc_ast::ast::ModKind; 122 use rustc_ast::ast::ModSpans; 123 use rustc_ast::ast::Movability; 124 use rustc_ast::ast::MutRestriction; 125 use rustc_ast::ast::MutTy; 126 use rustc_ast::ast::Mutability; 127 use rustc_ast::ast::NodeId; 128 use rustc_ast::ast::NormalAttr; 129 use rustc_ast::ast::Param; 130 use rustc_ast::ast::Parens; 131 use rustc_ast::ast::ParenthesizedArgs; 132 use rustc_ast::ast::Pat; 133 use rustc_ast::ast::PatField; 134 use rustc_ast::ast::PatFieldsRest; 135 use rustc_ast::ast::PatKind; 136 use rustc_ast::ast::Path; 137 use rustc_ast::ast::PathSegment; 138 use rustc_ast::ast::Pinnedness; 139 use rustc_ast::ast::PolyTraitRef; 140 use rustc_ast::ast::PreciseCapturingArg; 141 use rustc_ast::ast::QSelf; 142 use rustc_ast::ast::RangeEnd; 143 use rustc_ast::ast::RangeLimits; 144 use rustc_ast::ast::RangeSyntax; 145 use rustc_ast::ast::Recovered; 146 use rustc_ast::ast::RestrictionKind; 147 use rustc_ast::ast::Safety; 148 use rustc_ast::ast::StaticItem; 149 use rustc_ast::ast::Stmt; 150 use rustc_ast::ast::StmtKind; 151 use rustc_ast::ast::StrLit; 152 use rustc_ast::ast::StrStyle; 153 use rustc_ast::ast::StructExpr; 154 use rustc_ast::ast::StructRest; 155 use rustc_ast::ast::SyntheticAttr; 156 use rustc_ast::ast::Term; 157 use rustc_ast::ast::TestBinderBody; 158 use rustc_ast::ast::TestBinderBoundTypeConstraint; 159 use rustc_ast::ast::TestBinderConstraint; 160 use rustc_ast::ast::TestBinderConstraints; 161 use rustc_ast::ast::TestBinderExists; 162 use rustc_ast::ast::TestBinderForall; 163 use rustc_ast::ast::Trait; 164 use rustc_ast::ast::TraitAlias; 165 use rustc_ast::ast::TraitBoundModifiers; 166 use rustc_ast::ast::TraitImplHeader; 167 use rustc_ast::ast::TraitObjectSyntax; 168 use rustc_ast::ast::TraitRef; 169 use rustc_ast::ast::Ty; 170 use rustc_ast::ast::TyAlias; 171 use rustc_ast::ast::TyKind; 172 use rustc_ast::ast::TyPat; 173 use rustc_ast::ast::TyPatKind; 174 use rustc_ast::ast::UintTy; 175 use rustc_ast::ast::UnOp; 176 use rustc_ast::ast::UnsafeBinderCastKind; 177 use rustc_ast::ast::UnsafeBinderTy; 178 use rustc_ast::ast::UnsafeSource; 179 use rustc_ast::ast::UseTree; 180 use rustc_ast::ast::UseTreeKind; 181 use rustc_ast::ast::Variant; 182 use rustc_ast::ast::VariantData; 183 use rustc_ast::ast::Visibility; 184 use rustc_ast::ast::VisibilityKind; 185 use rustc_ast::ast::WhereBoundPredicate; 186 use rustc_ast::ast::WhereClause; 187 use rustc_ast::ast::WhereEqPredicate; 188 use rustc_ast::ast::WherePredicate; 189 use rustc_ast::ast::WherePredicateKind; 190 use rustc_ast::ast::WhereRegionPredicate; 191 use rustc_ast::ast::YieldKind; 192 use rustc_ast::attr::data_structures::CfgEntry; 193 use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Lit, Token, TokenKind}; 194 use rustc_ast::tokenstream::{ 195 AttrTokenStream, AttrTokenTree, AttrsTarget, DelimSpacing, DelimSpan, LazyAttrTokenStream, 196 Spacing, TokenStream, TokenTree, 197 }; 198 use rustc_data_structures::packed::Pu128; 199 use rustc_span::symbol::{sym, ByteSymbol, Ident, Symbol}; 200 use rustc_span::{ErrorGuaranteed, LocalExpnId, Span, Spanned, SyntaxContext, DUMMY_SP}; 201 use std::borrow::Cow; 202 use std::collections::HashMap; 203 use std::hash::{BuildHasher, Hash}; 204 use std::sync::Arc; 205 use thin_vec::ThinVec; 206 207 pub trait SpanlessEq { 208 fn eq(&self, other: &Self) -> bool; 209 } 210 211 impl SpanlessEq for Box { 212 fn eq(&self, other: &Self) -> bool { 213 SpanlessEq::eq(&**self, &**other) 214 } 215 } 216 217 impl SpanlessEq for Arc { 218 fn eq(&self, other: &Self) -> bool { 219 SpanlessEq::eq(&**self, &**other) 220 } 221 } 222 223 impl SpanlessEq for Option { 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 233 impl SpanlessEq for Result { 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 243 impl 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 249 impl SpanlessEq for Vec { 250 fn eq(&self, other: &Self) -> bool { 251 <[T] as SpanlessEq>::eq(self, other) 252 } 253 } 254 255 impl SpanlessEq for ThinVec { 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 265 impl SpanlessEq for HashMap { 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 276 impl<'a, T: ?Sized + ToOwned + SpanlessEq> SpanlessEq for Cow<'a, T> { 277 fn eq(&self, other: &Self) -> bool { 278 ::eq(self, other) 279 } 280 } 281 282 impl SpanlessEq for Spanned { 283 fn eq(&self, other: &Self) -> bool { 284 SpanlessEq::eq(&self.node, &other.node) 285 } 286 } 287 288 impl 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 294 impl 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 302 macro_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 312 spanless_eq_true!(Span); 313 spanless_eq_true!(DelimSpan); 314 spanless_eq_true!(AttrId); 315 spanless_eq_true!(NodeId); 316 spanless_eq_true!(SyntaxContext); 317 spanless_eq_true!(Spacing); 318 spanless_eq_true!(LocalExpnId); 319 320 macro_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 330 spanless_eq_partial_eq!(()); 331 spanless_eq_partial_eq!(bool); 332 spanless_eq_partial_eq!(u8); 333 spanless_eq_partial_eq!(u16); 334 spanless_eq_partial_eq!(u32); 335 spanless_eq_partial_eq!(u128); 336 spanless_eq_partial_eq!(usize); 337 spanless_eq_partial_eq!(char); 338 spanless_eq_partial_eq!(str); 339 spanless_eq_partial_eq!(String); 340 spanless_eq_partial_eq!(Pu128); 341 spanless_eq_partial_eq!(Symbol); 342 spanless_eq_partial_eq!(ByteSymbol); 343 spanless_eq_partial_eq!(CommentKind); 344 spanless_eq_partial_eq!(Delimiter); 345 spanless_eq_partial_eq!(InlineAsmOptions); 346 spanless_eq_partial_eq!(token::LitKind); 347 spanless_eq_partial_eq!(ErrorGuaranteed); 348 spanless_eq_partial_eq!(CfgEntry); 349 350 macro_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 398 macro_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 497 spanless_eq_struct!(AngleBracketedArgs; span args); 498 spanless_eq_struct!(AnonConst; id value); 499 spanless_eq_struct!(Arm; attrs pat guard body span id is_placeholder); 500 spanless_eq_struct!(AssocItemConstraint; id ident gen_args kind span); 501 spanless_eq_struct!(AttrItem; unsafety path args span); 502 spanless_eq_struct!(AttrTokenStream; 0); 503 spanless_eq_struct!(Attribute; kind id style span); 504 spanless_eq_struct!(AttrsTarget; attrs tokens); 505 spanless_eq_struct!(BindingMode; 0 1); 506 spanless_eq_struct!(Block; stmts id rules span); 507 spanless_eq_struct!(Closure; binder capture_clause constness coroutine_marker movability fn_decl body !fn_decl_span !fn_arg_span); 508 spanless_eq_struct!(ConstBlockItem; id span block); 509 spanless_eq_struct!(ConstItem; defaultness ident generics ty body define_opaque); 510 spanless_eq_struct!(CoroutineMarker; kind span closure_id return_impl_trait_id); 511 spanless_eq_struct!(Crate; attrs items spans id is_placeholder); 512 spanless_eq_struct!(Delegation; id qself path ident rename body source); 513 spanless_eq_struct!(DelegationMac; qself prefix suffixes body); 514 spanless_eq_struct!(DelimArgs; dspan delim tokens); 515 spanless_eq_struct!(DelimSpacing; open close); 516 spanless_eq_struct!(EiiDecl; foreign_item impl_unsafe); 517 spanless_eq_struct!(EiiImpl; node_id eii_macro_path known_eii_macro_resolution impl_safety span inner_span is_default); 518 spanless_eq_struct!(EnumDef; variants); 519 spanless_eq_struct!(Expr; id kind span attrs !tokens); 520 spanless_eq_struct!(ExprField; attrs id span ident expr is_shorthand is_placeholder); 521 spanless_eq_struct!(FieldDef; attrs id span vis extras ident ty is_placeholder); 522 spanless_eq_struct!(FieldDefExtras; safety mut_restriction default); 523 spanless_eq_struct!(Fn; defaultness ident generics sig contract define_opaque body eii_impl); 524 spanless_eq_struct!(FnContract; declarations requires ensures); 525 spanless_eq_struct!(FnDecl; inputs output); 526 spanless_eq_struct!(FnHeader; constness coroutine_marker safety ext); 527 spanless_eq_struct!(FnPtrTy; safety ext generic_params decl decl_span); 528 spanless_eq_struct!(FnSig; header decl span); 529 spanless_eq_struct!(ForLoop; pat iter body label kind); 530 spanless_eq_struct!(ForeignMod; extern_span safety abi items); 531 spanless_eq_struct!(FormatArgPosition; index kind span); 532 spanless_eq_struct!(FormatArgs; span template arguments uncooked_fmt_str is_source_literal); 533 spanless_eq_struct!(FormatArgument; kind expr); 534 spanless_eq_struct!(FormatOptions; width precision alignment fill sign alternate zero_pad debug_hex); 535 spanless_eq_struct!(FormatPlaceholder; argument span format_trait format_options); 536 spanless_eq_struct!(GenericParam; id ident attrs bounds is_placeholder kind !colon_span); 537 spanless_eq_struct!(Generics; params where_clause span); 538 spanless_eq_struct!(Guard; cond span_with_leading_if); 539 spanless_eq_struct!(Impl; generics constness of_trait self_ty items); 540 spanless_eq_struct!(ImplRestriction; kind span); 541 spanless_eq_struct!(InlineAsm; asm_macro template template_strs operands clobber_abis options line_spans); 542 spanless_eq_struct!(InlineAsmSym; id qself path); 543 spanless_eq_struct!(Item; attrs id span vis kind !tokens); 544 spanless_eq_struct!(Label; ident); 545 spanless_eq_struct!(Lifetime; id ident); 546 spanless_eq_struct!(Lit; kind symbol suffix); 547 spanless_eq_struct!(Local; id super_ pat ty kind span colon_sp attrs !tokens); 548 spanless_eq_struct!(MacCall; path args); 549 spanless_eq_struct!(MacCallStmt; mac style attrs tokens); 550 spanless_eq_struct!(MacroDef; body macro_rules eii_declaration); 551 spanless_eq_struct!(MetaItem; unsafety path kind span); 552 spanless_eq_struct!(MetaItemLit; symbol suffix kind span); 553 spanless_eq_struct!(MethodCall; seg receiver args !span); 554 spanless_eq_struct!(ModSpans; !inner_span !inject_use_span); 555 spanless_eq_struct!(MutRestriction; kind span); 556 spanless_eq_struct!(MutTy; ty mutbl); 557 spanless_eq_struct!(NormalAttr; item tokens); 558 spanless_eq_struct!(ParenthesizedArgs; span inputs inputs_span output); 559 spanless_eq_struct!(Pat; id kind span); 560 spanless_eq_struct!(PatField; ident pat is_shorthand attrs id span is_placeholder); 561 spanless_eq_struct!(Path; span segments); 562 spanless_eq_struct!(PathSegment; ident id args); 563 spanless_eq_struct!(PolyTraitRef; bound_generic_params modifiers trait_ref span parens); 564 spanless_eq_struct!(QSelf; ty path_span position); 565 spanless_eq_struct!(StaticItem; ident ty safety mutability expr define_opaque eii_impl); 566 spanless_eq_struct!(Stmt; id kind span); 567 spanless_eq_struct!(StrLit; symbol suffix symbol_unescaped style span); 568 spanless_eq_struct!(StructExpr; qself path fields rest); 569 spanless_eq_struct!(TestBinderBody; foralls exists constraints predicates); 570 spanless_eq_struct!(TestBinderBoundTypeConstraint; span node_id params lhs rhs); 571 spanless_eq_struct!(TestBinderConstraints; generics body); 572 spanless_eq_struct!(TestBinderExists; span node_id params body); 573 spanless_eq_struct!(TestBinderForall; span node_id generics body assert_on_exit); 574 spanless_eq_struct!(Token; kind span); 575 spanless_eq_struct!(Trait; constness safety is_auto impl_restriction ident generics bounds items); 576 spanless_eq_struct!(TraitAlias; constness ident generics bounds); 577 spanless_eq_struct!(TraitBoundModifiers; constness asyncness polarity); 578 spanless_eq_struct!(TraitImplHeader; defaultness safety polarity trait_ref); 579 spanless_eq_struct!(TraitRef; path ref_id); 580 spanless_eq_struct!(Ty; id kind span); 581 spanless_eq_struct!(TyAlias; defaultness ident generics after_where_clause bounds ty); 582 spanless_eq_struct!(TyPat; id kind span); 583 spanless_eq_struct!(UnsafeBinderTy; generic_params inner_ty); 584 spanless_eq_struct!(UseTree; prefix kind); 585 spanless_eq_struct!(Variant; attrs id span !vis ident data disr_expr is_placeholder); 586 spanless_eq_struct!(Visibility; kind span); 587 spanless_eq_struct!(WhereBoundPredicate; bound_generic_params bounded_ty bounds); 588 spanless_eq_struct!(WhereClause; has_where_token predicates span); 589 spanless_eq_struct!(WhereEqPredicate; lhs_ty rhs_ty); 590 spanless_eq_struct!(WherePredicate; attrs kind id span is_placeholder); 591 spanless_eq_struct!(WhereRegionPredicate; lifetime bounds); 592 spanless_eq_enum!(AngleBracketedArg; Arg(0) Constraint(0)); 593 spanless_eq_enum!(AsmMacro; Asm GlobalAsm NakedAsm); 594 spanless_eq_enum!(AssocItemConstraintKind; Equality(term) Bound(bounds)); 595 spanless_eq_enum!(AssocItemKind; Const(0) Fn(0) Type(0) MacCall(0) Delegation(0) DelegationMac(0)); 596 spanless_eq_enum!(AttrArgs; Empty Delimited(0) Eq(eq_span expr)); 597 spanless_eq_enum!(AttrStyle; Outer Inner); 598 spanless_eq_enum!(AttrTokenTree; Token(0 1) Delimited(0 1 2 3) AttrsTarget(0)); 599 spanless_eq_enum!(BinOpKind; Add Sub Mul Div Rem And Or BitXor BitAnd BitOr Shl Shr Eq Lt Le Ne Ge Gt); 600 spanless_eq_enum!(BlockCheckMode; Default Unsafe(0)); 601 spanless_eq_enum!(BorrowKind; Ref Raw Pin); 602 spanless_eq_enum!(BoundAsyncness; Normal Async(0)); 603 spanless_eq_enum!(BoundConstness; Never Always(0) Maybe(0)); 604 spanless_eq_enum!(BoundPolarity; Positive Negative(0) Maybe(0)); 605 spanless_eq_enum!(ByRef; Yes(0 1) No); 606 spanless_eq_enum!(CaptureBy; Value(move_kw) Ref Use(use_kw)); 607 spanless_eq_enum!(ClosureBinder; NotPresent For(span generic_params)); 608 spanless_eq_enum!(Const; Yes(0) No); 609 spanless_eq_enum!(CoroutineKind; Async Gen AsyncGen); 610 spanless_eq_enum!(Defaultness; Implicit Default(0) Final(0)); 611 spanless_eq_enum!(DelegationSource; Single List(0) Glob); 612 spanless_eq_enum!(DelegationSuffixes; List(0) Glob(0)); 613 spanless_eq_enum!(Extern; None Implicit(0) Explicit(0 1)); 614 spanless_eq_enum!(FloatTy; F16 F32 F64 F128); 615 spanless_eq_enum!(FnRetTy; Default(0) Ty(0)); 616 spanless_eq_enum!(ForLoopKind; For ForAwait); 617 spanless_eq_enum!(ForeignItemKind; Static(0) Fn(0) TyAlias(0) MacCall(0)); 618 spanless_eq_enum!(FormatAlignment; Left Right Center); 619 spanless_eq_enum!(FormatArgPositionKind; Implicit Number Named); 620 spanless_eq_enum!(FormatArgsPiece; Literal(0) Placeholder(0)); 621 spanless_eq_enum!(FormatArgumentKind; Normal Named(0) Captured(0)); 622 spanless_eq_enum!(FormatCount; Literal(0) Argument(0)); 623 spanless_eq_enum!(FormatDebugHex; Lower Upper); 624 spanless_eq_enum!(FormatSign; Plus Minus); 625 spanless_eq_enum!(FormatTrait; Display Debug LowerExp UpperExp Octal Pointer Binary LowerHex UpperHex); 626 spanless_eq_enum!(GenericArg; Lifetime(0) Type(0) Const(0)); 627 spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0) ParenthesizedElided(0)); 628 spanless_eq_enum!(GenericBound; Trait(0) Outlives(0) Use(0 1)); 629 spanless_eq_enum!(GenericParamKind; Lifetime Type(default) Const(ty span default)); 630 spanless_eq_enum!(ImplPolarity; Positive Negative(0)); 631 spanless_eq_enum!(Inline; Yes No(had_parse_error)); 632 spanless_eq_enum!(InlineAsmRegOrRegClass; Reg(0) RegClass(0)); 633 spanless_eq_enum!(InlineAsmTemplatePiece; String(0) Placeholder(operand_idx modifier span)); 634 spanless_eq_enum!(IntTy; Isize I8 I16 I32 I64 I128); 635 spanless_eq_enum!(IsAuto; Yes No); 636 spanless_eq_enum!(LitFloatType; Suffixed(0) Unsuffixed); 637 spanless_eq_enum!(LitIntType; Signed(0) Unsigned(0) Unsuffixed); 638 spanless_eq_enum!(LocalKind; Decl Init(0) InitElse(0 1)); 639 spanless_eq_enum!(MacStmtStyle; Semicolon Braces NoBraces); 640 spanless_eq_enum!(MatchKind; Prefix Postfix); 641 spanless_eq_enum!(MetaItemInner; MetaItem(0) Lit(0)); 642 spanless_eq_enum!(MetaItemKind; Word List(0) NameValue(0)); 643 spanless_eq_enum!(ModKind; Loaded(0 1 2) Unloaded); 644 spanless_eq_enum!(Movability; Static Movable); 645 spanless_eq_enum!(Mutability; Mut Not); 646 spanless_eq_enum!(Parens; Yes No); 647 spanless_eq_enum!(PatFieldsRest; Rest(0) Recovered(0) None); 648 spanless_eq_enum!(Pinnedness; Not Pinned); 649 spanless_eq_enum!(PreciseCapturingArg; Lifetime(0) Arg(0 1)); 650 spanless_eq_enum!(RangeEnd; Included(0) Excluded); 651 spanless_eq_enum!(RangeLimits; HalfOpen Closed); 652 spanless_eq_enum!(Recovered; No Yes(0)); 653 spanless_eq_enum!(RestrictionKind; Unrestricted Restricted(path id shorthand)); 654 spanless_eq_enum!(Safety; Unsafe(0) Safe(0) Default); 655 spanless_eq_enum!(StmtKind; Let(0) Item(0) Expr(0) Semi(0) Empty MacCall(0)); 656 spanless_eq_enum!(StrStyle; Cooked Raw(0)); 657 spanless_eq_enum!(StructRest; Base(0) Rest(0) None NoneWithError(0)); 658 spanless_eq_enum!(SyntheticAttr; CfgTrace(0) CfgAttrTrace(0)); 659 spanless_eq_enum!(Term; Ty(0) Const(0)); 660 spanless_eq_enum!(TestBinderConstraint; And(items) Or(items) Lifetime(lhs rhs) PlaceholderOutlives(lhs rhs) AliasOutlives(bound_type_constraint)); 661 spanless_eq_enum!(TokenTree; Token(0 1) Delimited(0 1 2 3)); 662 spanless_eq_enum!(TraitObjectSyntax; Dyn None); 663 spanless_eq_enum!(TyPatKind; Range(0 1 2) NotNull Or(0) Err(0)); 664 spanless_eq_enum!(UintTy; Usize U8 U16 U32 U64 U128); 665 spanless_eq_enum!(UnOp; Deref Not Neg); 666 spanless_eq_enum!(UnsafeBinderCastKind; Wrap Unwrap); 667 spanless_eq_enum!(UnsafeSource; CompilerGenerated UserProvided); 668 spanless_eq_enum!(UseTreeKind; Simple(0) Nested(items span) Glob(0)); 669 spanless_eq_enum!(VariantData; Struct(fields recovered) Tuple(0 1) Unit(0)); 670 spanless_eq_enum!(VisibilityKind; Public Restricted(path id shorthand) Inherited); 671 spanless_eq_enum!(WherePredicateKind; BoundPredicate(0) RegionPredicate(0)); 672 spanless_eq_enum!(YieldKind; Prefix(0) Postfix(0)); 673 spanless_eq_enum!(AssignOpKind; AddAssign SubAssign MulAssign DivAssign 674 RemAssign BitXorAssign BitAndAssign BitOrAssign ShlAssign ShrAssign); 675 spanless_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); 684 spanless_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)); 687 spanless_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)); 692 spanless_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)); 694 spanless_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)); 697 spanless_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 702 impl SpanlessEq for Ident { 703 fn eq(&self, other: &Self) -> bool { 704 self.as_str() == other.as_str() 705 } 706 } 707 708 impl SpanlessEq for RangeSyntax { 709 fn eq(&self, _other: &Self) -> bool { 710 match self { 711 RangeSyntax::DotDotDot | RangeSyntax::DotDotEq => true, 712 } 713 } 714 } 715 716 impl 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 744 impl 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 757 impl 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 792 fn doc_comment<'a>( 793 style: AttrStyle, 794 unescaped: Symbol, 795 trees: &mut impl Iterator, 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 845 fn 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 858 fn 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 870 fn 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 884 fn 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 893 impl 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 901 impl 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 933 impl SpanlessEq for FormatArguments { 934 fn eq(&self, other: &Self) -> bool { 935 SpanlessEq::eq(self.all_args(), other.all_args()) 936 } 937 }