mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
resolve: Do not rely on default transparency when detecting proc macro derives
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -1647,10 +1647,14 @@ fn hygienic_lexical_parent_with_compatibility_fallback(&mut self, module: Module
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,18 +119,6 @@ pub fn is_descendant_of(self, ancestor: ExpnId) -> bool {
|
||||
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)]
|
||||
|
||||
Reference in New Issue
Block a user