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