Avoid modifying invocations in place for derive helper attributes

This commit is contained in:
Vadim Petrochenkov
2018-08-03 02:30:03 +03:00
parent 467a7ab2b1
commit c84562e019
3 changed files with 28 additions and 59 deletions

View File

@@ -252,13 +252,6 @@ impl Invocation {
InvocationKind::Derive { ref path, .. } => path.span,
}
}
pub fn attr_id(&self) -> Option<ast::AttrId> {
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
}