Skip to content

Commit 22eb319

Browse files
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.
1 parent fae29e4 commit 22eb319

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

Diff for: src/libsyntax/ext/expand.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -772,20 +772,17 @@ fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
772772
// If this is a macro invocation with a semicolon, then apply that
773773
// semicolon to the final statement produced by expansion.
774774
if style == MacStmtWithSemicolon {
775-
match fully_expanded.pop() {
776-
Some(stmt) => {
777-
let new_stmt = stmt.map(|Spanned {node, span}| {
778-
Spanned {
779-
node: match node {
780-
StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id),
781-
_ => node /* might already have a semi */
782-
},
783-
span: span
784-
}
785-
});
786-
fully_expanded.push(new_stmt);
787-
}
788-
None => (),
775+
if let Some(stmt) = fully_expanded.pop() {
776+
let new_stmt = stmt.map(|Spanned {node, span}| {
777+
Spanned {
778+
node: match node {
779+
StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id),
780+
_ => node /* might already have a semi */
781+
},
782+
span: span
783+
}
784+
});
785+
fully_expanded.push(new_stmt);
789786
}
790787
}
791788

Diff for: src/libsyntax/util/small_vector.rs

+1-23
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,7 @@ impl<T> SmallVector<T> {
7979
_ => unreachable!()
8080
}
8181
}
82-
Many(..) => {
83-
let mut many = mem::replace(&mut self.repr, Zero);
84-
let item =
85-
match many {
86-
Many(ref mut vs) if vs.len() == 1 => {
87-
// self.repr is already Zero
88-
vs.pop()
89-
},
90-
Many(ref mut vs) if vs.len() == 2 => {
91-
let item = vs.pop();
92-
mem::replace(&mut self.repr, One(vs.pop().unwrap()));
93-
item
94-
},
95-
Many(ref mut vs) if vs.len() > 2 => {
96-
let item = vs.pop();
97-
let rest = mem::replace(vs, vec!());
98-
mem::replace(&mut self.repr, Many(rest));
99-
item
100-
},
101-
_ => unreachable!()
102-
};
103-
item
104-
}
82+
Many(ref mut vs) => vs.pop(),
10583
}
10684
}
10785

0 commit comments

Comments
 (0)