Fix tooling

Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
This commit is contained in:
Jonathan Brouwer 2025-07-07 22:28:37 +02:00
parent e64f75b3d2
commit 97b65215ff
No known key found for this signature in database
GPG key ID: F13E55D38C971DEF
2 changed files with 21 additions and 34 deletions

View file

@ -36,6 +36,7 @@ use std::mem;
use rustc_ast::token::{Token, TokenKind};
use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_attr_data_structures::{AttributeKind, find_attr};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, IndexEntry};
use rustc_errors::codes::*;
use rustc_errors::{FatalError, struct_span_code_err};
@ -987,28 +988,17 @@ fn clean_proc_macro<'tcx>(
kind: MacroKind,
cx: &mut DocContext<'tcx>,
) -> ItemKind {
if kind != MacroKind::Derive {
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
}
let attrs = cx.tcx.hir_attrs(item.hir_id());
if kind == MacroKind::Derive
&& let Some(derive_name) =
hir_attr_lists(attrs, sym::proc_macro_derive).find_map(|mi| mi.ident())
{
*name = derive_name.name;
}
let Some((trait_name, helper_attrs)) = find_attr!(attrs, AttributeKind::ProcMacroDerive { trait_name, helper_attrs, ..} => (*trait_name, helper_attrs))
else {
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
};
*name = trait_name;
let helpers = helper_attrs.iter().copied().collect();
let mut helpers = Vec::new();
for mi in hir_attr_lists(attrs, sym::proc_macro_derive) {
if !mi.has_name(sym::attributes) {
continue;
}
if let Some(list) = mi.meta_item_list() {
for inner_mi in list {
if let Some(ident) = inner_mi.ident() {
helpers.push(ident.name);
}
}
}
}
ProcMacroItem(ProcMacro { kind, helpers })
}
@ -1021,17 +1011,16 @@ fn clean_fn_or_proc_macro<'tcx>(
cx: &mut DocContext<'tcx>,
) -> ItemKind {
let attrs = cx.tcx.hir_attrs(item.hir_id());
let macro_kind = attrs.iter().find_map(|a| {
if a.has_name(sym::proc_macro) {
Some(MacroKind::Bang)
} else if a.has_name(sym::proc_macro_derive) {
Some(MacroKind::Derive)
} else if a.has_name(sym::proc_macro_attribute) {
Some(MacroKind::Attr)
} else {
None
}
});
let macro_kind = if find_attr!(attrs, AttributeKind::ProcMacro(..)) {
Some(MacroKind::Bang)
} else if find_attr!(attrs, AttributeKind::ProcMacroDerive { .. }) {
Some(MacroKind::Derive)
} else if find_attr!(attrs, AttributeKind::ProcMacroAttribute(..)) {
Some(MacroKind::Attr)
} else {
None
};
match macro_kind {
Some(kind) => clean_proc_macro(item, name, kind, cx),
None => {

View file

@ -312,9 +312,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
/// Functions marked with these attributes must have the exact signature.
pub(crate) fn requires_exact_signature(attrs: &[Attribute]) -> bool {
attrs.iter().any(|attr| {
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
.iter()
.any(|&allow| attr.has_name(allow))
attr.is_proc_macro_attr()
})
}