Address the other cases of #22234; fix #22234.

The other cases: `concat_idents!`, `log_syntax!`, and `trace_macros!`,
(these macros, with `asm!`, are handled (eagerly) in feature_gate.rs).
This commit is contained in:
Felix S. Klock II
2015-02-15 23:49:55 +01:00
parent 52bdda778a
commit dc0797c0c9
11 changed files with 199 additions and 6 deletions

View File

@@ -12,12 +12,21 @@ use ast;
use codemap::Span;
use ext::base::*;
use ext::base;
use feature_gate;
use parse::token;
use parse::token::{str_to_ident};
use ptr::P;
pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'cx> {
if !cx.ecfg.enable_concat_idents() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,
"concat_idents",
sp,
feature_gate::EXPLAIN_CONCAT_IDENTS);
return base::DummyResult::expr(sp);
}
let mut res_str = String::new();
for (i, e) in tts.iter().enumerate() {
if i & 1 == 1 {

View File

@@ -1436,6 +1436,27 @@ impl<'feat> ExpansionConfig<'feat> {
_ => 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<'feat>(parse_sess: &parse::ParseSess,

View File

@@ -11,12 +11,20 @@
use ast;
use codemap;
use ext::base;
use feature_gate;
use print;
pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt,
sp: codemap::Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+'cx> {
if !cx.ecfg.enable_log_syntax() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,
"log_syntax",
sp,
feature_gate::EXPLAIN_LOG_SYNTAX);
return base::DummyResult::any(sp);
}
cx.print_backtrace();

View File

@@ -12,6 +12,7 @@ use ast;
use codemap::Span;
use ext::base::ExtCtxt;
use ext::base;
use feature_gate;
use parse::token::keywords;
@@ -19,6 +20,15 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
sp: Span,
tt: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
if !cx.ecfg.enable_trace_macros() {
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,
"trace_macros",
sp,
feature_gate::EXPLAIN_TRACE_MACROS);
return base::DummyResult::any(sp);
}
match tt {
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => {
cx.set_trace_macros(true);