From 99ecdb3f5fc49efb3eccdd10fbe12dc98623a938 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 24 Jun 2018 19:54:23 +0300 Subject: hygiene: Implement transparent marks --- src/libsyntax/ext/base.rs | 8 ++++++++ src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 78fa3f326d6..e2424de4d14 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -649,6 +649,7 @@ pub enum SyntaxExtension { DeclMacro { expander: Box, def_info: Option<(ast::NodeId, Span)>, + is_transparent: bool, edition: Edition, } } @@ -682,6 +683,13 @@ impl SyntaxExtension { } } + pub fn is_transparent(&self) -> bool { + match *self { + SyntaxExtension::DeclMacro { is_transparent, .. } => is_transparent, + _ => false, + } + } + pub fn edition(&self) -> Edition { match *self { SyntaxExtension::NormalTT { edition, .. } | diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 38fa92f2c93..e364e145593 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -738,7 +738,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; let opt_expanded = match *ext { - DeclMacro { ref expander, def_info, edition } => { + DeclMacro { ref expander, def_info, edition, .. } => { if let Err(dummy_span) = validate_and_set_expn_info(self, def_info.map(|(_, s)| s), false, false, false, None, edition) { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 0c81a68e999..70fc9dada42 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -312,9 +312,12 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition: edition, } } else { + let is_transparent = attr::contains_name(&def.attrs, "rustc_transparent_macro"); + SyntaxExtension::DeclMacro { expander, def_info: Some((def.id, def.span)), + is_transparent, edition, } } -- cgit 1.4.1-3-g733a5