From 22eb3193a62fa01e97bf53d5f5aa74ca8ea57a67 Mon Sep 17 00:00:00 2001 From: Christopher Chambers Date: Fri, 10 Apr 2015 23:06:34 -0500 Subject: [PATCH] Simplifications to statement macro handling. SmallVector::pop no longer worries about converting a Many repr downward to One or Zero. expand_stmt makes use of `if let` for style purposes. --- src/libsyntax/ext/expand.rs | 25 +++++++++++-------------- src/libsyntax/util/small_vector.rs | 24 +----------------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4a6c45b5be581..8e6b5f85440b9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -772,20 +772,17 @@ fn expand_stmt(stmt: P, fld: &mut MacroExpander) -> SmallVector> { // If this is a macro invocation with a semicolon, then apply that // semicolon to the final statement produced by expansion. if style == MacStmtWithSemicolon { - match fully_expanded.pop() { - Some(stmt) => { - let new_stmt = stmt.map(|Spanned {node, span}| { - Spanned { - node: match node { - StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id), - _ => node /* might already have a semi */ - }, - span: span - } - }); - fully_expanded.push(new_stmt); - } - None => (), + if let Some(stmt) = fully_expanded.pop() { + let new_stmt = stmt.map(|Spanned {node, span}| { + Spanned { + node: match node { + StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id), + _ => node /* might already have a semi */ + }, + span: span + } + }); + fully_expanded.push(new_stmt); } } diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index c4b096d656f1b..6b864d5294766 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -79,29 +79,7 @@ impl SmallVector { _ => unreachable!() } } - Many(..) => { - let mut many = mem::replace(&mut self.repr, Zero); - let item = - match many { - Many(ref mut vs) if vs.len() == 1 => { - // self.repr is already Zero - vs.pop() - }, - Many(ref mut vs) if vs.len() == 2 => { - let item = vs.pop(); - mem::replace(&mut self.repr, One(vs.pop().unwrap())); - item - }, - Many(ref mut vs) if vs.len() > 2 => { - let item = vs.pop(); - let rest = mem::replace(vs, vec!()); - mem::replace(&mut self.repr, Many(rest)); - item - }, - _ => unreachable!() - }; - item - } + Many(ref mut vs) => vs.pop(), } }