diff options
| author | est31 <MTest31@outlook.com> | 2022-04-17 01:55:32 +0200 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2022-05-04 02:40:49 +0200 |
| commit | 3d43be3ad397b68d4fcf1c5d3d3f4eb3b75ca184 (patch) | |
| tree | 43d79e61706f973b05fd47ed0cc6f6a53006277a | |
| parent | e1b71feb592ba64805689e2b15b9fa570182c442 (diff) | |
| download | rust-3d43be3ad397b68d4fcf1c5d3d3f4eb3b75ca184.tar.gz rust-3d43be3ad397b68d4fcf1c5d3d3f4eb3b75ca184.zip | |
Add unused_macro_rules lint definition
Not fired yet.
| -rw-r--r-- | compiler/rustc_lint/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 18f229564c2..1886debde9b 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -303,6 +303,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { PATH_STATEMENTS, UNUSED_ATTRIBUTES, UNUSED_MACROS, + UNUSED_MACRO_RULES, UNUSED_ALLOCATION, UNUSED_DOC_COMMENTS, UNUSED_EXTERN_CRATES, diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index a42e3d5d957..d13e60e2ebc 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -749,6 +749,10 @@ declare_lint! { declare_lint! { /// The `unused_macros` lint detects macros that were not used. /// + /// Note that this lint is distinct from the `unused_macro_rules` lint, + /// which checks for single rules that never match of an otherwise used + /// macro, and thus never expand. + /// /// ### Example /// /// ```rust @@ -776,6 +780,45 @@ declare_lint! { } declare_lint! { + /// The `unused_macro_rules` lint detects macro rules that were not used. + /// + /// Note that the lint is distinct from the `unused_macros` lint, which + /// fires if the entire macro is never called, while this lint fires for + /// single unused rules of the macro that is otherwise used. + /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire. + /// + /// ### Example + /// + /// ```rust + /// macro_rules! unused_empty { + /// (hello) => { println!("Hello, world!") }; // This rule is unused + /// () => { println!("empty") }; // This rule is used + /// } + /// + /// fn main() { + /// unused_empty!(hello); + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Unused macro rules may signal a mistake or unfinished code. Furthermore, + /// they slow down compilation. Right now, silencing the warning is not + /// supported on a single rule level, so you have to add an allow to the + /// entire macro definition. + /// + /// If you intended to export the macro to make it + /// available outside of the crate, use the [`macro_export` attribute]. + /// + /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope + pub UNUSED_MACRO_RULES, + Warn, + "detects macro rules that were not used" +} + +declare_lint! { /// The `warnings` lint allows you to change the level of other /// lints which produce warnings. /// @@ -3138,6 +3181,7 @@ declare_lint_pass! { OVERLAPPING_RANGE_ENDPOINTS, BINDINGS_WITH_VARIANT_NAME, UNUSED_MACROS, + UNUSED_MACRO_RULES, WARNINGS, UNUSED_FEATURES, STABLE_FEATURES, |
