resolve: Do not rely on default transparency when detecting proc macro derives

This commit is contained in:
Vadim Petrochenkov 2019-08-22 01:29:34 +03:00
parent 0fb01d219c
commit bf345dd6e3
3 changed files with 9 additions and 17 deletions

View file

@ -145,7 +145,7 @@ impl<'a> Resolver<'a> {
}
}
fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
if let Some(ext) = self.macro_map.get(&def_id) {
return Some(ext.clone());
}

View file

@ -1647,10 +1647,14 @@ impl<'a> Resolver<'a> {
if module.expansion != parent.expansion &&
module.expansion.is_descendant_of(parent.expansion) {
// The macro is a proc macro derive
if module.expansion.looks_like_proc_macro_derive() {
if parent.expansion.outer_expn_is_descendant_of(span.ctxt()) {
*poisoned = Some(node_id);
return module.parent;
if let Some(&def_id) = self.macro_defs.get(&module.expansion) {
if let Some(ext) = self.get_macro_by_def_id(def_id) {
if !ext.is_builtin && ext.macro_kind() == MacroKind::Derive {
if parent.expansion.outer_expn_is_descendant_of(span.ctxt()) {
*poisoned = Some(node_id);
return module.parent;
}
}
}
}
}

View file

@ -119,18 +119,6 @@ impl ExpnId {
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt)))
}
// Used for enabling some compatibility fallback in resolve.
#[inline]
pub fn looks_like_proc_macro_derive(self) -> bool {
HygieneData::with(|data| {
let expn_data = data.expn_data(self);
if let ExpnKind::Macro(MacroKind::Derive, _) = expn_data.kind {
return expn_data.default_transparency == Transparency::Opaque;
}
false
})
}
}
#[derive(Debug)]