mirror of https://github.com/rust-lang/rust.git
Remove `is_lint` field from `Level::Error`.
Because it's redundant w.r.t. `Diagnostic::is_lint`, which is present for every diagnostic level. `struct_lint_level_impl` was the only place that set the `Error` field to `true`, and it's also the only place that calls `Diagnostic::is_lint()` to set the `is_lint` field.
This commit is contained in:
parent
8e6bca63f9
commit
8388112970
|
@ -395,7 +395,7 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
|
||||||
// These were a warning before #92959 and need to continue being that to avoid breaking
|
// These were a warning before #92959 and need to continue being that to avoid breaking
|
||||||
// stable user code (#94508).
|
// stable user code (#94508).
|
||||||
Some(ast::ItemKind::MacCall(_)) => Level::Warning(None),
|
Some(ast::ItemKind::MacCall(_)) => Level::Warning(None),
|
||||||
_ => Level::Error { lint: false },
|
_ => Level::Error,
|
||||||
};
|
};
|
||||||
let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg);
|
let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg);
|
||||||
err.span(attr_sp);
|
err.span(attr_sp);
|
||||||
|
|
|
@ -416,7 +416,7 @@ fn report_inline_asm(
|
||||||
cookie = 0;
|
cookie = 0;
|
||||||
}
|
}
|
||||||
let level = match level {
|
let level = match level {
|
||||||
llvm::DiagnosticLevel::Error => Level::Error { lint: false },
|
llvm::DiagnosticLevel::Error => Level::Error,
|
||||||
llvm::DiagnosticLevel::Warning => Level::Warning(None),
|
llvm::DiagnosticLevel::Warning => Level::Warning(None),
|
||||||
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
|
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1848,7 +1848,7 @@ impl SharedEmitterMain {
|
||||||
}
|
}
|
||||||
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
|
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
|
||||||
let err_level = match level {
|
let err_level = match level {
|
||||||
Level::Error { lint: false } => Level::Error { lint: false },
|
Level::Error => Level::Error,
|
||||||
Level::Warning(_) => Level::Warning(None),
|
Level::Warning(_) => Level::Warning(None),
|
||||||
Level::Note => Level::Note,
|
Level::Note => Level::Note,
|
||||||
_ => bug!("Invalid inline asm diagnostic level"),
|
_ => bug!("Invalid inline asm diagnostic level"),
|
||||||
|
|
|
@ -86,9 +86,7 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
|
||||||
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
|
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
|
||||||
fn annotation_type_for_level(level: Level) -> AnnotationType {
|
fn annotation_type_for_level(level: Level) -> AnnotationType {
|
||||||
match level {
|
match level {
|
||||||
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error { .. } => {
|
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error => AnnotationType::Error,
|
||||||
AnnotationType::Error
|
|
||||||
}
|
|
||||||
Level::Warning(_) => AnnotationType::Warning,
|
Level::Warning(_) => AnnotationType::Warning,
|
||||||
Level::Note | Level::OnceNote => AnnotationType::Note,
|
Level::Note | Level::OnceNote => AnnotationType::Note,
|
||||||
Level::Help | Level::OnceHelp => AnnotationType::Help,
|
Level::Help | Level::OnceHelp => AnnotationType::Help,
|
||||||
|
|
|
@ -244,11 +244,9 @@ impl Diagnostic {
|
||||||
|
|
||||||
pub fn is_error(&self) -> bool {
|
pub fn is_error(&self) -> bool {
|
||||||
match self.level {
|
match self.level {
|
||||||
Level::Bug
|
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error | Level::FailureNote => {
|
||||||
| Level::DelayedBug
|
true
|
||||||
| Level::Fatal
|
}
|
||||||
| Level::Error { .. }
|
|
||||||
| Level::FailureNote => true,
|
|
||||||
|
|
||||||
Level::Warning(_)
|
Level::Warning(_)
|
||||||
| Level::Note
|
| Level::Note
|
||||||
|
|
|
@ -673,7 +673,7 @@ impl DiagCtxt {
|
||||||
let key = (span.with_parent(None), key);
|
let key = (span.with_parent(None), key);
|
||||||
|
|
||||||
if diag.is_error() {
|
if diag.is_error() {
|
||||||
if matches!(diag.level, Error { lint: true }) {
|
if diag.level == Error && diag.is_lint {
|
||||||
inner.lint_err_count += 1;
|
inner.lint_err_count += 1;
|
||||||
} else {
|
} else {
|
||||||
inner.err_count += 1;
|
inner.err_count += 1;
|
||||||
|
@ -697,7 +697,7 @@ impl DiagCtxt {
|
||||||
let key = (span.with_parent(None), key);
|
let key = (span.with_parent(None), key);
|
||||||
let diag = inner.stashed_diagnostics.remove(&key)?;
|
let diag = inner.stashed_diagnostics.remove(&key)?;
|
||||||
if diag.is_error() {
|
if diag.is_error() {
|
||||||
if matches!(diag.level, Error { lint: true }) {
|
if diag.level == Error && diag.is_lint {
|
||||||
inner.lint_err_count -= 1;
|
inner.lint_err_count -= 1;
|
||||||
} else {
|
} else {
|
||||||
inner.err_count -= 1;
|
inner.err_count -= 1;
|
||||||
|
@ -812,7 +812,7 @@ impl DiagCtxt {
|
||||||
#[rustc_lint_diagnostics]
|
#[rustc_lint_diagnostics]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
|
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
|
||||||
DiagnosticBuilder::new(self, Error { lint: false }, msg)
|
DiagnosticBuilder::new(self, Error, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a builder at the `Error` level with the `msg` and the `code`.
|
/// Construct a builder at the `Error` level with the `msg` and the `code`.
|
||||||
|
@ -1212,7 +1212,7 @@ impl DiagCtxt {
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
|
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
|
||||||
err.into_diagnostic(self, Error { lint: false })
|
err.into_diagnostic(self, Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -1367,7 +1367,7 @@ impl DiagCtxtInner {
|
||||||
for diag in diags {
|
for diag in diags {
|
||||||
// Decrement the count tracking the stash; emitting will increment it.
|
// Decrement the count tracking the stash; emitting will increment it.
|
||||||
if diag.is_error() {
|
if diag.is_error() {
|
||||||
if matches!(diag.level, Error { lint: true }) {
|
if diag.level == Error && diag.is_lint {
|
||||||
self.lint_err_count -= 1;
|
self.lint_err_count -= 1;
|
||||||
} else {
|
} else {
|
||||||
self.err_count -= 1;
|
self.err_count -= 1;
|
||||||
|
@ -1398,7 +1398,7 @@ impl DiagCtxtInner {
|
||||||
&mut self,
|
&mut self,
|
||||||
diagnostic: &mut Diagnostic,
|
diagnostic: &mut Diagnostic,
|
||||||
) -> Option<ErrorGuaranteed> {
|
) -> Option<ErrorGuaranteed> {
|
||||||
if matches!(diagnostic.level, Error { .. } | Fatal) && self.treat_err_as_bug() {
|
if matches!(diagnostic.level, Error | Fatal) && self.treat_err_as_bug() {
|
||||||
diagnostic.level = Bug;
|
diagnostic.level = Bug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1499,7 +1499,7 @@ impl DiagCtxtInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if diagnostic.is_error() {
|
if diagnostic.is_error() {
|
||||||
if matches!(diagnostic.level, Error { lint: true }) {
|
if diagnostic.level == Error && diagnostic.is_lint {
|
||||||
self.bump_lint_err_count();
|
self.bump_lint_err_count();
|
||||||
} else {
|
} else {
|
||||||
self.bump_err_count();
|
self.bump_err_count();
|
||||||
|
@ -1695,11 +1695,7 @@ pub enum Level {
|
||||||
/// most common case.
|
/// most common case.
|
||||||
///
|
///
|
||||||
/// Its `EmissionGuarantee` is `ErrorGuaranteed`.
|
/// Its `EmissionGuarantee` is `ErrorGuaranteed`.
|
||||||
Error {
|
Error,
|
||||||
/// If this error comes from a lint, don't abort compilation even when abort_if_errors() is
|
|
||||||
/// called.
|
|
||||||
lint: bool,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// A warning about the code being compiled. Does not prevent compilation from finishing.
|
/// A warning about the code being compiled. Does not prevent compilation from finishing.
|
||||||
///
|
///
|
||||||
|
@ -1758,7 +1754,7 @@ impl Level {
|
||||||
fn color(self) -> ColorSpec {
|
fn color(self) -> ColorSpec {
|
||||||
let mut spec = ColorSpec::new();
|
let mut spec = ColorSpec::new();
|
||||||
match self {
|
match self {
|
||||||
Bug | DelayedBug | Fatal | Error { .. } => {
|
Bug | DelayedBug | Fatal | Error => {
|
||||||
spec.set_fg(Some(Color::Red)).set_intense(true);
|
spec.set_fg(Some(Color::Red)).set_intense(true);
|
||||||
}
|
}
|
||||||
Warning(_) => {
|
Warning(_) => {
|
||||||
|
@ -1779,7 +1775,7 @@ impl Level {
|
||||||
pub fn to_str(self) -> &'static str {
|
pub fn to_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Bug | DelayedBug => "error: internal compiler error",
|
Bug | DelayedBug => "error: internal compiler error",
|
||||||
Fatal | Error { .. } => "error",
|
Fatal | Error => "error",
|
||||||
Warning(_) => "warning",
|
Warning(_) => "warning",
|
||||||
Note | OnceNote => "note",
|
Note | OnceNote => "note",
|
||||||
Help | OnceHelp => "help",
|
Help | OnceHelp => "help",
|
||||||
|
|
|
@ -379,7 +379,7 @@ impl ToInternal<SmallVec<[tokenstream::TokenTree; 2]>>
|
||||||
impl ToInternal<rustc_errors::Level> for Level {
|
impl ToInternal<rustc_errors::Level> for Level {
|
||||||
fn to_internal(self) -> rustc_errors::Level {
|
fn to_internal(self) -> rustc_errors::Level {
|
||||||
match self {
|
match self {
|
||||||
Level::Error => rustc_errors::Level::Error { lint: false },
|
Level::Error => rustc_errors::Level::Error,
|
||||||
Level::Warning => rustc_errors::Level::Warning(None),
|
Level::Warning => rustc_errors::Level::Warning(None),
|
||||||
Level::Note => rustc_errors::Level::Note,
|
Level::Note => rustc_errors::Level::Note,
|
||||||
Level::Help => rustc_errors::Level::Help,
|
Level::Help => rustc_errors::Level::Help,
|
||||||
|
|
|
@ -314,7 +314,7 @@ pub fn struct_lint_level(
|
||||||
}
|
}
|
||||||
Level::ForceWarn(Some(expect_id)) => rustc_errors::Level::Warning(Some(expect_id)),
|
Level::ForceWarn(Some(expect_id)) => rustc_errors::Level::Warning(Some(expect_id)),
|
||||||
Level::Warn | Level::ForceWarn(None) => rustc_errors::Level::Warning(None),
|
Level::Warn | Level::ForceWarn(None) => rustc_errors::Level::Warning(None),
|
||||||
Level::Deny | Level::Forbid => rustc_errors::Level::Error { lint: true },
|
Level::Deny | Level::Forbid => rustc_errors::Level::Error,
|
||||||
};
|
};
|
||||||
let mut err = DiagnosticBuilder::new(sess.dcx(), err_level, "");
|
let mut err = DiagnosticBuilder::new(sess.dcx(), err_level, "");
|
||||||
if let Some(span) = span {
|
if let Some(span) = span {
|
||||||
|
|
|
@ -454,7 +454,7 @@ pub fn report_msg<'tcx>(
|
||||||
let span = stacktrace.first().map_or(DUMMY_SP, |fi| fi.span);
|
let span = stacktrace.first().map_or(DUMMY_SP, |fi| fi.span);
|
||||||
let sess = machine.tcx.sess;
|
let sess = machine.tcx.sess;
|
||||||
let level = match diag_level {
|
let level = match diag_level {
|
||||||
DiagLevel::Error => Level::Error { lint: false },
|
DiagLevel::Error => Level::Error,
|
||||||
DiagLevel::Warning => Level::Warning(None),
|
DiagLevel::Warning => Level::Warning(None),
|
||||||
DiagLevel::Note => Level::Note,
|
DiagLevel::Note => Level::Note,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue