about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-03-01 13:46:00 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-03-01 13:56:24 +1100
commit7ef605be3fa24f93194a3faf4f75d3a05ceca78a (patch)
tree885014c13c3e6843033a764623c91dbb12b66119 /compiler/rustc_errors/src
parenta7d926265f25abfd05b13a3a0144f2ad9dd02dd7 (diff)
downloadrust-7ef605be3fa24f93194a3faf4f75d3a05ceca78a.tar.gz
rust-7ef605be3fa24f93194a3faf4f75d3a05ceca78a.zip
Make the `match` in `emit_diagnostic` complete.
This match is complex enough that it's a good idea to enumerate every
variant.

This also means `can_be_top_or_sub` can just be `can_be_subdiag`.
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/emitter.rs2
-rw-r--r--compiler/rustc_errors/src/lib.rs41
2 files changed, 24 insertions, 19 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 5637c05d04c..212bda5ff03 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -2104,7 +2104,7 @@ impl HumanEmitter {
                 }
                 if !self.short_message {
                     for child in children {
-                        assert!(child.level.can_be_top_or_sub().1);
+                        assert!(child.level.can_be_subdiag());
                         let span = &child.span;
                         if let Err(err) = self.emit_messages_default_inner(
                             span,
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 738016f9b99..069ac863d99 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -1354,8 +1354,6 @@ impl DiagCtxtInner {
 
     // Return value is only `Some` if the level is `Error` or `DelayedBug`.
     fn emit_diagnostic(&mut self, mut diagnostic: DiagInner) -> Option<ErrorGuaranteed> {
-        assert!(diagnostic.level.can_be_top_or_sub().0);
-
         if diagnostic.has_future_breakage() {
             // Future breakages aren't emitted if they're Level::Allow,
             // but they still need to be constructed and stashed below,
@@ -1368,9 +1366,12 @@ impl DiagCtxtInner {
         // return early *and* have some kind of side-effect, except where
         // noted.
         match diagnostic.level {
-            Fatal | Error if self.treat_next_err_as_bug() => {
-                // `Fatal` and `Error` can be promoted to `Bug`.
-                diagnostic.level = Bug;
+            Bug => {}
+            Fatal | Error => {
+                if self.treat_next_err_as_bug() {
+                    // `Fatal` and `Error` can be promoted to `Bug`.
+                    diagnostic.level = Bug;
+                }
             }
             DelayedBug => {
                 // Note that because we check these conditions first,
@@ -1405,14 +1406,21 @@ impl DiagCtxtInner {
                     };
                 }
             }
-            Warning if !self.flags.can_emit_warnings => {
-                if diagnostic.has_future_breakage() {
-                    // The side-effect is at the top of this method.
-                    TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
+            ForceWarning(None) => {} // `ForceWarning(Some(...))` is below, with `Expect`
+            Warning => {
+                if !self.flags.can_emit_warnings {
+                    // We are not emitting warnings.
+                    if diagnostic.has_future_breakage() {
+                        // The side-effect is at the top of this method.
+                        TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
+                    }
+                    return None;
                 }
-                return None;
             }
+            Note | Help | FailureNote => {}
+            OnceNote | OnceHelp => panic!("bad level: {:?}", diagnostic.level),
             Allow => {
+                // Nothing emitted for allowed lints.
                 if diagnostic.has_future_breakage() {
                     // The side-effect is at the top of this method.
                     TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
@@ -1434,12 +1442,12 @@ impl DiagCtxtInner {
                 }
                 self.fulfilled_expectations.insert(expect_id.normalize());
                 if let Expect(_) = diagnostic.level {
+                    // Nothing emitted here for expected lints.
                     TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
                     self.suppressed_expected_diag = true;
                     return None;
                 }
             }
-            _ => {}
         }
 
         TRACK_DIAGNOSTIC(diagnostic, &mut |mut diagnostic| {
@@ -1816,16 +1824,13 @@ impl Level {
         matches!(*self, FailureNote)
     }
 
-    // Can this level be used in a top-level diagnostic message and/or a
-    // subdiagnostic message?
-    fn can_be_top_or_sub(&self) -> (bool, bool) {
+    // Can this level be used in a subdiagnostic message?
+    fn can_be_subdiag(&self) -> bool {
         match self {
             Bug | DelayedBug | Fatal | Error | ForceWarning(_) | FailureNote | Allow
-            | Expect(_) => (true, false),
-
-            Warning | Note | Help => (true, true),
+            | Expect(_) => false,
 
-            OnceNote | OnceHelp => (false, true),
+            Warning | Note | Help | OnceNote | OnceHelp => true,
         }
     }
 }