diff options
Diffstat (limited to 'tests/common/eq.rs')
-rw-r--r-- | tests/common/eq.rs | 84 |
1 files changed, 27 insertions, 57 deletions
diff --git a/tests/common/eq.rs b/tests/common/eq.rs index 247a58b7..7589a075 100644 --- a/tests/common/eq.rs +++ b/tests/common/eq.rs @@ -14,22 +14,22 @@ use rustc_ast::ast::{ GenericParam, GenericParamKind, Generics, GlobalAsm, ImplPolarity, InlineAsm, InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece, IntTy, IsAuto, Item, ItemKind, Label, Lifetime, Lit, LitFloatType, LitIntType, LitKind, LlvmAsmDialect, - LlvmInlineAsm, LlvmInlineAsmOutput, Local, MacArgs, MacCall, MacDelimiter, MacStmtStyle, - MacroDef, Mod, Movability, MutTy, Mutability, NodeId, Param, ParenthesizedArgs, Pat, PatKind, - Path, PathSegment, PolyTraitRef, QSelf, RangeEnd, RangeLimits, RangeSyntax, Stmt, StmtKind, - StrLit, StrStyle, StructField, TraitBoundModifier, TraitObjectSyntax, TraitRef, Ty, TyKind, - UintTy, UnOp, Unsafe, UnsafeSource, UseTree, UseTreeKind, Variant, VariantData, VisibilityKind, - WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate, WhereRegionPredicate, + LlvmInlineAsm, LlvmInlineAsmOutput, Local, MacArgs, MacCall, MacCallStmt, MacDelimiter, + MacStmtStyle, MacroDef, Mod, Movability, MutTy, Mutability, NodeId, Param, ParenthesizedArgs, + Pat, PatKind, Path, PathSegment, PolyTraitRef, QSelf, RangeEnd, RangeLimits, RangeSyntax, Stmt, + StmtKind, StrLit, StrStyle, StructField, TraitBoundModifier, TraitObjectSyntax, TraitRef, Ty, + TyKind, UintTy, UnOp, Unsafe, UnsafeSource, UseTree, UseTreeKind, Variant, VariantData, + VisibilityKind, WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate, + WhereRegionPredicate, }; use rustc_ast::ptr::P; -use rustc_ast::token::{self, DelimToken, Token, TokenKind}; +use rustc_ast::token::{self, CommentKind, DelimToken, Token, TokenKind}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree}; -use rustc_ast::util::comments; use rustc_data_structures::sync::Lrc; use rustc_data_structures::thin_vec::ThinVec; use rustc_span::source_map::Spanned; use rustc_span::symbol::Ident; -use rustc_span::{sym, Span, Symbol, SyntaxContext, DUMMY_SP}; +use rustc_span::{Span, Symbol, SyntaxContext}; pub trait SpanlessEq { fn eq(&self, other: &Self) -> bool; @@ -85,14 +85,6 @@ impl<A: SpanlessEq, B: SpanlessEq> SpanlessEq for (A, B) { } } -impl<A: SpanlessEq, B: SpanlessEq, C: SpanlessEq> SpanlessEq for (A, B, C) { - fn eq(&self, other: &Self) -> bool { - SpanlessEq::eq(&self.0, &other.0) - && SpanlessEq::eq(&self.1, &other.1) - && SpanlessEq::eq(&self.2, &other.2) - } -} - macro_rules! spanless_eq_true { ($name:ident) => { impl SpanlessEq for $name { @@ -127,6 +119,7 @@ spanless_eq_partial_eq!(usize); spanless_eq_partial_eq!(char); spanless_eq_partial_eq!(String); spanless_eq_partial_eq!(Symbol); +spanless_eq_partial_eq!(CommentKind); spanless_eq_partial_eq!(DelimToken); spanless_eq_partial_eq!(InlineAsmOptions); @@ -278,7 +271,7 @@ spanless_eq_struct!(Field; attrs id span ident expr is_shorthand is_placeholder) spanless_eq_struct!(FieldPat; ident pat is_shorthand attrs id span is_placeholder); spanless_eq_struct!(FnDecl; inputs output); spanless_eq_struct!(FnHeader; constness asyncness unsafety ext); -spanless_eq_struct!(FnSig; header decl); +spanless_eq_struct!(FnSig; header decl span); spanless_eq_struct!(ForeignMod; abi items); spanless_eq_struct!(GenericParam; id ident attrs bounds is_placeholder kind); spanless_eq_struct!(Generics; params where_clause span); @@ -292,12 +285,13 @@ spanless_eq_struct!(LlvmInlineAsm; asm asm_str_style outputs inputs clobbers vol spanless_eq_struct!(LlvmInlineAsmOutput; constraint expr is_rw is_indirect); spanless_eq_struct!(Local; pat ty init id span attrs); spanless_eq_struct!(MacCall; path args prior_type_ascription); +spanless_eq_struct!(MacCallStmt; mac style attrs); spanless_eq_struct!(MacroDef; body macro_rules); spanless_eq_struct!(Mod; inner items inline); spanless_eq_struct!(MutTy; ty mutbl); spanless_eq_struct!(Param; attrs ty pat id span is_placeholder); spanless_eq_struct!(ParenthesizedArgs; span inputs output); -spanless_eq_struct!(Pat; id kind span); +spanless_eq_struct!(Pat; id kind span tokens); spanless_eq_struct!(Path; span segments); spanless_eq_struct!(PathSegment; ident id args); spanless_eq_struct!(PolyTraitRef; bound_generic_params trait_ref span); @@ -318,7 +312,7 @@ spanless_eq_enum!(AngleBracketedArg; Arg(0) Constraint(0)); spanless_eq_enum!(AssocItemKind; Const(0 1 2) Fn(0 1 2 3) TyAlias(0 1 2 3) MacCall(0)); spanless_eq_enum!(AssocTyConstraintKind; Equality(ty) Bound(bounds)); spanless_eq_enum!(Async; Yes(span closure_id return_impl_trait_id) No); -spanless_eq_enum!(AttrKind; Normal(0) DocComment(0)); +spanless_eq_enum!(AttrKind; Normal(0) DocComment(0 1)); spanless_eq_enum!(AttrStyle; Outer Inner); spanless_eq_enum!(BinOpKind; Add Sub Mul Div Rem And Or BitXor BitAnd BitOr Shl Shr Eq Lt Le Ne Ge Gt); spanless_eq_enum!(BindingMode; ByRef(0) ByValue(0)); @@ -425,44 +419,20 @@ impl SpanlessEq for TokenKind { impl SpanlessEq for TokenStream { fn eq(&self, other: &Self) -> bool { - SpanlessEq::eq(&expand_tts(self), &expand_tts(other)) - } -} - -fn expand_tts(tts: &TokenStream) -> Vec<TokenTree> { - let mut tokens = Vec::new(); - for tt in tts.clone().into_trees() { - let c = match tt { - TokenTree::Token(Token { - kind: TokenKind::DocComment(c), - .. - }) => c, - _ => { - tokens.push(tt); - continue; + let mut this = self.clone().into_trees(); + let mut other = other.clone().into_trees(); + loop { + let this = match this.next() { + None => return other.next().is_none(), + Some(val) => val, + }; + let other = match other.next() { + None => return false, + Some(val) => val, + }; + if !SpanlessEq::eq(&this, &other) { + return false; } - }; - let contents = comments::strip_doc_comment_decoration(c); - let style = comments::doc_comment_style(c); - tokens.push(TokenTree::token(TokenKind::Pound, DUMMY_SP)); - if style == AttrStyle::Inner { - tokens.push(TokenTree::token(TokenKind::Not, DUMMY_SP)); } - let lit = token::Lit { - kind: token::LitKind::Str, - symbol: Symbol::intern(&contents), - suffix: None, - }; - let tts = vec![ - TokenTree::token(TokenKind::Ident(sym::doc, false), DUMMY_SP), - TokenTree::token(TokenKind::Eq, DUMMY_SP), - TokenTree::token(TokenKind::Literal(lit), DUMMY_SP), - ]; - tokens.push(TokenTree::Delimited( - DelimSpan::dummy(), - DelimToken::Bracket, - tts.into_iter().collect::<TokenStream>().into(), - )); } - tokens } |