diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2025-07-04 01:22:37 -0700 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2025-07-05 16:23:13 -0700 |
| commit | 63cfb3af37d74d312829d4e260e03128eb7e3f27 (patch) | |
| tree | 27a7b1f6e95eac594af63fb1bc230fd6008ebd11 /compiler/rustc_expand/src/base.rs | |
| parent | 0d5ab3e46ce3be1e5e3c45ac0ff7d355303c4353 (diff) | |
| download | rust-63cfb3af37d74d312829d4e260e03128eb7e3f27.tar.gz rust-63cfb3af37d74d312829d4e260e03128eb7e3f27.zip | |
mbe: Defer checks for `compile_error!` until reporting an unused macro rule
The MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This ends up being a net simplification, and reduction in code size.
Diffstat (limited to 'compiler/rustc_expand/src/base.rs')
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 80f6e9d9fc4..d6d89808839 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -348,6 +348,10 @@ pub trait TTMacroExpander { span: Span, input: TokenStream, ) -> MacroExpanderResult<'cx>; + + fn get_unused_rule(&self, _rule_i: usize) -> Option<(&Ident, Span)> { + None + } } pub type MacroExpanderResult<'cx> = ExpandResult<Box<dyn MacResult + 'cx>, ()>; |
