Skip to content

Commit 2b42dae

Browse files
Fix tooling
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 19c205b commit 2b42dae

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};
@@ -986,28 +987,17 @@ fn clean_proc_macro<'tcx>(
986987
kind: MacroKind,
987988
cx: &mut DocContext<'tcx>,
988989
) -> ItemKind {
989-
let attrs = cx.tcx.hir_attrs(item.hir_id());
990-
if kind == MacroKind::Derive
991-
&& let Some(derive_name) =
992-
hir_attr_lists(attrs, sym::proc_macro_derive).find_map(|mi| mi.ident())
993-
{
994-
*name = derive_name.name;
990+
if kind != MacroKind::Derive {
991+
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
995992
}
993+
let attrs = cx.tcx.hir_attrs(item.hir_id());
994+
let Some((trait_name, helper_attrs)) = find_attr!(attrs, AttributeKind::ProcMacroDerive { trait_name, helper_attrs, ..} => (*trait_name, helper_attrs))
995+
else {
996+
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
997+
};
998+
*name = trait_name;
999+
let helpers = helper_attrs.iter().copied().collect();
9961000

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

@@ -1020,17 +1010,16 @@ fn clean_fn_or_proc_macro<'tcx>(
10201010
cx: &mut DocContext<'tcx>,
10211011
) -> ItemKind {
10221012
let attrs = cx.tcx.hir_attrs(item.hir_id());
1023-
let macro_kind = attrs.iter().find_map(|a| {
1024-
if a.has_name(sym::proc_macro) {
1025-
Some(MacroKind::Bang)
1026-
} else if a.has_name(sym::proc_macro_derive) {
1027-
Some(MacroKind::Derive)
1028-
} else if a.has_name(sym::proc_macro_attribute) {
1029-
Some(MacroKind::Attr)
1030-
} else {
1031-
None
1032-
}
1033-
});
1013+
let macro_kind = if find_attr!(attrs, AttributeKind::ProcMacro(..)) {
1014+
Some(MacroKind::Bang)
1015+
} else if find_attr!(attrs, AttributeKind::ProcMacroDerive { .. }) {
1016+
Some(MacroKind::Derive)
1017+
} else if find_attr!(attrs, AttributeKind::ProcMacroAttribute(..)) {
1018+
Some(MacroKind::Attr)
1019+
} else {
1020+
None
1021+
};
1022+
10341023
match macro_kind {
10351024
Some(kind) => clean_proc_macro(item, name, kind, cx),
10361025
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
@@ -308,9 +308,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
308308
/// Functions marked with these attributes must have the exact signature.
309309
pub(crate) fn requires_exact_signature(attrs: &[Attribute]) -> bool {
310310
attrs.iter().any(|attr| {
311-
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
312-
.iter()
313-
.any(|&allow| attr.has_name(allow))
311+
attr.is_proc_macro_attr()
314312
})
315313
}
316314

0 commit comments

Comments
 (0)