Skip to content

Commit cf42ac6

Browse files
Rollup merge of rust-lang#145153 - joshtriplett:macro-kinds-plural, r=petrochenkov
Handle macros with multiple kinds, and improve errors (I recommend reviewing this commit-by-commit.) Switch to a bitflags `MacroKinds` to support macros with more than one kind Review everything that uses `MacroKind`, and switch anything that could refer to more than one kind to use `MacroKinds`. Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros, using the concrete `MacroRulesMacroExpander` type, and have it track which kinds it can handle. Eliminate the separate optional `attr_ext`, now that a `SyntaxExtension` can handle multiple macro kinds. This also avoids the need to downcast when calling methods on `MacroRulesMacroExpander`, such as `get_unused_rule`. Integrate macro kind checking into name resolution's `sub_namespace_match`, so that we only find a macro if it's the right type, and eliminate the special-case hack for attributes. This allows detecting and report macro kind mismatches early, and more precisely, improving various error messages. In particular, this eliminates the case in `failed_to_match_macro` to check for a function-like invocation of a macro with no function-like rules. Instead, macro kind mismatches now result in an unresolved macro, and we detect this case in `unresolved_macro_suggestions`, which now carefully distinguishes between a kind mismatch and other errors. This also handles cases of forward-referenced attributes and cyclic attributes. ---- In this PR, I've minimally fixed up `rustdoc` so that it compiles and passes tests. This is just the minimal necessary fixes to handle the switch to `MacroKinds`, and it only works for macros that don't actually have multiple kinds. This will panic (with a `todo!`) if it encounters a macro with multiple kinds. rustdoc needs further fixes to handle macros with multiple kinds, and to handle attributes and derive macros that aren't proc macros. I'd appreciate some help from a rustdoc expert on that. ---- r? ````````@petrochenkov````````
2 parents d42a48d + e7e18a3 commit cf42ac6

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

clippy_lints/src/item_name_repetitions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_data_structures::fx::FxHashSet;
88
use rustc_hir::{EnumDef, FieldDef, Item, ItemKind, OwnerId, QPath, TyKind, Variant, VariantData};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_session::impl_lint_pass;
11-
use rustc_span::MacroKind;
1211
use rustc_span::symbol::Symbol;
1312

1413
declare_clippy_lint! {
@@ -503,8 +502,8 @@ impl LateLintPass<'_> for ItemNameRepetitions {
503502
);
504503
}
505504

506-
let is_macro_rule = matches!(item.kind, ItemKind::Macro(_, _, MacroKind::Bang));
507-
if both_are_public && item_camel.len() > mod_camel.len() && !is_macro_rule {
505+
let is_macro = matches!(item.kind, ItemKind::Macro(_, _, _));
506+
if both_are_public && item_camel.len() > mod_camel.len() && !is_macro {
508507
let matching = count_match_start(mod_camel, &item_camel);
509508
let rmatching = count_match_end(mod_camel, &item_camel);
510509
let nchars = mod_camel.chars().count();

clippy_lints/src/redundant_pub_crate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty;
88
use rustc_session::impl_lint_pass;
99
use rustc_span::def_id::CRATE_DEF_ID;
10-
use rustc_span::hygiene::MacroKind;
1110

1211
declare_clippy_lint! {
1312
/// ### What it does
@@ -89,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
8988
// We ignore macro exports. And `ListStem` uses, which aren't interesting.
9089
fn is_ignorable_export<'tcx>(item: &'tcx Item<'tcx>) -> bool {
9190
if let ItemKind::Use(path, kind) = item.kind {
92-
let ignore = matches!(path.res.macro_ns, Some(Res::Def(DefKind::Macro(MacroKind::Bang), _)))
91+
let ignore = matches!(path.res.macro_ns, Some(Res::Def(DefKind::Macro(_), _)))
9392
|| kind == UseKind::ListStem;
9493
if ignore {
9594
return true;

0 commit comments

Comments
 (0)