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-2.0.119/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-2.0.119 / tests / common / eq.rs` 926 lines ยท 34209 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::AttrItemKind; 22 use rustc_ast::ast::AttrKind; 23 use rustc_ast::ast::AttrStyle; 24 use rustc_ast::ast::Attribute; 25 use rustc_ast::ast::BinOpKind; 26 use rustc_ast::ast::BindingMode; 27 use rustc_ast::ast::Block; 28 use rustc_ast::ast::BlockCheckMode; 29 use rustc_ast::ast::BorrowKind; 30 use rustc_ast::ast::BoundAsyncness; 31 use rustc_ast::ast::BoundConstness; 32 use rustc_ast::ast::BoundPolarity; 33 use rustc_ast::ast::ByRef; 34 use rustc_ast::ast::CaptureBy; 35 use rustc_ast::ast::Closure; 36 use rustc_ast::ast::ClosureBinder; 37 use rustc_ast::ast::Const; 38 use rustc_ast::ast::ConstBlockItem; 39 use rustc_ast::ast::ConstItem; 40 use rustc_ast::ast::ConstItemRhsKind; 41 use rustc_ast::ast::CoroutineKind; 42 use rustc_ast::ast::Crate; 43 use rustc_ast::ast::Defaultness; 44 use rustc_ast::ast::Delegation; 45 use rustc_ast::ast::DelegationMac; 46 use rustc_ast::ast::DelegationSource; 47 use rustc_ast::ast::DelegationSuffixes; 48 use rustc_ast::ast::DelimArgs; 49 use rustc_ast::ast::EarlyParsedAttribute; 50 use rustc_ast::ast::EiiDecl; 51 use rustc_ast::ast::EiiImpl; 52 use rustc_ast::ast::EnumDef; 53 use rustc_ast::ast::Expr; 54 use rustc_ast::ast::ExprField; 55 use rustc_ast::ast::ExprKind; 56 use rustc_ast::ast::Extern; 57 use rustc_ast::ast::FieldDef; 58 use rustc_ast::ast::FloatTy; 59 use rustc_ast::ast::Fn; 60 use rustc_ast::ast::FnContract; 61 use rustc_ast::ast::FnDecl; 62 use rustc_ast::ast::FnHeader; 63 use rustc_ast::ast::FnPtrTy; 64 use rustc_ast::ast::FnRetTy; 65 use rustc_ast::ast::FnSig; 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::GenBlockKind; 84 use rustc_ast::ast::GenericArg; 85 use rustc_ast::ast::GenericArgs; 86 use rustc_ast::ast::GenericBound; 87 use rustc_ast::ast::GenericParam; 88 use rustc_ast::ast::GenericParamKind; 89 use rustc_ast::ast::Generics; 90 use rustc_ast::ast::Guard; 91 use rustc_ast::ast::Impl; 92 use rustc_ast::ast::ImplPolarity; 93 use rustc_ast::ast::ImplRestriction; 94 use rustc_ast::ast::Inline; 95 use rustc_ast::ast::InlineAsm; 96 use rustc_ast::ast::InlineAsmOperand; 97 use rustc_ast::ast::InlineAsmOptions; 98 use rustc_ast::ast::InlineAsmRegOrRegClass; 99 use rustc_ast::ast::InlineAsmSym; 100 use rustc_ast::ast::InlineAsmTemplatePiece; 101 use rustc_ast::ast::IntTy; 102 use rustc_ast::ast::IsAuto; 103 use rustc_ast::ast::Item; 104 use rustc_ast::ast::ItemKind; 105 use rustc_ast::ast::Label; 106 use rustc_ast::ast::Lifetime; 107 use rustc_ast::ast::LitFloatType; 108 use rustc_ast::ast::LitIntType; 109 use rustc_ast::ast::LitKind; 110 use rustc_ast::ast::Local; 111 use rustc_ast::ast::LocalKind; 112 use rustc_ast::ast::MacCall; 113 use rustc_ast::ast::MacCallStmt; 114 use rustc_ast::ast::MacStmtStyle; 115 use rustc_ast::ast::MacroDef; 116 use rustc_ast::ast::MatchKind; 117 use rustc_ast::ast::MetaItem; 118 use rustc_ast::ast::MetaItemInner; 119 use rustc_ast::ast::MetaItemKind; 120 use rustc_ast::ast::MetaItemLit; 121 use rustc_ast::ast::MethodCall; 122 use rustc_ast::ast::ModKind; 123 use rustc_ast::ast::ModSpans; 124 use rustc_ast::ast::Movability; 125 use rustc_ast::ast::MutRestriction; 126 use rustc_ast::ast::MutTy; 127 use rustc_ast::ast::Mutability; 128 use rustc_ast::ast::NodeId; 129 use rustc_ast::ast::NormalAttr; 130 use rustc_ast::ast::Param; 131 use rustc_ast::ast::Parens; 132 use rustc_ast::ast::ParenthesizedArgs; 133 use rustc_ast::ast::Pat; 134 use rustc_ast::ast::PatField; 135 use rustc_ast::ast::PatFieldsRest; 136 use rustc_ast::ast::PatKind; 137 use rustc_ast::ast::Path; 138 use rustc_ast::ast::PathSegment; 139 use rustc_ast::ast::Pinnedness; 140 use rustc_ast::ast::PolyTraitRef; 141 use rustc_ast::ast::PreciseCapturingArg; 142 use rustc_ast::ast::QSelf; 143 use rustc_ast::ast::RangeEnd; 144 use rustc_ast::ast::RangeLimits; 145 use rustc_ast::ast::RangeSyntax; 146 use rustc_ast::ast::Recovered; 147 use rustc_ast::ast::RestrictionKind; 148 use rustc_ast::ast::Safety; 149 use rustc_ast::ast::StaticItem; 150 use rustc_ast::ast::Stmt; 151 use rustc_ast::ast::StmtKind; 152 use rustc_ast::ast::StrLit; 153 use rustc_ast::ast::StrStyle; 154 use rustc_ast::ast::StructExpr; 155 use rustc_ast::ast::StructRest; 156 use rustc_ast::ast::Term; 157 use rustc_ast::ast::Trait; 158 use rustc_ast::ast::TraitAlias; 159 use rustc_ast::ast::TraitBoundModifiers; 160 use rustc_ast::ast::TraitImplHeader; 161 use rustc_ast::ast::TraitObjectSyntax; 162 use rustc_ast::ast::TraitRef; 163 use rustc_ast::ast::Ty; 164 use rustc_ast::ast::TyAlias; 165 use rustc_ast::ast::TyKind; 166 use rustc_ast::ast::TyPat; 167 use rustc_ast::ast::TyPatKind; 168 use rustc_ast::ast::UintTy; 169 use rustc_ast::ast::UnOp; 170 use rustc_ast::ast::UnsafeBinderCastKind; 171 use rustc_ast::ast::UnsafeBinderTy; 172 use rustc_ast::ast::UnsafeSource; 173 use rustc_ast::ast::UseTree; 174 use rustc_ast::ast::UseTreeKind; 175 use rustc_ast::ast::Variant; 176 use rustc_ast::ast::VariantData; 177 use rustc_ast::ast::Visibility; 178 use rustc_ast::ast::VisibilityKind; 179 use rustc_ast::ast::WhereBoundPredicate; 180 use rustc_ast::ast::WhereClause; 181 use rustc_ast::ast::WhereEqPredicate; 182 use rustc_ast::ast::WherePredicate; 183 use rustc_ast::ast::WherePredicateKind; 184 use rustc_ast::ast::WhereRegionPredicate; 185 use rustc_ast::ast::YieldKind; 186 use rustc_ast::attr::data_structures::CfgEntry; 187 use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Lit, Token, TokenKind}; 188 use rustc_ast::tokenstream::{ 189 AttrTokenStream, AttrTokenTree, AttrsTarget, DelimSpacing, DelimSpan, LazyAttrTokenStream, 190 Spacing, TokenStream, TokenTree, 191 }; 192 use rustc_data_structures::packed::Pu128; 193 use rustc_span::symbol::{sym, ByteSymbol, Ident, Symbol}; 194 use rustc_span::{ErrorGuaranteed, LocalExpnId, Span, Spanned, SyntaxContext, DUMMY_SP}; 195 use std::borrow::Cow; 196 use std::collections::HashMap; 197 use std::hash::{BuildHasher, Hash}; 198 use std::sync::Arc; 199 use thin_vec::ThinVec; 200 201 pub trait SpanlessEq { 202 fn eq(&self, other: &Self) -> bool; 203 } 204 205 impl SpanlessEq for Box { 206 fn eq(&self, other: &Self) -> bool { 207 SpanlessEq::eq(&**self, &**other) 208 } 209 } 210 211 impl SpanlessEq for Arc { 212 fn eq(&self, other: &Self) -> bool { 213 SpanlessEq::eq(&**self, &**other) 214 } 215 } 216 217 impl SpanlessEq for Option { 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 227 impl SpanlessEq for Result { 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 237 impl 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 243 impl SpanlessEq for Vec { 244 fn eq(&self, other: &Self) -> bool { 245 <[T] as SpanlessEq>::eq(self, other) 246 } 247 } 248 249 impl SpanlessEq for ThinVec { 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 259 impl SpanlessEq for HashMap { 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 270 impl<'a, T: ?Sized + ToOwned + SpanlessEq> SpanlessEq for Cow<'a, T> { 271 fn eq(&self, other: &Self) -> bool { 272 ::eq(self, other) 273 } 274 } 275 276 impl SpanlessEq for Spanned { 277 fn eq(&self, other: &Self) -> bool { 278 SpanlessEq::eq(&self.node, &other.node) 279 } 280 } 281 282 impl 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 288 impl 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 296 macro_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 306 spanless_eq_true!(Span); 307 spanless_eq_true!(DelimSpan); 308 spanless_eq_true!(AttrId); 309 spanless_eq_true!(NodeId); 310 spanless_eq_true!(SyntaxContext); 311 spanless_eq_true!(Spacing); 312 spanless_eq_true!(LocalExpnId); 313 314 macro_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 324 spanless_eq_partial_eq!(()); 325 spanless_eq_partial_eq!(bool); 326 spanless_eq_partial_eq!(u8); 327 spanless_eq_partial_eq!(u16); 328 spanless_eq_partial_eq!(u32); 329 spanless_eq_partial_eq!(u128); 330 spanless_eq_partial_eq!(usize); 331 spanless_eq_partial_eq!(char); 332 spanless_eq_partial_eq!(str); 333 spanless_eq_partial_eq!(String); 334 spanless_eq_partial_eq!(Pu128); 335 spanless_eq_partial_eq!(Symbol); 336 spanless_eq_partial_eq!(ByteSymbol); 337 spanless_eq_partial_eq!(CommentKind); 338 spanless_eq_partial_eq!(Delimiter); 339 spanless_eq_partial_eq!(InlineAsmOptions); 340 spanless_eq_partial_eq!(token::LitKind); 341 spanless_eq_partial_eq!(ErrorGuaranteed); 342 spanless_eq_partial_eq!(CfgEntry); 343 344 macro_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 392 macro_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 491 spanless_eq_struct!(AngleBracketedArgs; span args); 492 spanless_eq_struct!(AnonConst; id value); 493 spanless_eq_struct!(Arm; attrs pat guard body span id is_placeholder); 494 spanless_eq_struct!(AssocItemConstraint; id ident gen_args kind span); 495 spanless_eq_struct!(AttrItem; unsafety path args); 496 spanless_eq_struct!(AttrTokenStream; 0); 497 spanless_eq_struct!(Attribute; kind id style span); 498 spanless_eq_struct!(AttrsTarget; attrs tokens); 499 spanless_eq_struct!(BindingMode; 0 1); 500 spanless_eq_struct!(Block; stmts id rules span); 501 spanless_eq_struct!(Closure; binder capture_clause constness coroutine_kind movability fn_decl body !fn_decl_span !fn_arg_span); 502 spanless_eq_struct!(ConstBlockItem; id span block); 503 spanless_eq_struct!(ConstItem; defaultness ident generics ty rhs_kind define_opaque); 504 spanless_eq_struct!(Crate; attrs items spans id is_placeholder); 505 spanless_eq_struct!(Delegation; id qself path ident rename body source); 506 spanless_eq_struct!(DelegationMac; qself prefix suffixes body); 507 spanless_eq_struct!(DelimArgs; dspan delim tokens); 508 spanless_eq_struct!(DelimSpacing; open close); 509 spanless_eq_struct!(EiiDecl; foreign_item impl_unsafe); 510 spanless_eq_struct!(EiiImpl; node_id eii_macro_path known_eii_macro_resolution impl_safety span inner_span is_default); 511 spanless_eq_struct!(EnumDef; variants); 512 spanless_eq_struct!(Expr; id kind span attrs !tokens); 513 spanless_eq_struct!(ExprField; attrs id span ident expr is_shorthand is_placeholder); 514 spanless_eq_struct!(FieldDef; attrs id span vis mut_restriction safety ident ty default is_placeholder); 515 spanless_eq_struct!(Fn; defaultness ident generics sig contract define_opaque body eii_impls); 516 spanless_eq_struct!(FnContract; declarations requires ensures); 517 spanless_eq_struct!(FnDecl; inputs output); 518 spanless_eq_struct!(FnHeader; constness coroutine_kind safety ext); 519 spanless_eq_struct!(FnPtrTy; safety ext generic_params decl decl_span); 520 spanless_eq_struct!(FnSig; header decl span); 521 spanless_eq_struct!(ForeignMod; extern_span safety abi items); 522 spanless_eq_struct!(FormatArgPosition; index kind span); 523 spanless_eq_struct!(FormatArgs; span template arguments uncooked_fmt_str is_source_literal); 524 spanless_eq_struct!(FormatArgument; kind expr); 525 spanless_eq_struct!(FormatOptions; width precision alignment fill sign alternate zero_pad debug_hex); 526 spanless_eq_struct!(FormatPlaceholder; argument span format_trait format_options); 527 spanless_eq_struct!(GenericParam; id ident attrs bounds is_placeholder kind !colon_span); 528 spanless_eq_struct!(Generics; params where_clause span); 529 spanless_eq_struct!(Guard; cond span_with_leading_if); 530 spanless_eq_struct!(Impl; generics constness of_trait self_ty items); 531 spanless_eq_struct!(ImplRestriction; kind span); 532 spanless_eq_struct!(InlineAsm; asm_macro template template_strs operands clobber_abis options line_spans); 533 spanless_eq_struct!(InlineAsmSym; id qself path); 534 spanless_eq_struct!(Item; attrs id span vis kind !tokens); 535 spanless_eq_struct!(Label; ident); 536 spanless_eq_struct!(Lifetime; id ident); 537 spanless_eq_struct!(Lit; kind symbol suffix); 538 spanless_eq_struct!(Local; id super_ pat ty kind span colon_sp attrs !tokens); 539 spanless_eq_struct!(MacCall; path args); 540 spanless_eq_struct!(MacCallStmt; mac style attrs tokens); 541 spanless_eq_struct!(MacroDef; body macro_rules eii_declaration); 542 spanless_eq_struct!(MetaItem; unsafety path kind span); 543 spanless_eq_struct!(MetaItemLit; symbol suffix kind span); 544 spanless_eq_struct!(MethodCall; seg receiver args !span); 545 spanless_eq_struct!(ModSpans; !inner_span !inject_use_span); 546 spanless_eq_struct!(MutRestriction; kind span); 547 spanless_eq_struct!(MutTy; ty mutbl); 548 spanless_eq_struct!(NormalAttr; item tokens); 549 spanless_eq_struct!(ParenthesizedArgs; span inputs inputs_span output); 550 spanless_eq_struct!(Pat; id kind span); 551 spanless_eq_struct!(PatField; ident pat is_shorthand attrs id span is_placeholder); 552 spanless_eq_struct!(Path; span segments); 553 spanless_eq_struct!(PathSegment; ident id args); 554 spanless_eq_struct!(PolyTraitRef; bound_generic_params modifiers trait_ref span parens); 555 spanless_eq_struct!(QSelf; ty path_span position); 556 spanless_eq_struct!(StaticItem; ident ty safety mutability expr define_opaque eii_impls); 557 spanless_eq_struct!(Stmt; id kind span); 558 spanless_eq_struct!(StrLit; symbol suffix symbol_unescaped style span); 559 spanless_eq_struct!(StructExpr; qself path fields rest); 560 spanless_eq_struct!(Token; kind span); 561 spanless_eq_struct!(Trait; constness safety is_auto impl_restriction ident generics bounds items); 562 spanless_eq_struct!(TraitAlias; constness ident generics bounds); 563 spanless_eq_struct!(TraitBoundModifiers; constness asyncness polarity); 564 spanless_eq_struct!(TraitImplHeader; defaultness safety polarity trait_ref); 565 spanless_eq_struct!(TraitRef; path ref_id); 566 spanless_eq_struct!(Ty; id kind span); 567 spanless_eq_struct!(TyAlias; defaultness ident generics after_where_clause bounds ty); 568 spanless_eq_struct!(TyPat; id kind span); 569 spanless_eq_struct!(UnsafeBinderTy; generic_params inner_ty); 570 spanless_eq_struct!(UseTree; prefix kind); 571 spanless_eq_struct!(Variant; attrs id span !vis ident data disr_expr is_placeholder); 572 spanless_eq_struct!(Visibility; kind span); 573 spanless_eq_struct!(WhereBoundPredicate; bound_generic_params bounded_ty bounds); 574 spanless_eq_struct!(WhereClause; has_where_token predicates span); 575 spanless_eq_struct!(WhereEqPredicate; lhs_ty rhs_ty); 576 spanless_eq_struct!(WherePredicate; attrs kind id span is_placeholder); 577 spanless_eq_struct!(WhereRegionPredicate; lifetime bounds); 578 spanless_eq_enum!(AngleBracketedArg; Arg(0) Constraint(0)); 579 spanless_eq_enum!(AsmMacro; Asm GlobalAsm NakedAsm); 580 spanless_eq_enum!(AssocItemConstraintKind; Equality(term) Bound(bounds)); 581 spanless_eq_enum!(AssocItemKind; Const(0) Fn(0) Type(0) MacCall(0) Delegation(0) DelegationMac(0)); 582 spanless_eq_enum!(AttrArgs; Empty Delimited(0) Eq(eq_span expr)); 583 spanless_eq_enum!(AttrItemKind; Parsed(0) Unparsed(0)); 584 spanless_eq_enum!(AttrStyle; Outer Inner); 585 spanless_eq_enum!(AttrTokenTree; Token(0 1) Delimited(0 1 2 3) AttrsTarget(0)); 586 spanless_eq_enum!(BinOpKind; Add Sub Mul Div Rem And Or BitXor BitAnd BitOr Shl Shr Eq Lt Le Ne Ge Gt); 587 spanless_eq_enum!(BlockCheckMode; Default Unsafe(0)); 588 spanless_eq_enum!(BorrowKind; Ref Raw Pin); 589 spanless_eq_enum!(BoundAsyncness; Normal Async(0)); 590 spanless_eq_enum!(BoundConstness; Never Always(0) Maybe(0)); 591 spanless_eq_enum!(BoundPolarity; Positive Negative(0) Maybe(0)); 592 spanless_eq_enum!(ByRef; Yes(0 1) No); 593 spanless_eq_enum!(CaptureBy; Value(move_kw) Ref Use(use_kw)); 594 spanless_eq_enum!(ClosureBinder; NotPresent For(span generic_params)); 595 spanless_eq_enum!(Const; Yes(0) No); 596 spanless_eq_enum!(ConstItemRhsKind; Body(rhs) TypeConst(rhs)); 597 spanless_eq_enum!(Defaultness; Implicit Default(0) Final(0)); 598 spanless_eq_enum!(DelegationSource; Single List(0) Glob); 599 spanless_eq_enum!(DelegationSuffixes; List(0) Glob(0)); 600 spanless_eq_enum!(EarlyParsedAttribute; CfgTrace(0) CfgAttrTrace); 601 spanless_eq_enum!(Extern; None Implicit(0) Explicit(0 1)); 602 spanless_eq_enum!(FloatTy; F16 F32 F64 F128); 603 spanless_eq_enum!(FnRetTy; Default(0) Ty(0)); 604 spanless_eq_enum!(ForLoopKind; For ForAwait); 605 spanless_eq_enum!(ForeignItemKind; Static(0) Fn(0) TyAlias(0) MacCall(0)); 606 spanless_eq_enum!(FormatAlignment; Left Right Center); 607 spanless_eq_enum!(FormatArgPositionKind; Implicit Number Named); 608 spanless_eq_enum!(FormatArgsPiece; Literal(0) Placeholder(0)); 609 spanless_eq_enum!(FormatArgumentKind; Normal Named(0) Captured(0)); 610 spanless_eq_enum!(FormatCount; Literal(0) Argument(0)); 611 spanless_eq_enum!(FormatDebugHex; Lower Upper); 612 spanless_eq_enum!(FormatSign; Plus Minus); 613 spanless_eq_enum!(FormatTrait; Display Debug LowerExp UpperExp Octal Pointer Binary LowerHex UpperHex); 614 spanless_eq_enum!(GenBlockKind; Async Gen AsyncGen); 615 spanless_eq_enum!(GenericArg; Lifetime(0) Type(0) Const(0)); 616 spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0) ParenthesizedElided(0)); 617 spanless_eq_enum!(GenericBound; Trait(0) Outlives(0) Use(0 1)); 618 spanless_eq_enum!(GenericParamKind; Lifetime Type(default) Const(ty span default)); 619 spanless_eq_enum!(ImplPolarity; Positive Negative(0)); 620 spanless_eq_enum!(Inline; Yes No(had_parse_error)); 621 spanless_eq_enum!(InlineAsmRegOrRegClass; Reg(0) RegClass(0)); 622 spanless_eq_enum!(InlineAsmTemplatePiece; String(0) Placeholder(operand_idx modifier span)); 623 spanless_eq_enum!(IntTy; Isize I8 I16 I32 I64 I128); 624 spanless_eq_enum!(IsAuto; Yes No); 625 spanless_eq_enum!(LitFloatType; Suffixed(0) Unsuffixed); 626 spanless_eq_enum!(LitIntType; Signed(0) Unsigned(0) Unsuffixed); 627 spanless_eq_enum!(LocalKind; Decl Init(0) InitElse(0 1)); 628 spanless_eq_enum!(MacStmtStyle; Semicolon Braces NoBraces); 629 spanless_eq_enum!(MatchKind; Prefix Postfix); 630 spanless_eq_enum!(MetaItemInner; MetaItem(0) Lit(0)); 631 spanless_eq_enum!(MetaItemKind; Word List(0) NameValue(0)); 632 spanless_eq_enum!(ModKind; Loaded(0 1 2) Unloaded); 633 spanless_eq_enum!(Movability; Static Movable); 634 spanless_eq_enum!(Mutability; Mut Not); 635 spanless_eq_enum!(Parens; Yes No); 636 spanless_eq_enum!(PatFieldsRest; Rest(0) Recovered(0) None); 637 spanless_eq_enum!(Pinnedness; Not Pinned); 638 spanless_eq_enum!(PreciseCapturingArg; Lifetime(0) Arg(0 1)); 639 spanless_eq_enum!(RangeEnd; Included(0) Excluded); 640 spanless_eq_enum!(RangeLimits; HalfOpen Closed); 641 spanless_eq_enum!(Recovered; No Yes(0)); 642 spanless_eq_enum!(RestrictionKind; Unrestricted Restricted(path id shorthand)); 643 spanless_eq_enum!(Safety; Unsafe(0) Safe(0) Default); 644 spanless_eq_enum!(StmtKind; Let(0) Item(0) Expr(0) Semi(0) Empty MacCall(0)); 645 spanless_eq_enum!(StrStyle; Cooked Raw(0)); 646 spanless_eq_enum!(StructRest; Base(0) Rest(0) None NoneWithError(0)); 647 spanless_eq_enum!(Term; Ty(0) Const(0)); 648 spanless_eq_enum!(TokenTree; Token(0 1) Delimited(0 1 2 3)); 649 spanless_eq_enum!(TraitObjectSyntax; Dyn None); 650 spanless_eq_enum!(TyPatKind; Range(0 1 2) NotNull Or(0) Err(0)); 651 spanless_eq_enum!(UintTy; Usize U8 U16 U32 U64 U128); 652 spanless_eq_enum!(UnOp; Deref Not Neg); 653 spanless_eq_enum!(UnsafeBinderCastKind; Wrap Unwrap); 654 spanless_eq_enum!(UnsafeSource; CompilerGenerated UserProvided); 655 spanless_eq_enum!(UseTreeKind; Simple(0) Nested(items span) Glob(0)); 656 spanless_eq_enum!(VariantData; Struct(fields recovered) Tuple(0 1) Unit(0)); 657 spanless_eq_enum!(VisibilityKind; Public Restricted(path id shorthand) Inherited); 658 spanless_eq_enum!(WherePredicateKind; BoundPredicate(0) RegionPredicate(0)); 659 spanless_eq_enum!(YieldKind; Prefix(0) Postfix(0)); 660 spanless_eq_enum!(AssignOpKind; AddAssign SubAssign MulAssign DivAssign 661 RemAssign BitXorAssign BitAndAssign BitOrAssign ShlAssign ShrAssign); 662 spanless_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)); 665 spanless_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); 674 spanless_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)); 677 spanless_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)); 681 spanless_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)); 683 spanless_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)); 687 spanless_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 692 impl SpanlessEq for Ident { 693 fn eq(&self, other: &Self) -> bool { 694 self.as_str() == other.as_str() 695 } 696 } 697 698 impl SpanlessEq for RangeSyntax { 699 fn eq(&self, _other: &Self) -> bool { 700 match self { 701 RangeSyntax::DotDotDot | RangeSyntax::DotDotEq => true, 702 } 703 } 704 } 705 706 impl 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 734 impl 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 747 impl 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 782 fn doc_comment<'a>( 783 style: AttrStyle, 784 unescaped: Symbol, 785 trees: &mut impl Iterator, 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 835 fn 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 848 fn 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 860 fn 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 874 fn 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 883 impl 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 891 impl 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 922 impl SpanlessEq for FormatArguments { 923 fn eq(&self, other: &Self) -> bool { 924 SpanlessEq::eq(self.all_args(), other.all_args()) 925 } 926 }