Skip to content

Commit 3cba93f

Browse files
committed
Refactor with_exts_frame from a macro to a function.
1 parent de2e678 commit 3cba93f

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,6 @@ fn expand_mac_invoc(invoc: Invocation, fld: &mut MacroExpander) -> Expansion {
270270
fully_expanded
271271
}
272272

273-
// eval $e with a new exts frame.
274-
// must be a macro so that $e isn't evaluated too early.
275-
macro_rules! with_exts_frame {
276-
($extsboxexpr:expr,$macros_escape:expr,$e:expr) =>
277-
({$extsboxexpr.push_frame();
278-
$extsboxexpr.info().macros_escape = $macros_escape;
279-
let result = $e;
280-
$extsboxexpr.pop_frame();
281-
result
282-
})
283-
}
284-
285273
// When we enter a module, record it, for the sake of `module!`
286274
pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
287275
-> SmallVector<P<ast::Item>> {
@@ -378,9 +366,7 @@ fn expand_multi_modified(a: Annotatable, fld: &mut MacroExpander) -> SmallVector
378366
fld.cx.mod_push(it.ident);
379367
}
380368
let macro_use = contains_macro_use(fld, &it.attrs);
381-
let result = with_exts_frame!(fld.cx.syntax_env,
382-
macro_use,
383-
noop_fold_item(it, fld));
369+
let result = fld.with_exts_frame(macro_use, |fld| noop_fold_item(it, fld));
384370
if valid_ident {
385371
fld.cx.mod_pop();
386372
}
@@ -561,6 +547,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
561547
let mark = Mark::fresh();
562548
Invocation { span: span, attrs: attrs, mac: mac, mark: mark, kind: kind, ident: None }
563549
}
550+
551+
fn with_exts_frame<T, F: FnOnce(&mut Self) -> T>(&mut self, macros_escape: bool, f: F) -> T {
552+
self.cx.syntax_env.push_frame();
553+
self.cx.syntax_env.info().macros_escape = macros_escape;
554+
let result = f(self);
555+
self.cx.syntax_env.pop_frame();
556+
result
557+
}
564558
}
565559

566560
impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
@@ -624,7 +618,7 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
624618

625619
fn fold_block(&mut self, block: P<Block>) -> P<Block> {
626620
let was_in_block = ::std::mem::replace(&mut self.cx.in_block, true);
627-
let result = with_exts_frame!(self.cx.syntax_env, false, noop_fold_block(block, self));
621+
let result = self.with_exts_frame(false, |this| noop_fold_block(block, this));
628622
self.cx.in_block = was_in_block;
629623
result
630624
}

0 commit comments

Comments
 (0)