Skip to content

Allow tool lint levels to be set based on the build environment. #109063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_feature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 33 additions & 23 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,28 +663,29 @@ pub type RegisteredTools = FxIndexSet<Ident>;
/// 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),
default_level: $crate::$Level,
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()
};
);
Expand All @@ -706,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),)?
Expand Down