diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-27 06:27:35 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-09-05 04:53:21 +0000 |
| commit | 3cba93f9933fe96fb77d625a480eb4cdddeed91f (patch) | |
| tree | 5d135d75bb89d2cb102ec3bfa5b42b1efe2c46b8 /src/libsyntax | |
| parent | de2e67836e23405e5bdc27cefa510fa562c5298f (diff) | |
| download | rust-3cba93f9933fe96fb77d625a480eb4cdddeed91f.tar.gz rust-3cba93f9933fe96fb77d625a480eb4cdddeed91f.zip | |
Refactor `with_exts_frame` from a macro to a function.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 485bd3ce10b..481278eb257 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -270,18 +270,6 @@ fn expand_mac_invoc(invoc: Invocation, fld: &mut MacroExpander) -> Expansion { fully_expanded } -// eval $e with a new exts frame. -// must be a macro so that $e isn't evaluated too early. -macro_rules! with_exts_frame { - ($extsboxexpr:expr,$macros_escape:expr,$e:expr) => - ({$extsboxexpr.push_frame(); - $extsboxexpr.info().macros_escape = $macros_escape; - let result = $e; - $extsboxexpr.pop_frame(); - result - }) -} - // When we enter a module, record it, for the sake of `module!` pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander) -> SmallVector<P<ast::Item>> { @@ -378,9 +366,7 @@ fn expand_multi_modified(a: Annotatable, fld: &mut MacroExpander) -> SmallVector fld.cx.mod_push(it.ident); } let macro_use = contains_macro_use(fld, &it.attrs); - let result = with_exts_frame!(fld.cx.syntax_env, - macro_use, - noop_fold_item(it, fld)); + let result = fld.with_exts_frame(macro_use, |fld| noop_fold_item(it, fld)); if valid_ident { fld.cx.mod_pop(); } @@ -561,6 +547,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let mark = Mark::fresh(); Invocation { span: span, attrs: attrs, mac: mac, mark: mark, kind: kind, ident: None } } + + fn with_exts_frame<T, F: FnOnce(&mut Self) -> T>(&mut self, macros_escape: bool, f: F) -> T { + self.cx.syntax_env.push_frame(); + self.cx.syntax_env.info().macros_escape = macros_escape; + let result = f(self); + self.cx.syntax_env.pop_frame(); + result + } } impl<'a, 'b> Folder for MacroExpander<'a, 'b> { @@ -624,7 +618,7 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> { fn fold_block(&mut self, block: P<Block>) -> P<Block> { let was_in_block = ::std::mem::replace(&mut self.cx.in_block, true); - let result = with_exts_frame!(self.cx.syntax_env, false, noop_fold_block(block, self)); + let result = self.with_exts_frame(false, |this| noop_fold_block(block, this)); self.cx.in_block = was_in_block; result } |
