Skip to content

Commit d87bc44

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.
1 parent d06c474 commit d87bc44

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,20 @@ 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+
if !(sub_namespace_match(binding_macro_kind, macro_kind)
633+
|| (binding_macro_kind == Some(MacroKind::Bang)
634+
&& macro_kind == Some(MacroKind::Attr)
635+
&& this
636+
.get_macro(binding.res())
637+
.is_some_and(|macro_data| macro_data.attr_ext.is_some())))
638+
{
639+
return None;
640+
}
641+
631642
if finalize.is_none() || matches!(scope_set, ScopeSet::Late(..)) {
632643
return Some(Ok(binding));
633644
}
@@ -704,7 +715,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
704715
innermost_result = Some((binding, flags));
705716
}
706717
}
707-
Ok(..) | Err(Determinacy::Determined) => {}
718+
Err(Determinacy::Determined) => {}
708719
Err(Determinacy::Undetermined) => determinacy = Determinacy::Undetermined,
709720
}
710721

0 commit comments

Comments
 (0)