Skip to content

Commit 97b6521

Browse files
Fix tooling
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent e64f75b commit 97b6521

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::mem;
3636

3737
use rustc_ast::token::{Token, TokenKind};
3838
use rustc_ast::tokenstream::{TokenStream, TokenTree};
39+
use rustc_attr_data_structures::{AttributeKind, find_attr};
3940
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, IndexEntry};
4041
use rustc_errors::codes::*;
4142
use rustc_errors::{FatalError, struct_span_code_err};
@@ -987,28 +988,17 @@ fn clean_proc_macro<'tcx>(
987988
kind: MacroKind,
988989
cx: &mut DocContext<'tcx>,
989990
) -> ItemKind {
990-
let attrs = cx.tcx.hir_attrs(item.hir_id());
991-
if kind == MacroKind::Derive
992-
&& let Some(derive_name) =
993-
hir_attr_lists(attrs, sym::proc_macro_derive).find_map(|mi| mi.ident())
994-
{
995-
*name = derive_name.name;
991+
if kind != MacroKind::Derive {
992+
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
996993
}
994+
let attrs = cx.tcx.hir_attrs(item.hir_id());
995+
let Some((trait_name, helper_attrs)) = find_attr!(attrs, AttributeKind::ProcMacroDerive { trait_name, helper_attrs, ..} => (*trait_name, helper_attrs))
996+
else {
997+
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
998+
};
999+
*name = trait_name;
1000+
let helpers = helper_attrs.iter().copied().collect();
9971001

998-
let mut helpers = Vec::new();
999-
for mi in hir_attr_lists(attrs, sym::proc_macro_derive) {
1000-
if !mi.has_name(sym::attributes) {
1001-
continue;
1002-
}
1003-
1004-
if let Some(list) = mi.meta_item_list() {
1005-
for inner_mi in list {
1006-
if let Some(ident) = inner_mi.ident() {
1007-
helpers.push(ident.name);
1008-
}
1009-
}
1010-
}
1011-
}
10121002
ProcMacroItem(ProcMacro { kind, helpers })
10131003
}
10141004

@@ -1021,17 +1011,16 @@ fn clean_fn_or_proc_macro<'tcx>(
10211011
cx: &mut DocContext<'tcx>,
10221012
) -> ItemKind {
10231013
let attrs = cx.tcx.hir_attrs(item.hir_id());
1024-
let macro_kind = attrs.iter().find_map(|a| {
1025-
if a.has_name(sym::proc_macro) {
1026-
Some(MacroKind::Bang)
1027-
} else if a.has_name(sym::proc_macro_derive) {
1028-
Some(MacroKind::Derive)
1029-
} else if a.has_name(sym::proc_macro_attribute) {
1030-
Some(MacroKind::Attr)
1031-
} else {
1032-
None
1033-
}
1034-
});
1014+
let macro_kind = if find_attr!(attrs, AttributeKind::ProcMacro(..)) {
1015+
Some(MacroKind::Bang)
1016+
} else if find_attr!(attrs, AttributeKind::ProcMacroDerive { .. }) {
1017+
Some(MacroKind::Derive)
1018+
} else if find_attr!(attrs, AttributeKind::ProcMacroAttribute(..)) {
1019+
Some(MacroKind::Attr)
1020+
} else {
1021+
None
1022+
};
1023+
10351024
match macro_kind {
10361025
Some(kind) => clean_proc_macro(item, name, kind, cx),
10371026
None => {

src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
312312
/// Functions marked with these attributes must have the exact signature.
313313
pub(crate) fn requires_exact_signature(attrs: &[Attribute]) -> bool {
314314
attrs.iter().any(|attr| {
315-
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
316-
.iter()
317-
.any(|&allow| attr.has_name(allow))
315+
attr.is_proc_macro_attr()
318316
})
319317
}
320318

0 commit comments

Comments
 (0)