1
Fork 0

Make declare_lint take any amount of boolean fields

This commit is contained in:
Mark Rousskov 2019-10-08 18:47:08 -04:00
parent aa4ee2cc0f
commit c1abc30660
4 changed files with 24 additions and 13 deletions

View file

@ -22,7 +22,7 @@ declare_lint! {
pub CONST_ERR,
Deny,
"constant evaluation detected erroneous expression",
report_in_external_macro: true
report_in_external_macro
}
declare_lint! {
@ -71,7 +71,7 @@ declare_lint! {
pub UNREACHABLE_CODE,
Warn,
"detects unreachable code paths",
report_in_external_macro: true
report_in_external_macro
}
declare_lint! {
@ -211,7 +211,7 @@ declare_lint! {
pub DEPRECATED,
Warn,
"detects use of deprecated items",
report_in_external_macro: true
report_in_external_macro
}
declare_lint! {
@ -381,7 +381,7 @@ declare_lint! {
pub DEPRECATED_IN_FUTURE,
Allow,
"detects use of items that will be deprecated in a future version",
report_in_external_macro: true
report_in_external_macro
}
declare_lint! {

View file

@ -81,6 +81,17 @@ pub struct Lint {
}
impl Lint {
pub const fn default_fields_for_macro() -> Self {
Lint {
name: "",
default_level: Level::Forbid,
desc: "",
edition_lint_opts: None,
is_plugin: false,
report_in_external_macro: false,
}
}
/// Returns the `rust::lint::Lint` for a `syntax::early_buffered_lints::BufferedEarlyLintId`.
pub fn from_parser_lint_id(lint_id: BufferedEarlyLintId) -> &'static Self {
match lint_id {
@ -107,19 +118,19 @@ impl Lint {
#[macro_export]
macro_rules! declare_lint {
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
declare_lint!{$vis $NAME, $Level, $desc, false}
declare_lint!(
$vis $NAME, $Level, $desc,
);
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr, report_in_external_macro: $rep: expr) => (
declare_lint!{$vis $NAME, $Level, $desc, $rep}
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $($v:ident),*) => (
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: stringify!($NAME),
default_level: $crate::lint::$Level,
desc: $desc,
edition_lint_opts: None,
report_in_external_macro: $external,
is_plugin: false,
$($v: true,)*
..$crate::lint::Lint::default_fields_for_macro()
};
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr,

View file

@ -280,7 +280,7 @@ declare_lint! {
pub MISSING_DOCS,
Allow,
"detects missing documentation for public members",
report_in_external_macro: true
report_in_external_macro
}
pub struct MissingDoc {
@ -1374,7 +1374,7 @@ declare_lint! {
UNNAMEABLE_TEST_ITEMS,
Warn,
"detects an item that cannot be named being marked as `#[test_case]`",
report_in_external_macro: true
report_in_external_macro
}
pub struct UnnameableTestItems {

View file

@ -25,7 +25,7 @@ declare_lint! {
pub UNUSED_MUST_USE,
Warn,
"unused result of a type flagged as `#[must_use]`",
report_in_external_macro: true
report_in_external_macro
}
declare_lint! {