mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor: Add a helper for telling if a level is an error
This commit is contained in:
parent
b2c0aea98d
commit
01a270f402
@ -329,6 +329,10 @@ impl Display for LintLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LintLevel {
|
impl LintLevel {
|
||||||
|
pub fn is_error(&self) -> bool {
|
||||||
|
self == &LintLevel::Forbid || self == &LintLevel::Deny
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_diagnostic_level(self) -> Level {
|
pub fn to_diagnostic_level(self) -> Level {
|
||||||
match self {
|
match self {
|
||||||
LintLevel::Allow => unreachable!("allow does not map to a diagnostic level"),
|
LintLevel::Allow => unreachable!("allow does not map to a diagnostic level"),
|
||||||
@ -440,7 +444,7 @@ pub fn check_im_a_teapot(
|
|||||||
.package()
|
.package()
|
||||||
.is_some_and(|p| p.im_a_teapot.is_some())
|
.is_some_and(|p| p.im_a_teapot.is_some())
|
||||||
{
|
{
|
||||||
if lint_level == LintLevel::Forbid || lint_level == LintLevel::Deny {
|
if lint_level.is_error() {
|
||||||
*error_count += 1;
|
*error_count += 1;
|
||||||
}
|
}
|
||||||
let level = lint_level.to_diagnostic_level();
|
let level = lint_level.to_diagnostic_level();
|
||||||
@ -514,7 +518,7 @@ fn output_unknown_lints(
|
|||||||
let level = lint_level.to_diagnostic_level();
|
let level = lint_level.to_diagnostic_level();
|
||||||
let mut emitted_source = None;
|
let mut emitted_source = None;
|
||||||
for lint_name in unknown_lints {
|
for lint_name in unknown_lints {
|
||||||
if lint_level == LintLevel::Forbid || lint_level == LintLevel::Deny {
|
if lint_level.is_error() {
|
||||||
*error_count += 1;
|
*error_count += 1;
|
||||||
}
|
}
|
||||||
let title = format!("{}: `{lint_name}`", UNKNOWN_LINTS.desc);
|
let title = format!("{}: `{lint_name}`", UNKNOWN_LINTS.desc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user