Skip to content

Commit 20d8222

Browse files
committed
libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes.
1 parent cf636c2 commit 20d8222

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/librustc_driver/driver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
469469
new_path.extend(env::split_paths(&_old_path));
470470
env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());
471471
}
472+
let features = sess.features.borrow();
472473
let cfg = syntax::ext::expand::ExpansionConfig {
473474
crate_name: crate_name.to_string(),
474-
enable_quotes: sess.features.borrow().quote,
475+
features: Some(&features),
475476
recursion_limit: sess.recursion_limit.get(),
476477
};
477478
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,

src/libsyntax/ext/base.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ impl BlockInfo {
439439

440440
/// The base map of methods for expanding syntax extension
441441
/// AST nodes into full ASTs
442-
fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
442+
fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
443+
-> SyntaxEnv {
443444
// utility function to simplify creating NormalTT syntax extensions
444445
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
445446
NormalTT(box f, None)
@@ -470,7 +471,7 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
470471
syntax_expanders.insert(intern("deriving"),
471472
Decorator(box ext::deriving::expand_deprecated_deriving));
472473

473-
if ecfg.enable_quotes {
474+
if ecfg.enable_quotes() {
474475
// Quasi-quoting expanders
475476
syntax_expanders.insert(intern("quote_tokens"),
476477
builtin_normal_expander(
@@ -541,7 +542,7 @@ pub struct ExtCtxt<'a> {
541542
pub parse_sess: &'a parse::ParseSess,
542543
pub cfg: ast::CrateConfig,
543544
pub backtrace: ExpnId,
544-
pub ecfg: expand::ExpansionConfig,
545+
pub ecfg: expand::ExpansionConfig<'a>,
545546
pub use_std: bool,
546547

547548
pub mod_path: Vec<ast::Ident> ,
@@ -554,7 +555,7 @@ pub struct ExtCtxt<'a> {
554555

555556
impl<'a> ExtCtxt<'a> {
556557
pub fn new(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig,
557-
ecfg: expand::ExpansionConfig) -> ExtCtxt<'a> {
558+
ecfg: expand::ExpansionConfig<'a>) -> ExtCtxt<'a> {
558559
let env = initial_syntax_expander_table(&ecfg);
559560
ExtCtxt {
560561
parse_sess: parse_sess,

src/libsyntax/ext/expand.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use attr::AttrMetaMethods;
2222
use codemap;
2323
use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
2424
use ext::base::*;
25+
use feature_gate::{Features};
2526
use fold;
2627
use fold::*;
2728
use parse;
@@ -1407,28 +1408,35 @@ fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
14071408
}
14081409
}
14091410

1410-
pub struct ExpansionConfig {
1411+
pub struct ExpansionConfig<'feat> {
14111412
pub crate_name: String,
1412-
pub enable_quotes: bool,
1413+
pub features: Option<&'feat Features>,
14131414
pub recursion_limit: usize,
14141415
}
14151416

1416-
impl ExpansionConfig {
1417-
pub fn default(crate_name: String) -> ExpansionConfig {
1417+
impl<'feat> ExpansionConfig<'feat> {
1418+
pub fn default(crate_name: String) -> ExpansionConfig<'static> {
14181419
ExpansionConfig {
14191420
crate_name: crate_name,
1420-
enable_quotes: false,
1421+
features: None,
14211422
recursion_limit: 64,
14221423
}
14231424
}
1425+
1426+
pub fn enable_quotes(&self) -> bool {
1427+
match self.features {
1428+
Some(&Features { quote: true, .. }) => true,
1429+
_ => false,
1430+
}
1431+
}
14241432
}
14251433

1426-
pub fn expand_crate(parse_sess: &parse::ParseSess,
1427-
cfg: ExpansionConfig,
1428-
// these are the macros being imported to this crate:
1429-
imported_macros: Vec<ast::MacroDef>,
1430-
user_exts: Vec<NamedSyntaxExtension>,
1431-
c: Crate) -> Crate {
1434+
pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
1435+
cfg: ExpansionConfig<'feat>,
1436+
// these are the macros being imported to this crate:
1437+
imported_macros: Vec<ast::MacroDef>,
1438+
user_exts: Vec<NamedSyntaxExtension>,
1439+
c: Crate) -> Crate {
14321440
let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg);
14331441
cx.use_std = std_inject::use_std(&c);
14341442

@@ -1597,7 +1605,7 @@ mod test {
15971605
// these following tests are quite fragile, in that they don't test what
15981606
// *kind* of failure occurs.
15991607

1600-
fn test_ecfg() -> ExpansionConfig {
1608+
fn test_ecfg() -> ExpansionConfig<'static> {
16011609
ExpansionConfig::default("test".to_string())
16021610
}
16031611

0 commit comments

Comments
 (0)