diff options
| author | Steven Fackler <sfackler@gmail.com> | 2013-11-25 20:02:15 -0800 |
|---|---|---|
| committer | Steven Fackler <sfackler@palantir.com> | 2013-11-26 13:56:02 -0800 |
| commit | c403c1f18e987482a050299a647b0fbcdfea09ad (patch) | |
| tree | 122251a53e17ae499c2af9f4cf190197c2a075a1 /src/libsyntax/ext | |
| parent | c144752a2de4ffe3a2a22da9a8309ca2ecd85c58 (diff) | |
| download | rust-c403c1f18e987482a050299a647b0fbcdfea09ad.tar.gz rust-c403c1f18e987482a050299a647b0fbcdfea09ad.zip | |
Clean up SmallVector use a bit
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 3719362a7df..45f82d9b3a9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -678,7 +678,9 @@ pub fn expand_block_elts(exts: SyntaxEnv, b: &Block, fld: &MacroExpander) let rename_fld = renames_to_fold(pending_renames); let new_view_items = b.view_items.map(|x| fld.fold_view_item(x)); let new_stmts = b.stmts.iter() - .flat_map(|x| fld.fold_stmt(mustbeone(rename_fld.fold_stmt(*x))).move_iter()) + .map(|x| rename_fld.fold_stmt(*x) + .expect_one("rename_fold didn't return one value")) + .flat_map(|x| fld.fold_stmt(x).move_iter()) .collect(); let new_expr = b.expr.map(|x| fld.fold_expr(rename_fld.fold_expr(x))); Block{ @@ -691,14 +693,6 @@ pub fn expand_block_elts(exts: SyntaxEnv, b: &Block, fld: &MacroExpander) } } -// rename_fold should never return anything other than one thing -fn mustbeone<T>(mut val : SmallVector<T>) -> T { - if val.len() != 1 { - fail!("rename_fold didn't return one value"); - } - val.pop() -} - // get the (innermost) BlockInfo from an exts stack fn get_block_info(exts : SyntaxEnv) -> BlockInfo { match exts.find_in_topmost_frame(&intern(special_block_name)) { @@ -734,11 +728,8 @@ pub fn renames_to_fold(renames: @mut ~[(ast::Ident,ast::Name)]) -> @ast_fold { // perform a bunch of renames fn apply_pending_renames(folder : @ast_fold, stmt : ast::Stmt) -> @ast::Stmt { - let mut stmts = folder.fold_stmt(&stmt); - if stmts.len() != 1 { - fail!("renaming of stmt did not produce one stmt"); - } - stmts.pop() + folder.fold_stmt(&stmt) + .expect_one("renaming of stmt did not produce one stmt") } @@ -1185,11 +1176,8 @@ fn mark_expr(expr : @ast::Expr, m : Mrk) -> @ast::Expr { // apply a given mark to the given stmt. Used following the expansion of a macro. fn mark_stmt(expr : &ast::Stmt, m : Mrk) -> @ast::Stmt { - let mut stmts = new_mark_folder(m).fold_stmt(expr); - if stmts.len() != 1 { - fail!("marking a stmt didn't return a stmt"); - } - stmts.pop() + new_mark_folder(m).fold_stmt(expr) + .expect_one("marking a stmt didn't return a stmt") } // apply a given mark to the given item. Used following the expansion of a macro. |
