Skip to content

Commit 21ba816

Browse files
committed
Move fields single_step and keep_macs from MacroExpander to ExpansionConfig.
1 parent d1acabe commit 21ba816

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/librustc_driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,11 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
674674
}
675675
let features = sess.features.borrow();
676676
let cfg = syntax::ext::expand::ExpansionConfig {
677-
crate_name: crate_name.to_string(),
678677
features: Some(&features),
679678
recursion_limit: sess.recursion_limit.get(),
680679
trace_mac: sess.opts.debugging_opts.trace_macros,
681680
should_test: sess.opts.test,
681+
..syntax::ext::expand::ExpansionConfig::default(crate_name.to_string())
682682
};
683683
let mut ecx = ExtCtxt::new(&sess.parse_sess, krate.config.clone(), cfg, &mut resolver);
684684
let ret = syntax::ext::expand::expand_crate(&mut ecx, syntax_exts, krate);

src/libsyntax/ext/expand.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,12 @@ impl Invocation {
173173

174174
pub struct MacroExpander<'a, 'b:'a> {
175175
pub cx: &'a mut ExtCtxt<'b>,
176-
pub single_step: bool,
177-
pub keep_macs: bool,
178176
monotonic: bool, // c.f. `cx.monotonic_expander()`
179177
}
180178

181179
impl<'a, 'b> MacroExpander<'a, 'b> {
182180
pub fn new(cx: &'a mut ExtCtxt<'b>, monotonic: bool) -> Self {
183-
MacroExpander {
184-
cx: cx,
185-
monotonic: monotonic,
186-
single_step: false,
187-
keep_macs: false,
188-
}
181+
MacroExpander { cx: cx, monotonic: monotonic }
189182
}
190183

191184
fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
@@ -238,7 +231,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
238231
expansions.push(Vec::new());
239232
}
240233
expansions[depth].push((mark.as_u32(), expansion));
241-
if !self.single_step {
234+
if !self.cx.ecfg.single_step {
242235
invocations.extend(new_invocations.into_iter().rev());
243236
}
244237
}
@@ -417,7 +410,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
417410
self.cx.insert_macro(def.clone());
418411

419412
// If keep_macs is true, expands to a MacEager::items instead.
420-
if self.keep_macs {
413+
if self.cx.ecfg.keep_macs {
421414
Some(placeholders::reconstructed_macro_rules(&def, &path))
422415
} else {
423416
Some(placeholders::macro_scope_placeholder())
@@ -726,6 +719,8 @@ pub struct ExpansionConfig<'feat> {
726719
pub recursion_limit: usize,
727720
pub trace_mac: bool,
728721
pub should_test: bool, // If false, strip `#[test]` nodes
722+
pub single_step: bool,
723+
pub keep_macs: bool,
729724
}
730725

731726
macro_rules! feature_tests {
@@ -749,6 +744,8 @@ impl<'feat> ExpansionConfig<'feat> {
749744
recursion_limit: 64,
750745
trace_mac: false,
751746
should_test: false,
747+
single_step: false,
748+
keep_macs: false,
752749
}
753750
}
754751

0 commit comments

Comments
 (0)