@@ -749,6 +749,10 @@ declare_lint! {
749
749
declare_lint ! {
750
750
/// The `unused_macros` lint detects macros that were not used.
751
751
///
752
+ /// Note that this lint is distinct from the `unused_macro_rules` lint,
753
+ /// which checks for single rules that never match of an otherwise used
754
+ /// macro, and thus never expand.
755
+ ///
752
756
/// ### Example
753
757
///
754
758
/// ```rust
@@ -775,6 +779,45 @@ declare_lint! {
775
779
"detects macros that were not used"
776
780
}
777
781
782
+ declare_lint ! {
783
+ /// The `unused_macro_rules` lint detects macro rules that were not used.
784
+ ///
785
+ /// Note that the lint is distinct from the `unused_macros` lint, which
786
+ /// fires if the entire macro is never called, while this lint fires for
787
+ /// single unused rules of the macro that is otherwise used.
788
+ /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
789
+ ///
790
+ /// ### Example
791
+ ///
792
+ /// ```rust
793
+ /// macro_rules! unused_empty {
794
+ /// (hello) => { println!("Hello, world!") }; // This rule is unused
795
+ /// () => { println!("empty") }; // This rule is used
796
+ /// }
797
+ ///
798
+ /// fn main() {
799
+ /// unused_empty!(hello);
800
+ /// }
801
+ /// ```
802
+ ///
803
+ /// {{produces}}
804
+ ///
805
+ /// ### Explanation
806
+ ///
807
+ /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
808
+ /// they slow down compilation. Right now, silencing the warning is not
809
+ /// supported on a single rule level, so you have to add an allow to the
810
+ /// entire macro definition.
811
+ ///
812
+ /// If you intended to export the macro to make it
813
+ /// available outside of the crate, use the [`macro_export` attribute].
814
+ ///
815
+ /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
816
+ pub UNUSED_MACRO_RULES ,
817
+ Warn ,
818
+ "detects macro rules that were not used"
819
+ }
820
+
778
821
declare_lint ! {
779
822
/// The `warnings` lint allows you to change the level of other
780
823
/// lints which produce warnings.
@@ -3138,6 +3181,7 @@ declare_lint_pass! {
3138
3181
OVERLAPPING_RANGE_ENDPOINTS ,
3139
3182
BINDINGS_WITH_VARIANT_NAME ,
3140
3183
UNUSED_MACROS ,
3184
+ UNUSED_MACRO_RULES ,
3141
3185
WARNINGS ,
3142
3186
UNUSED_FEATURES ,
3143
3187
STABLE_FEATURES ,
0 commit comments