Skip to content

Commit 8388112

Browse files
committed
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.
1 parent 8e6bca6 commit 8388112

File tree

9 files changed

+20
-28
lines changed

9 files changed

+20
-28
lines changed

compiler/rustc_builtin_macros/src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
395395
// These were a warning before #92959 and need to continue being that to avoid breaking
396396
// stable user code (#94508).
397397
Some(ast::ItemKind::MacCall(_)) => Level::Warning(None),
398-
_ => Level::Error { lint: false },
398+
_ => Level::Error,
399399
};
400400
let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg);
401401
err.span(attr_sp);

compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn report_inline_asm(
416416
cookie = 0;
417417
}
418418
let level = match level {
419-
llvm::DiagnosticLevel::Error => Level::Error { lint: false },
419+
llvm::DiagnosticLevel::Error => Level::Error,
420420
llvm::DiagnosticLevel::Warning => Level::Warning(None),
421421
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
422422
};

compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ impl SharedEmitterMain {
18481848
}
18491849
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
18501850
let err_level = match level {
1851-
Level::Error { lint: false } => Level::Error { lint: false },
1851+
Level::Error => Level::Error,
18521852
Level::Warning(_) => Level::Warning(None),
18531853
Level::Note => Level::Note,
18541854
_ => bug!("Invalid inline asm diagnostic level"),

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8686
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
8787
fn annotation_type_for_level(level: Level) -> AnnotationType {
8888
match level {
89-
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error { .. } => {
90-
AnnotationType::Error
91-
}
89+
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error => AnnotationType::Error,
9290
Level::Warning(_) => AnnotationType::Warning,
9391
Level::Note | Level::OnceNote => AnnotationType::Note,
9492
Level::Help | Level::OnceHelp => AnnotationType::Help,

compiler/rustc_errors/src/diagnostic.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,9 @@ impl Diagnostic {
244244

245245
pub fn is_error(&self) -> bool {
246246
match self.level {
247-
Level::Bug
248-
| Level::DelayedBug
249-
| Level::Fatal
250-
| Level::Error { .. }
251-
| Level::FailureNote => true,
247+
Level::Bug | Level::DelayedBug | Level::Fatal | Level::Error | Level::FailureNote => {
248+
true
249+
}
252250

253251
Level::Warning(_)
254252
| Level::Note

compiler/rustc_errors/src/lib.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl DiagCtxt {
673673
let key = (span.with_parent(None), key);
674674

675675
if diag.is_error() {
676-
if matches!(diag.level, Error { lint: true }) {
676+
if diag.level == Error && diag.is_lint {
677677
inner.lint_err_count += 1;
678678
} else {
679679
inner.err_count += 1;
@@ -697,7 +697,7 @@ impl DiagCtxt {
697697
let key = (span.with_parent(None), key);
698698
let diag = inner.stashed_diagnostics.remove(&key)?;
699699
if diag.is_error() {
700-
if matches!(diag.level, Error { lint: true }) {
700+
if diag.level == Error && diag.is_lint {
701701
inner.lint_err_count -= 1;
702702
} else {
703703
inner.err_count -= 1;
@@ -812,7 +812,7 @@ impl DiagCtxt {
812812
#[rustc_lint_diagnostics]
813813
#[track_caller]
814814
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
815-
DiagnosticBuilder::new(self, Error { lint: false }, msg)
815+
DiagnosticBuilder::new(self, Error, msg)
816816
}
817817

818818
/// Construct a builder at the `Error` level with the `msg` and the `code`.
@@ -1212,7 +1212,7 @@ impl DiagCtxt {
12121212

12131213
#[track_caller]
12141214
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
1215-
err.into_diagnostic(self, Error { lint: false })
1215+
err.into_diagnostic(self, Error)
12161216
}
12171217

12181218
#[track_caller]
@@ -1367,7 +1367,7 @@ impl DiagCtxtInner {
13671367
for diag in diags {
13681368
// Decrement the count tracking the stash; emitting will increment it.
13691369
if diag.is_error() {
1370-
if matches!(diag.level, Error { lint: true }) {
1370+
if diag.level == Error && diag.is_lint {
13711371
self.lint_err_count -= 1;
13721372
} else {
13731373
self.err_count -= 1;
@@ -1398,7 +1398,7 @@ impl DiagCtxtInner {
13981398
&mut self,
13991399
diagnostic: &mut Diagnostic,
14001400
) -> Option<ErrorGuaranteed> {
1401-
if matches!(diagnostic.level, Error { .. } | Fatal) && self.treat_err_as_bug() {
1401+
if matches!(diagnostic.level, Error | Fatal) && self.treat_err_as_bug() {
14021402
diagnostic.level = Bug;
14031403
}
14041404

@@ -1499,7 +1499,7 @@ impl DiagCtxtInner {
14991499
}
15001500
}
15011501
if diagnostic.is_error() {
1502-
if matches!(diagnostic.level, Error { lint: true }) {
1502+
if diagnostic.level == Error && diagnostic.is_lint {
15031503
self.bump_lint_err_count();
15041504
} else {
15051505
self.bump_err_count();
@@ -1695,11 +1695,7 @@ pub enum Level {
16951695
/// most common case.
16961696
///
16971697
/// Its `EmissionGuarantee` is `ErrorGuaranteed`.
1698-
Error {
1699-
/// If this error comes from a lint, don't abort compilation even when abort_if_errors() is
1700-
/// called.
1701-
lint: bool,
1702-
},
1698+
Error,
17031699

17041700
/// A warning about the code being compiled. Does not prevent compilation from finishing.
17051701
///
@@ -1758,7 +1754,7 @@ impl Level {
17581754
fn color(self) -> ColorSpec {
17591755
let mut spec = ColorSpec::new();
17601756
match self {
1761-
Bug | DelayedBug | Fatal | Error { .. } => {
1757+
Bug | DelayedBug | Fatal | Error => {
17621758
spec.set_fg(Some(Color::Red)).set_intense(true);
17631759
}
17641760
Warning(_) => {
@@ -1779,7 +1775,7 @@ impl Level {
17791775
pub fn to_str(self) -> &'static str {
17801776
match self {
17811777
Bug | DelayedBug => "error: internal compiler error",
1782-
Fatal | Error { .. } => "error",
1778+
Fatal | Error => "error",
17831779
Warning(_) => "warning",
17841780
Note | OnceNote => "note",
17851781
Help | OnceHelp => "help",

compiler/rustc_expand/src/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl ToInternal<SmallVec<[tokenstream::TokenTree; 2]>>
379379
impl ToInternal<rustc_errors::Level> for Level {
380380
fn to_internal(self) -> rustc_errors::Level {
381381
match self {
382-
Level::Error => rustc_errors::Level::Error { lint: false },
382+
Level::Error => rustc_errors::Level::Error,
383383
Level::Warning => rustc_errors::Level::Warning(None),
384384
Level::Note => rustc_errors::Level::Note,
385385
Level::Help => rustc_errors::Level::Help,

compiler/rustc_middle/src/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub fn struct_lint_level(
314314
}
315315
Level::ForceWarn(Some(expect_id)) => rustc_errors::Level::Warning(Some(expect_id)),
316316
Level::Warn | Level::ForceWarn(None) => rustc_errors::Level::Warning(None),
317-
Level::Deny | Level::Forbid => rustc_errors::Level::Error { lint: true },
317+
Level::Deny | Level::Forbid => rustc_errors::Level::Error,
318318
};
319319
let mut err = DiagnosticBuilder::new(sess.dcx(), err_level, "");
320320
if let Some(span) = span {

src/tools/miri/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub fn report_msg<'tcx>(
454454
let span = stacktrace.first().map_or(DUMMY_SP, |fi| fi.span);
455455
let sess = machine.tcx.sess;
456456
let level = match diag_level {
457-
DiagLevel::Error => Level::Error { lint: false },
457+
DiagLevel::Error => Level::Error,
458458
DiagLevel::Warning => Level::Warning(None),
459459
DiagLevel::Note => Level::Note,
460460
};

0 commit comments

Comments
 (0)