From c84562e019e3061c79879487ace098a652d19490 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 3 Aug 2018 02:30:03 +0300 Subject: Avoid modifying invocations in place for derive helper attributes --- src/libsyntax/ext/base.rs | 4 ++-- src/libsyntax/ext/expand.rs | 21 ++------------------- 2 files changed, 4 insertions(+), 21 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 8450daa3f7c..1bc5cb93c11 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -726,7 +726,7 @@ pub trait Resolver { fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec, allow_derive: bool) -> Option; - fn resolve_invoc(&mut self, invoc: &mut Invocation, scope: Mark, force: bool) + fn resolve_invoc(&mut self, invoc: &Invocation, scope: Mark, force: bool) -> Result>, Determinacy>; fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, force: bool) -> Result, Determinacy>; @@ -754,7 +754,7 @@ impl Resolver for DummyResolver { fn resolve_imports(&mut self) {} fn find_legacy_attr_invoc(&mut self, _attrs: &mut Vec, _allow_derive: bool) -> Option { None } - fn resolve_invoc(&mut self, _invoc: &mut Invocation, _scope: Mark, _force: bool) + fn resolve_invoc(&mut self, _invoc: &Invocation, _scope: Mark, _force: bool) -> Result>, Determinacy> { Err(Determinacy::Determined) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 8bd30e43476..7148f3c00f2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -252,13 +252,6 @@ impl Invocation { InvocationKind::Derive { ref path, .. } => path.span, } } - - pub fn attr_id(&self) -> Option { - match self.kind { - InvocationKind::Attr { attr: Some(ref attr), .. } => Some(attr.id), - _ => None, - } - } } pub struct MacroExpander<'a, 'b:'a> { @@ -338,7 +331,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let mut undetermined_invocations = Vec::new(); let (mut progress, mut force) = (false, !self.monotonic); loop { - let mut invoc = if let Some(invoc) = invocations.pop() { + let invoc = if let Some(invoc) = invocations.pop() { invoc } else { self.resolve_imports(); @@ -350,20 +343,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let scope = if self.monotonic { invoc.expansion_data.mark } else { orig_expansion_data.mark }; - let attr_id_before = invoc.attr_id(); - let ext = match self.cx.resolver.resolve_invoc(&mut invoc, scope, force) { + let ext = match self.cx.resolver.resolve_invoc(&invoc, scope, force) { Ok(ext) => Some(ext), Err(Determinacy::Determined) => None, Err(Determinacy::Undetermined) => { - // Sometimes attributes which we thought were invocations - // end up being custom attributes for custom derives. If - // that's the case our `invoc` will have changed out from - // under us. If this is the case we're making progress so we - // want to flag it as such, and we test this by looking if - // the `attr_id()` method has been changing over time. - if invoc.attr_id() != attr_id_before { - progress = true; - } undetermined_invocations.push(invoc); continue } -- cgit 1.4.1-3-g733a5