From 7cd62020f1027f93fa2c5c7b64aa801a64d9331f Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sun, 12 Mar 2023 19:20:43 -0400 Subject: [PATCH 1/2] Simplify `declare_lints` definition. --- compiler/rustc_lint_defs/src/lib.rs | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 6f22bdabff450..1eb14e8a93c27 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -663,15 +663,14 @@ pub type RegisteredTools = FxIndexSet; /// commands to avoid rebuilding the compiler. #[macro_export] macro_rules! declare_lint { - ($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr) => ( - $crate::declare_lint!( - $(#[$attr])* $vis $NAME, $Level, $desc, - ); - ); - ($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr, - $(@feature_gate = $gate:expr;)? - $(@future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )? - $($v:ident),*) => ( + ( + $(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr + $(, + $(@feature_gate = $gate:expr;)? + $(@future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )? + $($v:ident),* $(,)? + )? + ) => ( $(#[$attr])* $vis static $NAME: &$crate::Lint = &$crate::Lint { name: stringify!($NAME), @@ -679,12 +678,14 @@ macro_rules! declare_lint { desc: $desc, edition_lint_opts: None, is_plugin: false, - $($v: true,)* - $(feature_gate: Some($gate),)* - $(future_incompatible: Some($crate::FutureIncompatibleInfo { - $($field: $val,)* - ..$crate::FutureIncompatibleInfo::default_fields_for_macro() - }),)* + $( + $($v: true,)* + $(feature_gate: Some($gate),)? + $(future_incompatible: Some($crate::FutureIncompatibleInfo { + $($field: $val,)* + ..$crate::FutureIncompatibleInfo::default_fields_for_macro() + }),)? + )? ..$crate::Lint::default_fields_for_macro() }; ); From a116a92c7f28a5f559a141c118103a10de0d51e0 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sun, 12 Mar 2023 19:21:15 -0400 Subject: [PATCH 2/2] Allow tool lint levels to be set based on the build environment. --- compiler/rustc_feature/src/lib.rs | 9 +++++++++ compiler/rustc_lint_defs/src/lib.rs | 25 +++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs index 93d1671634691..244ab9af29397 100644 --- a/compiler/rustc_feature/src/lib.rs +++ b/compiler/rustc_feature/src/lib.rs @@ -99,6 +99,15 @@ impl UnstableFeatures { } } + /// This only takes the build environment into account. + pub const fn is_nightly_build_environment() -> bool { + match option_env!("CFG_DISABLE_UNSTABLE_FEATURES") { + Some(x) if matches!(x.as_bytes(), b"0") => true, + None => true, + Some(_) => false, + } + } + pub fn is_nightly_build(&self) -> bool { match *self { UnstableFeatures::Allow | UnstableFeatures::Cheat => true, diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 1eb14e8a93c27..47922c3e61f0d 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -707,30 +707,39 @@ macro_rules! declare_lint { #[macro_export] macro_rules! declare_tool_lint { ( - $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr + $(, report_in_external_macro: $rep:expr)? $(, @feature_gate = $gate:expr;)? ) => ( - $crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @feature_gate = $gate;)?} + $crate::declare_tool_lint!{ + $(#[$attr])* $vis $tool::$NAME, $crate::$Level, $desc + $(, report_in_external_macro: $rep)? + $(, @feature_gate = $gate;)? + } ); ( $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, - report_in_external_macro: $rep:expr + $external:expr $(, @feature_gate = $gate:expr;)? ) => ( - $crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @feature_gate = $gate;)?} + $crate::declare_tool_lint!{ + $(#[$attr])* $vis $tool::$NAME, $crate::$Level, $desc + $(, report_in_external_macro: $external)? + $(, @feature_gate = $gate;)? + } ); ( - $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr, - $external:expr + $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:expr, $desc:expr + $(, report_in_external_macro: $external:expr)? $(, @feature_gate = $gate:expr;)? ) => ( $(#[$attr])* $vis static $NAME: &$crate::Lint = &$crate::Lint { name: &concat!(stringify!($tool), "::", stringify!($NAME)), - default_level: $crate::$Level, + default_level: $Level, desc: $desc, edition_lint_opts: None, - report_in_external_macro: $external, + $(report_in_external_macro: $external,)? future_incompatible: None, is_plugin: true, $(feature_gate: Some($gate),)?