From 1ee64e44a9ecf2968b214cd9b90e1c96f40dcee8 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Mon, 19 Sep 2016 07:27:20 +0000 Subject: Use `Resolver::visit_expansion` only with monotonic expansions. --- src/libsyntax/ext/base.rs | 6 ++++-- src/libsyntax/ext/expand.rs | 17 +++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 9d0d74138cd..87337c6a269 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -470,7 +470,7 @@ pub trait Resolver { fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec); fn find_attr_invoc(&mut self, attrs: &mut Vec) -> Option; - fn resolve_invoc(&mut self, invoc: &Invocation) -> Option>; + fn resolve_invoc(&mut self, scope: Mark, invoc: &Invocation) -> Option>; } pub enum LoadedMacro { @@ -491,7 +491,9 @@ impl Resolver for DummyResolver { fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec) {} fn find_attr_invoc(&mut self, _attrs: &mut Vec) -> Option { None } - fn resolve_invoc(&mut self, _invoc: &Invocation) -> Option> { None } + fn resolve_invoc(&mut self, _scope: Mark, _invoc: &Invocation) -> Option> { + None + } } #[derive(Clone)] diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index db0183a8b3a..92c8292ae90 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -165,10 +165,6 @@ impl Invocation { InvocationKind::Attr { ref attr, .. } => attr.span, } } - - pub fn mark(&self) -> Mark { - self.expansion_data.mark - } } pub struct MacroExpander<'a, 'b:'a> { @@ -219,7 +215,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let ExpansionData { depth, mark, .. } = invoc.expansion_data; self.cx.current_expansion = invoc.expansion_data.clone(); - let expansion = match self.cx.resolver.resolve_invoc(&invoc) { + let scope = if self.monotonic { mark } else { orig_expansion_data.mark }; + self.cx.current_expansion.mark = scope; + let expansion = match self.cx.resolver.resolve_invoc(scope, &invoc) { Some(ext) => self.expand_invoc(invoc, ext), None => invoc.expansion_kind.dummy(invoc.span()), }; @@ -267,8 +265,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }; self.cx.cfg = crate_config; - let mark = self.cx.current_expansion.mark; - self.cx.resolver.visit_expansion(mark, &result.0); + if self.monotonic { + let mark = self.cx.current_expansion.mark; + self.cx.resolver.visit_expansion(mark, &result.0); + } + result } @@ -314,7 +315,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { /// Expand a macro invocation. Returns the result of expansion. fn expand_bang_invoc(&mut self, invoc: Invocation, ext: Rc) -> Expansion { - let (mark, kind) = (invoc.mark(), invoc.expansion_kind); + let (mark, kind) = (invoc.expansion_data.mark, invoc.expansion_kind); let (attrs, mac, ident, span) = match invoc.kind { InvocationKind::Bang { attrs, mac, ident, span } => (attrs, mac, ident, span), _ => unreachable!(), -- cgit 1.4.1-3-g733a5