diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index 35dbd8ccfc..3c16973621 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -15,7 +15,6 @@ //! 5. Compare the expressions with one another, if they are not equal fail. extern crate rustc_data_structures; -extern crate smallvec; extern crate syntax; extern crate syntax_pos; @@ -24,7 +23,6 @@ mod features; use quote::quote; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use regex::Regex; -use smallvec::smallvec; use syntax::ast; use syntax::ptr::P; use syntax_pos::edition::Edition; @@ -211,16 +209,57 @@ fn libsyntax_parse_and_rewrite(input: &str) -> Option> { /// This method operates on libsyntax objects. fn libsyntax_brackets(mut libsyntax_expr: P) -> Option> { use rustc_data_structures::thin_vec::ThinVec; - use smallvec::SmallVec; use std::mem; - use syntax::ast::{Expr, ExprKind, Field, Mac, Pat, Stmt, StmtKind, Ty}; - use syntax::mut_visit::{noop_visit_expr, MutVisitor}; + use syntax::ast::{Block, Expr, ExprKind, Field, Mac, Pat, Stmt, StmtKind, Ty}; + use syntax::mut_visit::MutVisitor; + use syntax::util::map_in_place::MapInPlace; use syntax_pos::DUMMY_SP; struct BracketsVisitor { failed: bool, }; + fn flat_map_field(mut f: Field, vis: &mut T) -> Vec { + if f.is_shorthand { + noop_visit_expr(&mut f.expr, vis); + } else { + vis.visit_expr(&mut f.expr); + } + vec![f] + } + + fn flat_map_stmt(stmt: Stmt, vis: &mut T) -> Vec { + let kind = match stmt.kind { + // Don't wrap toplevel expressions in statements. + StmtKind::Expr(mut e) => { + noop_visit_expr(&mut e, vis); + StmtKind::Expr(e) + } + StmtKind::Semi(mut e) => { + noop_visit_expr(&mut e, vis); + StmtKind::Semi(e) + } + s => s, + }; + + vec![Stmt { kind, ..stmt }] + } + + fn noop_visit_expr(e: &mut Expr, vis: &mut T) { + use syntax::mut_visit::{noop_visit_expr, visit_opt, visit_thin_attrs}; + match &mut e.kind { + ExprKind::Struct(path, fields, expr) => { + vis.visit_path(path); + fields.flat_map_in_place(|field| flat_map_field(field, vis)); + visit_opt(expr, |expr| vis.visit_expr(expr)); + vis.visit_id(&mut e.id); + vis.visit_span(&mut e.span); + visit_thin_attrs(&mut e.attrs, vis); + } + _ => noop_visit_expr(e, vis), + } + } + impl MutVisitor for BracketsVisitor { fn visit_expr(&mut self, e: &mut P) { noop_visit_expr(e, self); @@ -241,13 +280,10 @@ fn libsyntax_brackets(mut libsyntax_expr: P) -> Option> } } - fn flat_map_field(&mut self, mut f: Field) -> SmallVec<[Field; 1]> { - if f.is_shorthand { - noop_visit_expr(&mut f.expr, self); - } else { - self.visit_expr(&mut f.expr); - } - SmallVec::from([f]) + fn visit_block(&mut self, block: &mut P) { + self.visit_id(&mut block.id); + block.stmts.flat_map_in_place(|stmt| flat_map_stmt(stmt, self)); + self.visit_span(&mut block.span); } // We don't want to look at expressions that might appear in patterns or @@ -261,23 +297,6 @@ fn libsyntax_brackets(mut libsyntax_expr: P) -> Option> let _ = ty; } - fn flat_map_stmt(&mut self, stmt: Stmt) -> SmallVec<[Stmt; 1]> { - let kind = match stmt.kind { - // Don't wrap toplevel expressions in statements. - StmtKind::Expr(mut e) => { - noop_visit_expr(&mut e, self); - StmtKind::Expr(e) - } - StmtKind::Semi(mut e) => { - noop_visit_expr(&mut e, self); - StmtKind::Semi(e) - } - s => s, - }; - - smallvec![Stmt { kind, ..stmt }] - } - fn visit_mac(&mut self, mac: &mut Mac) { // By default when folding over macros, libsyntax panics. This is // because it's usually not what you want, you want to run after