diff options
| author | bors <bors@rust-lang.org> | 2016-09-22 19:54:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-22 19:54:56 -0700 |
| commit | 533c04dbb3e44ecb551b743993bd05e17b68236d (patch) | |
| tree | 0be7efba11643371f201155a524cfc5747fdc3de /src/libsyntax/ext | |
| parent | 3a5d975fdcef451375df20e5ac234bb01e453e33 (diff) | |
| parent | 173d5b339f5d17dd9a6e7796d307fe97e2fdde8a (diff) | |
| download | rust-533c04dbb3e44ecb551b743993bd05e17b68236d.tar.gz rust-533c04dbb3e44ecb551b743993bd05e17b68236d.zip | |
Auto merge of #36573 - jseyfried:groundwork, r=nrc
resolve: groundwork for building the module graph during expansion r? @nrc
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 17 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 91742680711..71a1b4ac3b1 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -667,7 +667,7 @@ pub trait Resolver { fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>); fn find_attr_invoc(&mut self, attrs: &mut Vec<Attribute>) -> Option<Attribute>; - fn resolve_invoc(&mut self, invoc: &Invocation) -> Option<Rc<SyntaxExtension>>; + fn resolve_invoc(&mut self, scope: Mark, invoc: &Invocation) -> Option<Rc<SyntaxExtension>>; } pub enum LoadedMacro { @@ -688,7 +688,9 @@ impl Resolver for DummyResolver { fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {} fn find_attr_invoc(&mut self, _attrs: &mut Vec<Attribute>) -> Option<Attribute> { None } - fn resolve_invoc(&mut self, _invoc: &Invocation) -> Option<Rc<SyntaxExtension>> { None } + fn resolve_invoc(&mut self, _scope: Mark, _invoc: &Invocation) -> Option<Rc<SyntaxExtension>> { + None + } } #[derive(Clone)] diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 18b32e9d0b6..a30109f0051 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -168,10 +168,6 @@ impl Invocation { InvocationKind::Attr { ref attr, .. } => attr.span, } } - - pub fn mark(&self) -> Mark { - self.expansion_data.mark - } } pub struct MacroExpander<'a, 'b:'a> { @@ -229,7 +225,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()), }; @@ -277,8 +275,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 } @@ -338,7 +339,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<SyntaxExtension>) -> 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!(), |
