Implement eq for libsyntax data structures
diff --git a/tests/common/eq.rs b/tests/common/eq.rs
new file mode 100644
index 0000000..887c22b
--- /dev/null
+++ b/tests/common/eq.rs
@@ -0,0 +1,446 @@
+extern crate rustc_data_structures;
+extern crate rustc_target;
+extern crate syntax;
+extern crate syntax_pos;
+
+use std::mem;
+
+use self::rustc_data_structures::sync::Lrc;
+use self::rustc_target::abi::FloatTy;
+use self::rustc_target::spec::abi::Abi;
+use self::syntax::ast::{
+    AngleBracketedArgs, AnonConst, Arg, Arm, AsmDialect, AttrId, AttrStyle, Attribute, BareFnTy,
+    BinOpKind, BindingMode, Block, BlockCheckMode, CaptureBy, Constness, Crate, CrateSugar,
+    Defaultness, EnumDef, Expr, ExprKind, Field, FieldPat, FnDecl, FnHeader, ForeignItem,
+    ForeignItemKind, ForeignMod, FunctionRetTy, GenericArg, GenericArgs, GenericBound,
+    GenericParam, GenericParamKind, Generics, GlobalAsm, Ident, ImplItem, ImplItemKind,
+    ImplPolarity, InlineAsm, InlineAsmOutput, IntTy, IsAsync, IsAuto, Item, ItemKind, Label,
+    Lifetime, LitIntType, LitKind, Local, MacDelimiter, MacStmtStyle, Mac_, MacroDef, MethodSig,
+    Mod, Movability, MutTy, Mutability, NodeId, ParenthesisedArgs, Pat, PatKind, Path, PathSegment,
+    PolyTraitRef, QSelf, RangeEnd, RangeLimits, RangeSyntax, Stmt, StmtKind, StrStyle, StructField,
+    TraitBoundModifier, TraitItem, TraitItemKind, TraitObjectSyntax, TraitRef, Ty, TyKind,
+    TypeBinding, UintTy, UnOp, UnsafeSource, Unsafety, UseTree, UseTreeKind, VariantData, Variant_,
+    VisibilityKind, WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate,
+    WhereRegionPredicate,
+};
+use self::syntax::codemap::Spanned;
+use self::syntax::parse::lexer::comments;
+use self::syntax::parse::token::{DelimToken, Lit, Token};
+use self::syntax::ptr::P;
+use self::syntax::symbol::Symbol;
+use self::syntax::tokenstream::{Delimited, ThinTokenStream, TokenStream, TokenTree};
+use self::syntax::util::ThinVec;
+use self::syntax_pos::{Span, SyntaxContext, DUMMY_SP};
+
+pub trait SpanlessEq {
+    fn eq(&self, other: &Self) -> bool;
+}
+
+impl<T: SpanlessEq> SpanlessEq for P<T> {
+    fn eq(&self, other: &Self) -> bool {
+        SpanlessEq::eq(&**self, &**other)
+    }
+}
+
+impl<T: SpanlessEq> SpanlessEq for Lrc<T> {
+    fn eq(&self, other: &Self) -> bool {
+        SpanlessEq::eq(&**self, &**other)
+    }
+}
+
+impl<T: SpanlessEq> SpanlessEq for Option<T> {
+    fn eq(&self, other: &Self) -> bool {
+        match (self, other) {
+            (None, None) => true,
+            (Some(this), Some(other)) => SpanlessEq::eq(this, other),
+            _ => false,
+        }
+    }
+}
+
+impl<T: SpanlessEq> SpanlessEq for Vec<T> {
+    fn eq(&self, other: &Self) -> bool {
+        self.len() == other.len() && self.iter().zip(other).all(|(a, b)| SpanlessEq::eq(a, b))
+    }
+}
+
+impl<T: SpanlessEq> SpanlessEq for ThinVec<T> {
+    fn eq(&self, other: &Self) -> bool {
+        self.len() == other.len()
+            && self
+                .iter()
+                .zip(other.iter())
+                .all(|(a, b)| SpanlessEq::eq(a, b))
+    }
+}
+
+impl<T: SpanlessEq> SpanlessEq for Spanned<T> {
+    fn eq(&self, other: &Self) -> bool {
+        SpanlessEq::eq(&self.node, &other.node)
+    }
+}
+
+impl<A: SpanlessEq, B: SpanlessEq> SpanlessEq for (A, B) {
+    fn eq(&self, other: &Self) -> bool {
+        SpanlessEq::eq(&self.0, &other.0) && SpanlessEq::eq(&self.1, &other.1)
+    }
+}
+
+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 {
+            fn eq(&self, _other: &Self) -> bool {
+                true
+            }
+        }
+    };
+}
+
+spanless_eq_true!(Span);
+spanless_eq_true!(AttrId);
+spanless_eq_true!(NodeId);
+spanless_eq_true!(SyntaxContext);
+
+macro_rules! spanless_eq_partial_eq {
+    ($name:ident) => {
+        impl SpanlessEq for $name {
+            fn eq(&self, other: &Self) -> bool {
+                PartialEq::eq(self, other)
+            }
+        }
+    };
+}
+
+spanless_eq_partial_eq!(bool);
+spanless_eq_partial_eq!(u8);
+spanless_eq_partial_eq!(u16);
+spanless_eq_partial_eq!(u128);
+spanless_eq_partial_eq!(usize);
+spanless_eq_partial_eq!(char);
+spanless_eq_partial_eq!(Symbol);
+spanless_eq_partial_eq!(Abi);
+spanless_eq_partial_eq!(DelimToken);
+
+macro_rules! spanless_eq_struct {
+    {
+        $name:ident;
+        $([$field:ident $other:ident])*
+        $(![$ignore:ident])*
+    } => {
+        impl SpanlessEq for $name {
+            fn eq(&self, other: &Self) -> bool {
+                let $name { $($field,)* $($ignore: _,)* } = self;
+                let $name { $($field: $other,)* $($ignore: _,)* } = other;
+                $(SpanlessEq::eq($field, $other))&&*
+            }
+        }
+    };
+
+    {
+        $name:ident;
+        $([$field:ident $other:ident])*
+        $next:ident
+        $($rest:ident)*
+        $(!$ignore:ident)*
+    } => {
+        spanless_eq_struct! {
+            $name;
+            $([$field $other])*
+            [$next other]
+            $($rest)*
+            $(!$ignore)*
+        }
+    };
+
+    {
+        $name:ident;
+        $([$field:ident $other:ident])*
+        $(![$ignore:ident])*
+        !$next:ident
+        $(!$rest:ident)*
+    } => {
+        spanless_eq_struct! {
+            $name;
+            $([$field $other])*
+            $(![$ignore])*
+            ![$next]
+            $(!$rest)*
+        }
+    };
+}
+
+macro_rules! spanless_eq_enum {
+    {
+        $name:ident;
+        $([$variant:ident $([$field:tt $this:ident $other:ident])*])*
+    } => {
+        impl SpanlessEq for $name {
+            fn eq(&self, other: &Self) -> bool {
+                match self {
+                    $(
+                        $name::$variant { .. } => {}
+                    )*
+                }
+                match (self, other) {
+                    $(
+                        (
+                            $name::$variant { $($field: $this),* },
+                            $name::$variant { $($field: $other),* },
+                        ) => {
+                            true $(&& SpanlessEq::eq($this, $other))*
+                        }
+                    )*
+                    _ => false,
+                }
+            }
+        }
+    };
+
+    {
+        $name:ident;
+        $([$variant:ident $($fields:tt)*])*
+        $next:ident [$($named:tt)*] ( $i:tt $($field:tt)* )
+        $($rest:tt)*
+    } => {
+        spanless_eq_enum! {
+            $name;
+            $([$variant $($fields)*])*
+            $next [$($named)* [$i this other]] ( $($field)* )
+            $($rest)*
+        }
+    };
+
+    {
+        $name:ident;
+        $([$variant:ident $($fields:tt)*])*
+        $next:ident [$($named:tt)*] ()
+        $($rest:tt)*
+    } => {
+        spanless_eq_enum! {
+            $name;
+            $([$variant $($fields)*])*
+            [$next $($named)*]
+            $($rest)*
+        }
+    };
+
+    {
+        $name:ident;
+        $([$variant:ident $($fields:tt)*])*
+        $next:ident ( $($field:tt)* )
+        $($rest:tt)*
+    } => {
+        spanless_eq_enum! {
+            $name;
+            $([$variant $($fields)*])*
+            $next [] ( $($field)* )
+            $($rest)*
+        }
+    };
+
+    {
+        $name:ident;
+        $([$variant:ident $($fields:tt)*])*
+        $next:ident
+        $($rest:tt)*
+    } => {
+        spanless_eq_enum! {
+            $name;
+            $([$variant $($fields)*])*
+            [$next]
+            $($rest)*
+        }
+    };
+}
+
+spanless_eq_struct!(AngleBracketedArgs; span args bindings);
+spanless_eq_struct!(AnonConst; id value);
+spanless_eq_struct!(Arg; ty pat id);
+spanless_eq_struct!(Arm; attrs pats guard body);
+spanless_eq_struct!(Attribute; id style path tokens span !is_sugared_doc);
+spanless_eq_struct!(BareFnTy; unsafety abi generic_params decl);
+spanless_eq_struct!(Block; stmts id rules span recovered);
+spanless_eq_struct!(Crate; module attrs span);
+spanless_eq_struct!(Delimited; delim tts);
+spanless_eq_struct!(EnumDef; variants);
+spanless_eq_struct!(Expr; id node span attrs);
+spanless_eq_struct!(Field; ident expr span is_shorthand attrs);
+spanless_eq_struct!(FieldPat; ident pat is_shorthand attrs);
+spanless_eq_struct!(FnDecl; inputs output variadic);
+spanless_eq_struct!(FnHeader; unsafety asyncness constness abi);
+spanless_eq_struct!(ForeignItem; ident attrs node id span vis);
+spanless_eq_struct!(ForeignMod; abi items);
+spanless_eq_struct!(GenericParam; id ident attrs bounds kind);
+spanless_eq_struct!(Generics; params where_clause span);
+spanless_eq_struct!(GlobalAsm; asm ctxt);
+spanless_eq_struct!(ImplItem; id ident vis defaultness attrs generics node span !tokens);
+spanless_eq_struct!(InlineAsm; asm asm_str_style outputs inputs clobbers volatile alignstack dialect ctxt);
+spanless_eq_struct!(InlineAsmOutput; constraint expr is_rw is_indirect);
+spanless_eq_struct!(Item; ident attrs id node vis span !tokens);
+spanless_eq_struct!(Label; ident);
+spanless_eq_struct!(Lifetime; id ident);
+spanless_eq_struct!(Local; pat ty init id span attrs);
+spanless_eq_struct!(Mac_; path delim tts);
+spanless_eq_struct!(MacroDef; tokens legacy);
+spanless_eq_struct!(MethodSig; header decl);
+spanless_eq_struct!(Mod; inner items);
+spanless_eq_struct!(MutTy; ty mutbl);
+spanless_eq_struct!(ParenthesisedArgs; span inputs output);
+spanless_eq_struct!(Pat; id node span);
+spanless_eq_struct!(Path; span segments);
+spanless_eq_struct!(PathSegment; ident args);
+spanless_eq_struct!(PolyTraitRef; bound_generic_params trait_ref span);
+spanless_eq_struct!(QSelf; ty path_span position);
+spanless_eq_struct!(Stmt; id node span);
+spanless_eq_struct!(StructField; span ident vis id ty attrs);
+spanless_eq_struct!(TraitItem; id ident attrs generics node span !tokens);
+spanless_eq_struct!(TraitRef; path ref_id);
+spanless_eq_struct!(Ty; id node span);
+spanless_eq_struct!(TypeBinding; id ident ty span);
+spanless_eq_struct!(UseTree; prefix kind span);
+spanless_eq_struct!(Variant_; ident attrs data disr_expr);
+spanless_eq_struct!(WhereBoundPredicate; span bound_generic_params bounded_ty bounds);
+spanless_eq_struct!(WhereClause; id predicates span);
+spanless_eq_struct!(WhereEqPredicate; id span lhs_ty rhs_ty);
+spanless_eq_struct!(WhereRegionPredicate; span lifetime bounds);
+spanless_eq_enum!(AsmDialect; Att Intel);
+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));
+spanless_eq_enum!(BlockCheckMode; Default Unsafe(0));
+spanless_eq_enum!(CaptureBy; Value Ref);
+spanless_eq_enum!(Constness; Const NotConst);
+spanless_eq_enum!(CrateSugar; PubCrate JustCrate);
+spanless_eq_enum!(Defaultness; Default Final);
+spanless_eq_enum!(FloatTy; F32 F64);
+spanless_eq_enum!(ForeignItemKind; Fn(0 1) Static(0 1) Ty Macro(0));
+spanless_eq_enum!(FunctionRetTy; Default(0) Ty(0));
+spanless_eq_enum!(GenericArg; Lifetime(0) Type(0));
+spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0));
+spanless_eq_enum!(GenericBound; Trait(0 1) Outlives(0));
+spanless_eq_enum!(GenericParamKind; Lifetime Type(default));
+spanless_eq_enum!(ImplItemKind; Const(0 1) Method(0 1) Type(0) Macro(0));
+spanless_eq_enum!(ImplPolarity; Positive Negative);
+spanless_eq_enum!(IntTy; Isize I8 I16 I32 I64 I128);
+spanless_eq_enum!(IsAsync; Async(closure_id return_impl_trait_id) NotAsync);
+spanless_eq_enum!(IsAuto; Yes No);
+spanless_eq_enum!(LitIntType; Signed(0) Unsigned(0) Unsuffixed);
+spanless_eq_enum!(MacDelimiter; Parenthesis Bracket Brace);
+spanless_eq_enum!(MacStmtStyle; Semicolon Braces NoBraces);
+spanless_eq_enum!(Movability; Static Movable);
+spanless_eq_enum!(Mutability; Mutable Immutable);
+spanless_eq_enum!(RangeEnd; Included(0) Excluded);
+spanless_eq_enum!(RangeLimits; HalfOpen Closed);
+spanless_eq_enum!(RangeSyntax; DotDotDot DotDotEq);
+spanless_eq_enum!(StmtKind; Local(0) Item(0) Expr(0) Semi(0) Mac(0));
+spanless_eq_enum!(StrStyle; Cooked Raw(0));
+spanless_eq_enum!(TokenTree; Token(0 1) Delimited(0 1));
+spanless_eq_enum!(TraitBoundModifier; None Maybe);
+spanless_eq_enum!(TraitItemKind; Const(0 1) Method(0 1) Type(0 1) Macro(0));
+spanless_eq_enum!(TraitObjectSyntax; Dyn None);
+spanless_eq_enum!(UintTy; Usize U8 U16 U32 U64 U128);
+spanless_eq_enum!(UnOp; Deref Not Neg);
+spanless_eq_enum!(UnsafeSource; CompilerGenerated UserProvided);
+spanless_eq_enum!(Unsafety; Unsafe Normal);
+spanless_eq_enum!(UseTreeKind; Simple(0 1 2) Nested(0) Glob);
+spanless_eq_enum!(VariantData; Struct(0 1) Tuple(0 1) Unit(0));
+spanless_eq_enum!(VisibilityKind; Public Crate(0) Restricted(path id) Inherited);
+spanless_eq_enum!(WherePredicate; BoundPredicate(0) RegionPredicate(0) EqPredicate(0));
+spanless_eq_enum!(ExprKind; Box(0) ObsoleteInPlace(0 1) Array(0) Call(0 1)
+    MethodCall(0 1) Tup(0) Binary(0 1 2) Unary(0 1) Lit(0) Cast(0 1) Type(0 1)
+    If(0 1 2) IfLet(0 1 2 3) While(0 1 2) WhileLet(0 1 2 3) ForLoop(0 1 2 3)
+    Loop(0 1) Match(0 1) Closure(0 1 2 3 4 5) Block(0 1) Async(0 1 2) Catch(0)
+    Assign(0 1) AssignOp(0 1 2) Field(0 1) Index(0 1) Range(0 1 2) Path(0 1)
+    AddrOf(0 1) Break(0 1) Continue(0) Ret(0) InlineAsm(0) Mac(0) Struct(0 1 2)
+    Repeat(0 1) Paren(0) Try(0) Yield(0));
+spanless_eq_enum!(ItemKind; ExternCrate(0) Use(0) Static(0 1 2) Const(0 1)
+    Fn(0 1 2 3) Mod(0) ForeignMod(0) GlobalAsm(0) Ty(0 1) Enum(0 1) Struct(0 1)
+    Union(0 1) Trait(0 1 2 3 4) TraitAlias(0 1) Impl(0 1 2 3 4 5 6) Mac(0)
+    MacroDef(0));
+spanless_eq_enum!(LitKind; Str(0 1) ByteStr(0) Byte(0) Char(0) Int(0 1)
+    Float(0 1) FloatUnsuffixed(0) Bool(0));
+spanless_eq_enum!(PatKind; Wild Ident(0 1 2) Struct(0 1 2) TupleStruct(0 1 2)
+    Path(0 1) Tuple(0 1) Box(0) Ref(0 1) Lit(0) Range(0 1 2) Slice(0 1 2)
+    Paren(0) Mac(0));
+spanless_eq_enum!(TyKind; Slice(0) Array(0 1) Ptr(0) Rptr(0 1) BareFn(0) Never
+    Tup(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) Paren(0) Typeof(0) Infer
+    ImplicitSelf Mac(0) Err);
+
+impl SpanlessEq for Ident {
+    fn eq(&self, other: &Self) -> bool {
+        self.as_str() == other.as_str()
+    }
+}
+
+// Give up on comparing literals inside of macros because there are so many
+// equivalent representations of the same literal; they are tested elsewhere
+impl SpanlessEq for Lit {
+    fn eq(&self, other: &Self) -> bool {
+        mem::discriminant(self) == mem::discriminant(other)
+    }
+}
+
+impl SpanlessEq for Token {
+    fn eq(&self, other: &Self) -> bool {
+        match (self, other) {
+            (Token::Literal(this, _), Token::Literal(other, _)) => SpanlessEq::eq(this, other),
+            _ => self == other,
+        }
+    }
+}
+
+impl SpanlessEq for TokenStream {
+    fn eq(&self, other: &Self) -> bool {
+        SpanlessEq::eq(&expand_tts(self), &expand_tts(other))
+    }
+}
+
+impl SpanlessEq for ThinTokenStream {
+    fn eq(&self, other: &Self) -> bool {
+        SpanlessEq::eq(
+            &TokenStream::from(self.clone()),
+            &TokenStream::from(other.clone()),
+        )
+    }
+}
+
+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::DocComment(c)) => c,
+            _ => {
+                tokens.push(tt);
+                continue;
+            }
+        };
+        let contents = comments::strip_doc_comment_decoration(&c.as_str());
+        let style = comments::doc_comment_style(&c.as_str());
+        tokens.push(TokenTree::Token(DUMMY_SP, Token::Pound));
+        if style == AttrStyle::Inner {
+            tokens.push(TokenTree::Token(DUMMY_SP, Token::Not));
+        }
+        let lit = Lit::Str_(Symbol::intern(&contents));
+        let mut tts = vec![
+            TokenTree::Token(DUMMY_SP, Token::Ident(Ident::from_str("doc"), false)),
+            TokenTree::Token(DUMMY_SP, Token::Eq),
+            TokenTree::Token(DUMMY_SP, Token::Literal(lit, None)),
+        ];
+        tokens.push(TokenTree::Delimited(
+            DUMMY_SP,
+            Delimited {
+                delim: DelimToken::Bracket,
+                tts: tts.into_iter().collect::<TokenStream>().into(),
+            },
+        ));
+    }
+    tokens
+}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 5bffa7b..e94f70f 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -17,8 +17,8 @@
 
 use self::walkdir::DirEntry;
 
+pub mod eq;
 pub mod parse;
-pub mod respan;
 
 pub fn check_min_stack() {
     let min_stack_value = match env::var("RUST_MIN_STACK") {
diff --git a/tests/common/respan.rs b/tests/common/respan.rs
deleted file mode 100644
index 3e2d152..0000000
--- a/tests/common/respan.rs
+++ /dev/null
@@ -1,222 +0,0 @@
-// Copyright 2018 Syn Developers
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-extern crate syntax;
-extern crate syntax_pos;
-
-use self::syntax::ast::{
-    AttrStyle, Attribute, Expr, ExprKind, FnHeader, Ident, ImplItem, Item, Mac, MetaItem,
-    MetaItemKind, NestedMetaItem, NestedMetaItemKind, Pat, PatKind, TraitItem, Visibility,
-    WhereClause,
-};
-use self::syntax::codemap::{self, Spanned};
-use self::syntax::fold::{self, Folder};
-use self::syntax::parse::lexer::comments;
-use self::syntax::parse::token::{DelimToken, Lit, Token};
-use self::syntax::ptr::P;
-use self::syntax::symbol::Symbol;
-use self::syntax::tokenstream::{Delimited, TokenStream, TokenTree};
-use self::syntax::util::move_map::MoveMap;
-use self::syntax::util::small_vector::SmallVector;
-
-use self::syntax::ast;
-use self::syntax_pos::{Span, DUMMY_SP};
-
-struct Respanner;
-
-impl Respanner {
-    fn fold_spanned<T>(&mut self, spanned: Spanned<T>) -> Spanned<T> {
-        codemap::respan(self.new_span(spanned.span), spanned.node)
-    }
-
-    fn fold_lit(&mut self, l: Lit) -> Lit {
-        // Give up on comparing literals inside of macros because there are
-        // so many equivalent representations of the same literal; they are
-        // tested elsewhere
-        match l {
-            Lit::Byte(_) => Lit::Byte(Symbol::intern("")),
-            Lit::Char(_) => Lit::Char(Symbol::intern("")),
-            Lit::Integer(_) => Lit::Integer(Symbol::intern("")),
-            Lit::Float(_) => Lit::Float(Symbol::intern("")),
-            Lit::Str_(_) => Lit::Str_(Symbol::intern("")),
-            Lit::ByteStr(_) => Lit::ByteStr(Symbol::intern("")),
-            _ => l,
-        }
-    }
-}
-
-impl Folder for Respanner {
-    fn new_span(&mut self, _: Span) -> Span {
-        DUMMY_SP
-    }
-
-    fn fold_item(&mut self, i: P<Item>) -> SmallVector<P<Item>> {
-        let i = i.map(|mut i| {
-            i.tokens = None;
-            i
-        });
-        fold::noop_fold_item(i, self)
-    }
-
-    fn fold_fn_header(&mut self, header: FnHeader) -> FnHeader {
-        FnHeader {
-            // default fold_item_kind does not fold this span
-            constness: self.fold_spanned(header.constness),
-            ..fold::noop_fold_fn_header(header, self)
-        }
-    }
-
-    fn fold_expr(&mut self, e: P<Expr>) -> P<Expr> {
-        e.map(|e| {
-            let folded = fold::noop_fold_expr(e, self);
-            Expr {
-                node: match folded.node {
-                    ExprKind::Lit(l) => {
-                        // default fold_expr does not fold lits
-                        ExprKind::Lit(l.map(|l| self.fold_spanned(l)))
-                    }
-                    ExprKind::Binary(op, lhs, rhs) => {
-                        // default fold_expr does not fold the op span
-                        ExprKind::Binary(self.fold_spanned(op), lhs, rhs)
-                    }
-                    ExprKind::AssignOp(op, lhs, rhs) => {
-                        // default fold_expr does not fold the op span
-                        ExprKind::AssignOp(self.fold_spanned(op), lhs, rhs)
-                    }
-                    other => other,
-                },
-                ..folded
-            }
-        })
-    }
-
-    fn fold_pat(&mut self, p: P<Pat>) -> P<Pat> {
-        fold::noop_fold_pat(p, self).map(|mut p| {
-            if let PatKind::Range(_, _, ref mut end) = p.node {
-                end.span = self.new_span(end.span);
-            }
-            p
-        })
-    }
-
-    fn fold_trait_item(&mut self, mut i: TraitItem) -> SmallVector<TraitItem> {
-        i.tokens = None;
-        fold::noop_fold_trait_item(i, self)
-    }
-
-    fn fold_impl_item(&mut self, mut i: ImplItem) -> SmallVector<ImplItem> {
-        i.tokens = None;
-        fold::noop_fold_impl_item(i, self)
-    }
-
-    fn fold_attribute(&mut self, mut at: Attribute) -> Option<Attribute> {
-        at.id.0 = 0;
-        at.is_sugared_doc = false;
-        fold::noop_fold_attribute(at, self)
-    }
-
-    fn fold_meta_item(&mut self, meta_item: MetaItem) -> MetaItem {
-        let MetaItem { ident, node, span } = meta_item;
-        MetaItem {
-            ident,
-            node: match node {
-                MetaItemKind::Word => MetaItemKind::Word,
-                MetaItemKind::List(nested) => {
-                    MetaItemKind::List(nested.move_map(|e| self.fold_meta_list_item(e)))
-                }
-                // default fold_meta_item does not fold the value span
-                MetaItemKind::NameValue(lit) => MetaItemKind::NameValue(self.fold_spanned(lit)),
-            },
-            span: self.new_span(span),
-        }
-    }
-
-    fn fold_meta_list_item(&mut self, list_item: NestedMetaItem) -> NestedMetaItem {
-        Spanned {
-            node: match list_item.node {
-                NestedMetaItemKind::MetaItem(mi) => {
-                    NestedMetaItemKind::MetaItem(self.fold_meta_item(mi))
-                }
-                // default fold_meta_list_item does not fold the span
-                NestedMetaItemKind::Literal(lit) => {
-                    NestedMetaItemKind::Literal(self.fold_spanned(lit))
-                }
-            },
-            span: self.new_span(list_item.span),
-        }
-    }
-
-    // This folder is disabled by default.
-    fn fold_mac(&mut self, mac: Mac) -> Mac {
-        fold::noop_fold_mac(mac, self)
-    }
-
-    fn fold_token(&mut self, t: Token) -> Token {
-        fold::noop_fold_token(
-            match t {
-                // default fold_token does not fold literals
-                Token::Literal(lit, repr) => Token::Literal(self.fold_lit(lit), repr),
-                _ => t,
-            },
-            self,
-        )
-    }
-
-    fn fold_vis(&mut self, vis: Visibility) -> Visibility {
-        fold::noop_fold_vis(self.fold_spanned(vis), self)
-    }
-
-    fn fold_where_clause(&mut self, mut clause: WhereClause) -> WhereClause {
-        // default fold_where_clause does not fold the span
-        clause.span = self.new_span(clause.span);
-        fold::noop_fold_where_clause(clause, self)
-    }
-
-    fn fold_tts(&mut self, tts: TokenStream) -> TokenStream {
-        let mut tokens = Vec::new();
-        for tt in tts.into_trees() {
-            let c = match tt {
-                TokenTree::Token(_, Token::DocComment(c)) => c,
-                _ => {
-                    tokens.push(tt);
-                    continue;
-                }
-            };
-            let contents = comments::strip_doc_comment_decoration(&c.as_str());
-            let style = comments::doc_comment_style(&c.as_str());
-            tokens.push(TokenTree::Token(DUMMY_SP, Token::Pound));
-            if style == AttrStyle::Inner {
-                tokens.push(TokenTree::Token(DUMMY_SP, Token::Not));
-            }
-            let lit = Lit::Str_(Symbol::intern(&contents));
-            let mut tts = vec![
-                TokenTree::Token(DUMMY_SP, Token::Ident(Ident::from_str("doc"), false)),
-                TokenTree::Token(DUMMY_SP, Token::Eq),
-                TokenTree::Token(DUMMY_SP, Token::Literal(lit, None)),
-            ];
-            tokens.push(TokenTree::Delimited(
-                DUMMY_SP,
-                Delimited {
-                    delim: DelimToken::Bracket,
-                    tts: tts.into_iter().collect::<TokenStream>().into(),
-                },
-            ));
-        }
-        tokens.into_iter().map(|tt| self.fold_tt(tt)).collect()
-    }
-}
-
-#[allow(dead_code)]
-pub fn respan_crate(krate: ast::Crate) -> ast::Crate {
-    Respanner.fold_crate(krate)
-}
-
-#[allow(dead_code)]
-pub fn respan_expr(expr: P<ast::Expr>) -> P<ast::Expr> {
-    Respanner.fold_expr(expr)
-}
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index a8c4881..fe33fbd 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -7,6 +7,7 @@
 // except according to those terms.
 
 #![cfg(feature = "extra-traits")]
+#![recursion_limit = "1024"]
 #![feature(rustc_private)]
 
 extern crate syn;
diff --git a/tests/test_grouping.rs b/tests/test_grouping.rs
index a25c99f..619e9ff 100644
--- a/tests/test_grouping.rs
+++ b/tests/test_grouping.rs
@@ -7,6 +7,7 @@
 // except according to those terms.
 
 #![cfg(all(feature = "extra-traits", feature = "full"))]
+#![recursion_limit = "1024"]
 #![feature(rustc_private)]
 
 #[macro_use]
diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs
index 1066b92..0daa23e 100644
--- a/tests/test_precedence.rs
+++ b/tests/test_precedence.rs
@@ -7,6 +7,7 @@
 // except according to those terms.
 
 #![cfg(all(feature = "full", feature = "fold"))]
+#![recursion_limit = "1024"]
 #![feature(rustc_private)]
 
 //! The tests in this module do the following:
@@ -37,7 +38,8 @@
 use std::process;
 use std::sync::atomic::{AtomicUsize, Ordering};
 
-use common::{parse, respan};
+use common::eq::SpanlessEq;
+use common::parse;
 
 #[macro_use]
 mod macros;
@@ -184,10 +186,7 @@
                 continue;
             };
 
-            let syn_ast = respan::respan_expr(syn_ast);
-            let libsyntax_ast = respan::respan_expr(libsyntax_ast);
-
-            if syn_ast == libsyntax_ast {
+            if SpanlessEq::eq(&syn_ast, &libsyntax_ast) {
                 passed += 1;
             } else {
                 failed += 1;
diff --git a/tests/test_round_trip.rs b/tests/test_round_trip.rs
index 4659be4..3e993fb 100644
--- a/tests/test_round_trip.rs
+++ b/tests/test_round_trip.rs
@@ -7,6 +7,7 @@
 // except according to those terms.
 
 #![cfg(feature = "full")]
+#![recursion_limit = "1024"]
 #![feature(rustc_private)]
 
 #[macro_use]
@@ -37,6 +38,8 @@
 #[allow(dead_code)]
 mod common;
 
+use common::eq::SpanlessEq;
+
 #[test]
 fn test_round_trip() {
     common::check_min_stack();
@@ -110,7 +113,7 @@
                         }
                     };
 
-                    if before == after {
+                    if SpanlessEq::eq(&before, &after) {
                         errorf!(
                             "=== {}: pass in {}ms\n",
                             path.display(),
@@ -149,5 +152,5 @@
 
 fn libsyntax_parse(content: String, sess: &ParseSess) -> PResult<ast::Crate> {
     let name = FileName::Custom("test_round_trip".to_string());
-    parse::parse_crate_from_source_str(name, content, sess).map(common::respan::respan_crate)
+    parse::parse_crate_from_source_str(name, content, sess)
 }