mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Rollup merge of #106669 - ozkanonur:helper-function-for-lint-level, r=Nilstrieb
create helper function for `rustc_lint_defs::Level` and remove it's duplicated code Signed-off-by: ozkanonur <work@onurozkan.dev>
This commit is contained in:
commit
0e92e1dd99
@ -179,16 +179,7 @@ impl IntoDiagnosticArg for type_ir::FloatTy {
|
||||
|
||||
impl IntoDiagnosticArg for Level {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(match self {
|
||||
Level::Allow => "-A",
|
||||
Level::Warn => "-W",
|
||||
Level::ForceWarn(_) => "--force-warn",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
Level::Expect(_) => {
|
||||
unreachable!("lints with the level of `expect` should not run this code");
|
||||
}
|
||||
}))
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,6 +253,19 @@ impl Level {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_cmd_flag(self) -> &'static str {
|
||||
match self {
|
||||
Level::Warn => "-W",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
Level::Allow => "-A",
|
||||
Level::ForceWarn(_) => "--force-warn",
|
||||
Level::Expect(_) => {
|
||||
unreachable!("the expect level does not have a commandline flag")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_error(self) -> bool {
|
||||
match self {
|
||||
Level::Allow | Level::Expect(_) | Level::Warn | Level::ForceWarn(_) => false,
|
||||
|
@ -234,16 +234,7 @@ pub fn explain_lint_level_source(
|
||||
err.note_once(&format!("`#[{}({})]` on by default", level.as_str(), name));
|
||||
}
|
||||
LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
|
||||
let flag = match orig_level {
|
||||
Level::Warn => "-W",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
Level::Allow => "-A",
|
||||
Level::ForceWarn(_) => "--force-warn",
|
||||
Level::Expect(_) => {
|
||||
unreachable!("the expect level does not have a commandline flag")
|
||||
}
|
||||
};
|
||||
let flag = orig_level.to_cmd_flag();
|
||||
let hyphen_case_lint_name = name.replace('_', "-");
|
||||
if lint_flag_val.as_str() == name {
|
||||
err.note_once(&format!(
|
||||
|
Loading…
Reference in New Issue
Block a user