diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-17 15:54:25 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-17 17:33:20 +0530 |
| commit | 020e4e4ad981ce0518bd8e3464ac592717c41143 (patch) | |
| tree | feca45da907af4dedc7aa930a8292a5fdf78073a /src/libsyntax/ext/expand.rs | |
| parent | 0e892283612ea21ce5aeb3be930296623facab36 (diff) | |
| parent | dc0797c0c99e7079170d0e09f82fc6f66b721932 (diff) | |
| download | rust-020e4e4ad981ce0518bd8e3464ac592717c41143.tar.gz rust-020e4e4ad981ce0518bd8e3464ac592717c41143.zip | |
Rollup merge of #22383 - pnkfelix:pass-features-along-during-expansion, r=huonw
Pass features along during expansion Use the set of passed features to detect uses of feature-gated macros without the corresponding feature enabled. Fix #22234. ---- Also, the framework this add (passing along a reference to the features in the expansion context) is a necessary precursor for landing a properly feature-gated desugaring-based overloaded-`box` and placement-`in` (#22181). ---- This is fixing a bug, but since there might be code out there that is unknowingly taking advantage of that bug, I feel obligated to mark this as a: [breaking-change]
Diffstat (limited to 'src/libsyntax/ext/expand.rs')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index fd98f42c2ab..6b7cecee815 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -22,6 +22,7 @@ use attr::AttrMetaMethods; use codemap; use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use ext::base::*; +use feature_gate::{Features}; use fold; use fold::*; use parse; @@ -1408,28 +1409,63 @@ fn new_span(cx: &ExtCtxt, sp: Span) -> Span { } } -pub struct ExpansionConfig { +pub struct ExpansionConfig<'feat> { pub crate_name: String, - pub enable_quotes: bool, + pub features: Option<&'feat Features>, pub recursion_limit: usize, } -impl ExpansionConfig { - pub fn default(crate_name: String) -> ExpansionConfig { +impl<'feat> ExpansionConfig<'feat> { + pub fn default(crate_name: String) -> ExpansionConfig<'static> { ExpansionConfig { crate_name: crate_name, - enable_quotes: false, + features: None, recursion_limit: 64, } } + + pub fn enable_quotes(&self) -> bool { + match self.features { + Some(&Features { allow_quote: true, .. }) => true, + _ => false, + } + } + + pub fn enable_asm(&self) -> bool { + match self.features { + Some(&Features { allow_asm: true, .. }) => true, + _ => false, + } + } + + pub fn enable_log_syntax(&self) -> bool { + match self.features { + Some(&Features { allow_log_syntax: true, .. }) => true, + _ => false, + } + } + + pub fn enable_concat_idents(&self) -> bool { + match self.features { + Some(&Features { allow_concat_idents: true, .. }) => true, + _ => false, + } + } + + pub fn enable_trace_macros(&self) -> bool { + match self.features { + Some(&Features { allow_trace_macros: true, .. }) => true, + _ => false, + } + } } -pub fn expand_crate(parse_sess: &parse::ParseSess, - cfg: ExpansionConfig, - // these are the macros being imported to this crate: - imported_macros: Vec<ast::MacroDef>, - user_exts: Vec<NamedSyntaxExtension>, - c: Crate) -> Crate { +pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, + cfg: ExpansionConfig<'feat>, + // these are the macros being imported to this crate: + imported_macros: Vec<ast::MacroDef>, + user_exts: Vec<NamedSyntaxExtension>, + c: Crate) -> Crate { let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); cx.use_std = std_inject::use_std(&c); @@ -1598,7 +1634,7 @@ mod test { // these following tests are quite fragile, in that they don't test what // *kind* of failure occurs. - fn test_ecfg() -> ExpansionConfig { + fn test_ecfg() -> ExpansionConfig<'static> { ExpansionConfig::default("test".to_string()) } |
