Skip to content

Commit 7662294

Browse files
xFrednetcamsteffen
andcommitted
Use a macro to create declare_clippy_lint macro (DRY)
This was first suggested by `@camsteffen` in rust-lang#6830. Back then, it was decided to avoid this implementation to keep the macro simple. Now it makes sense to again use this macro, as the implementation of the macro will get a bit more complicated to support nightly lints. Credit where credit is due: Co-authored-by: camsteffen <[email protected]>
1 parent aff0966 commit 7662294

File tree

1 file changed

+31
-55
lines changed

1 file changed

+31
-55
lines changed

clippy_lints/src/lib.rs

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -97,65 +97,41 @@ use rustc_session::Session;
9797
/// }
9898
/// ```
9999
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
100-
#[macro_export]
101-
macro_rules! declare_clippy_lint {
102-
{ $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
103-
declare_tool_lint! {
104-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
105-
}
106-
};
107-
{ $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
108-
declare_tool_lint! {
109-
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
110-
}
111-
};
112-
{ $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
113-
declare_tool_lint! {
114-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
115-
}
116-
};
117-
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
118-
declare_tool_lint! {
119-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
120-
}
121-
};
122-
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
123-
declare_tool_lint! {
124-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
125-
}
126-
};
127-
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
128-
declare_tool_lint! {
129-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
130-
}
131-
};
132-
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
133-
declare_tool_lint! {
134-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
135-
}
136-
};
137-
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
138-
declare_tool_lint! {
139-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
140-
}
141-
};
142-
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
143-
declare_tool_lint! {
144-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
145-
}
146-
};
147-
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
148-
declare_tool_lint! {
149-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
150-
}
151-
};
152-
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
153-
declare_tool_lint! {
154-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
100+
macro_rules! declare_clippy_lint_macro {
101+
({ $($category:tt: $level:tt,)* }, $d:tt) => {
102+
macro_rules! declare_clippy_lint {
103+
$(
104+
($d(#[$d meta:meta])* pub $d name:tt, $category, $d description:tt) => {
105+
declare_tool_lint! {
106+
$d(#[$d meta])*
107+
pub clippy::$d name,
108+
$level,
109+
$d description,
110+
report_in_external_macro: true
111+
}
112+
};
113+
)*
155114
}
156115
};
157116
}
158117

118+
declare_clippy_lint_macro! {
119+
{
120+
correctness: Deny,
121+
complexity: Warn,
122+
internal_warn: Warn,
123+
perf: Warn,
124+
suspicious: Warn,
125+
style: Warn,
126+
cargo: Allow,
127+
internal: Allow,
128+
nursery: Allow,
129+
pedantic: Allow,
130+
restriction: Allow,
131+
},
132+
$
133+
}
134+
159135
#[cfg(feature = "internal")]
160136
mod deprecated_lints;
161137
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]

0 commit comments

Comments
 (0)