Skip to content

Commit 549c2fe

Browse files
committed
mbe: Handle local macro_rules attr resolution
Teach the resolver to consider `macro_rules` macros when looking for a local attribute. When looking for an attribute and considering a `macro_rules` macro, load the macro in order to see if it has attribute rules. Include a FIXME about tracking multiple macro kinds for a Def instead.
1 parent 34be8ab commit 549c2fe

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
625625
};
626626

627627
match result {
628-
Ok((binding, flags))
629-
if sub_namespace_match(binding.macro_kind(), macro_kind) =>
630-
{
628+
Ok((binding, flags)) => {
629+
let binding_macro_kind = binding.macro_kind();
630+
// If we're looking for an attribute, that might be supported by a
631+
// `macro_rules!` macro.
632+
// FIXME: Replace this with tracking multiple macro kinds for one Def.
633+
if !(sub_namespace_match(binding_macro_kind, macro_kind)
634+
|| (binding_macro_kind == Some(MacroKind::Bang)
635+
&& macro_kind == Some(MacroKind::Attr)
636+
&& this
637+
.get_macro(binding.res())
638+
.is_some_and(|macro_data| macro_data.attr_ext.is_some())))
639+
{
640+
return None;
641+
}
642+
631643
if finalize.is_none() || matches!(scope_set, ScopeSet::Late(..)) {
632644
return Some(Ok(binding));
633645
}
@@ -704,7 +716,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
704716
innermost_result = Some((binding, flags));
705717
}
706718
}
707-
Ok(..) | Err(Determinacy::Determined) => {}
719+
Err(Determinacy::Determined) => {}
708720
Err(Determinacy::Undetermined) => determinacy = Determinacy::Undetermined,
709721
}
710722

0 commit comments

Comments
 (0)