Skip to content

Commit 035b698

Browse files
committed
Do not future-proof check imported macros.
1 parent ab3836d commit 035b698

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,12 @@ impl<'a> ExtCtxt<'a> {
715715
}
716716
}
717717

718-
pub fn insert_macro(&mut self, def: ast::MacroDef) {
718+
pub fn insert_macro(&mut self, def: ast::MacroDef, imported: bool) {
719719
if def.export {
720720
self.exported_macros.push(def.clone());
721721
}
722722
if def.use_locally {
723-
let ext = macro_rules::compile(self, &def);
723+
let ext = macro_rules::compile(self, &def, imported);
724724
self.syntax_env.insert(def.ident.name, ext);
725725
}
726726
}

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
290290
export: attr::contains_name(&attrs, "macro_export"),
291291
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
292292
attrs: attrs,
293-
});
293+
}, false);
294294

295295
// macro_rules! has a side effect but expands to nothing.
296296
fld.cx.bt_pop();
@@ -911,7 +911,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
911911
// We need to error on `#[macro_use] extern crate` when it isn't at the
912912
// crate root, because `$crate` won't work properly.
913913
for def in self.cx.loader.load_crate(item, self.at_crate_root) {
914-
self.cx.insert_macro(def);
914+
self.cx.insert_macro(def, true);
915915
}
916916
} else {
917917
let at_crate_root = ::std::mem::replace(&mut self.at_crate_root, false);

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
249249

250250
/// Converts a `macro_rules!` invocation into a syntax extension.
251251
pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
252-
def: &ast::MacroDef) -> SyntaxExtension {
252+
def: &ast::MacroDef,
253+
imported: bool) -> SyntaxExtension {
253254

254255
let lhs_nm = gensym_ident("lhs");
255256
let rhs_nm = gensym_ident("rhs");
@@ -305,7 +306,9 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
305306
MatchedSeq(ref s, _) => {
306307
s.iter().map(|m| match **m {
307308
MatchedNonterminal(NtTT(ref tt)) => {
308-
valid &= check_lhs_nt_follows(cx, tt);
309+
if !imported {
310+
valid &= check_lhs_nt_follows(cx, tt);
311+
}
309312
(**tt).clone()
310313
}
311314
_ => cx.span_bug(def.span, "wrong-structured lhs")
@@ -314,16 +317,18 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
314317
_ => cx.span_bug(def.span, "wrong-structured lhs")
315318
};
316319

317-
'a: for (i, lhs) in lhses.iter().enumerate() {
318-
for lhs_ in lhses[i + 1 ..].iter() {
319-
if !check_lhs_firsts(cx, lhs, lhs_) {
320-
cx.struct_span_warn(def.span, "macro is not future-proof")
321-
.span_help(lhs.get_span(), "parsing of this arm is ambiguous...")
322-
.span_help(lhs_.get_span(), "with the parsing of this arm.")
323-
.help("the behaviour of this macro might change in the future")
324-
.emit();
325-
//valid = false;
326-
break 'a;
320+
if !imported {
321+
'a: for (i, lhs) in lhses.iter().enumerate() {
322+
for lhs_ in lhses[i + 1 ..].iter() {
323+
if !check_lhs_firsts(cx, lhs, lhs_) {
324+
cx.struct_span_warn(def.span, "macro is not future-proof")
325+
.span_help(lhs.get_span(), "parsing of this arm is ambiguous...")
326+
.span_help(lhs_.get_span(), "with the parsing of this arm.")
327+
.help("the behaviour of this macro might change in the future")
328+
.emit();
329+
//valid = false;
330+
break 'a;
331+
}
327332
}
328333
}
329334
}

0 commit comments

Comments
 (0)