about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-01-09 12:28:45 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-01-11 07:56:17 +1100
commit0e388f21928219472d34a121cc33fcc4cf3e2c77 (patch)
tree9b45d67f1bcefe33f30c7f249e3c4ede378058d9 /compiler/rustc_middle/src
parent06cf8819690c586fe3bf0b710e6859202095ac15 (diff)
Change how `force-warn` lint diagnostics are recorded.
`is_force_warn` is only possible for diagnostics with `Level::Warning`,
but it is currently stored in `Diagnostic::code`, which every diagnostic
has.

This commit:
- removes the boolean `DiagnosticId::Lint::is_force_warn` field;
- adds a `ForceWarning` variant to `Level`.

Benefits:
- The common `Level::Warning` case now has no arguments, replacing
  lots of `Warning(None)` occurrences.
- `rustc_session::lint::Level` and `rustc_errors::Level` are more
  similar, both having `ForceWarning` and `Warning`.
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/lint.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs
index 212e831e106..c5e4dfaf19e 100644
--- a/compiler/rustc_middle/src/lint.rs
+++ b/compiler/rustc_middle/src/lint.rs
@@ -312,8 +312,9 @@ pub fn struct_lint_level(
                 // create a `DiagnosticBuilder` and continue as we would for warnings.
                 rustc_errors::Level::Expect(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::ForceWarn(Some(expect_id)) => rustc_errors::Level::ForceWarning(Some(expect_id)),
+            Level::ForceWarn(None) => rustc_errors::Level::ForceWarning(None),
+            Level::Warn => rustc_errors::Level::Warning,
             Level::Deny | Level::Forbid => rustc_errors::Level::Error,
         };
         let mut err = DiagnosticBuilder::new(sess.dcx(), err_level, "");
@@ -350,22 +351,19 @@ pub fn struct_lint_level(
         // suppressed the lint due to macros.
         err.primary_message(msg);
 
+        let name = lint.name_lower();
+        err.code(DiagnosticId::Lint { name, has_future_breakage });
+
         // Lint diagnostics that are covered by the expect level will not be emitted outside
         // the compiler. It is therefore not necessary to add any information for the user.
         // This will therefore directly call the decorate function which will in turn emit
         // the `Diagnostic`.
         if let Level::Expect(_) = level {
-            let name = lint.name_lower();
-            err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn: false });
             decorate(&mut err);
             err.emit();
             return;
         }
 
-        let name = lint.name_lower();
-        let is_force_warn = matches!(level, Level::ForceWarn(_));
-        err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn });
-
         if let Some(future_incompatible) = future_incompatible {
             let explanation = match future_incompatible.reason {
                 FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps