Convenience matcher in find_attrs for crate attrs

This commit is contained in:
Jana Dönszelmann
2026-02-05 13:12:09 +01:00
parent 63edc913fa
commit 07f46cec49
+7
View File
@@ -32,6 +32,13 @@
/// A common way to get those is through `tcx.get_all_attrs(did)`
#[macro_export]
macro_rules! find_attr {
($tcx: expr, crate, $pattern: pat $(if $guard: expr)?) => {
$crate::find_attr!($tcx, crate, $pattern $(if $guard)? => ()).is_some()
};
($tcx: expr, crate, $pattern: pat $(if $guard: expr)? => $e: expr) => {
$crate::find_attr!($tcx.hir_krate_attrs(), $pattern $(if $guard)? => $e)
};
($tcx: expr, $def_id: expr, $pattern: pat $(if $guard: expr)?) => {
$crate::find_attr!($tcx, $def_id, $pattern $(if $guard)? => ()).is_some()
};