Skip to content

Commit a6b7f55

Browse files
Fix tooling
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
1 parent d7105fe commit a6b7f55

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};
@@ -978,28 +979,17 @@ fn clean_proc_macro<'tcx>(
978979
kind: MacroKind,
979980
cx: &mut DocContext<'tcx>,
980981
) -> ItemKind {
981-
let attrs = cx.tcx.hir_attrs(item.hir_id());
982-
if kind == MacroKind::Derive
983-
&& let Some(derive_name) =
984-
hir_attr_lists(attrs, sym::proc_macro_derive).find_map(|mi| mi.ident())
985-
{
986-
*name = derive_name.name;
982+
if kind != MacroKind::Derive {
983+
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
987984
}
985+
let attrs = cx.tcx.hir_attrs(item.hir_id());
986+
let Some((trait_name, helper_attrs)) = find_attr!(attrs, AttributeKind::ProcMacroDerive { trait_name, helper_attrs, ..} => (*trait_name, helper_attrs))
987+
else {
988+
return ProcMacroItem(ProcMacro { kind, helpers: vec![] });
989+
};
990+
*name = trait_name;
991+
let helpers = helper_attrs.iter().copied().collect();
988992

989-
let mut helpers = Vec::new();
990-
for mi in hir_attr_lists(attrs, sym::proc_macro_derive) {
991-
if !mi.has_name(sym::attributes) {
992-
continue;
993-
}
994-
995-
if let Some(list) = mi.meta_item_list() {
996-
for inner_mi in list {
997-
if let Some(ident) = inner_mi.ident() {
998-
helpers.push(ident.name);
999-
}
1000-
}
1001-
}
1002-
}
1003993
ProcMacroItem(ProcMacro { kind, helpers })
1004994
}
1005995

@@ -1012,17 +1002,16 @@ fn clean_fn_or_proc_macro<'tcx>(
10121002
cx: &mut DocContext<'tcx>,
10131003
) -> ItemKind {
10141004
let attrs = cx.tcx.hir_attrs(item.hir_id());
1015-
let macro_kind = attrs.iter().find_map(|a| {
1016-
if a.has_name(sym::proc_macro) {
1017-
Some(MacroKind::Bang)
1018-
} else if a.has_name(sym::proc_macro_derive) {
1019-
Some(MacroKind::Derive)
1020-
} else if a.has_name(sym::proc_macro_attribute) {
1021-
Some(MacroKind::Attr)
1022-
} else {
1023-
None
1024-
}
1025-
});
1005+
let macro_kind = if find_attr!(attrs, AttributeKind::ProcMacro(..)) {
1006+
Some(MacroKind::Bang)
1007+
} else if find_attr!(attrs, AttributeKind::ProcMacroDerive { .. }) {
1008+
Some(MacroKind::Derive)
1009+
} else if find_attr!(attrs, AttributeKind::ProcMacroAttribute(..)) {
1010+
Some(MacroKind::Attr)
1011+
} else {
1012+
None
1013+
};
1014+
10261015
match macro_kind {
10271016
Some(kind) => clean_proc_macro(item, name, kind, cx),
10281017
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)