about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-06-27 17:48:46 +0200
committerGitHub <noreply@github.com>2023-06-27 17:48:46 +0200
commit526326e10de479c4e8b1f33dc6b2c2f442b5c4f4 (patch)
tree9017dcb5c0f34354a4a1e7dfcda5d6906f132990
parent1153aba3ec6faeb9286d1f2a25214685aa0febd7 (diff)
parentfbb2079a2410ccb067f7cb99f3ca3ebaccc543c4 (diff)
downloadrust-526326e10de479c4e8b1f33dc6b2c2f442b5c4f4.tar.gz
rust-526326e10de479c4e8b1f33dc6b2c2f442b5c4f4.zip
Rollup merge of #113079 - Zalathar:as-operand-id, r=oli-obk
Use `CoverageKind::as_operand_id` instead of manually reimplementing it

These two pieces of code are functionally equivalent to the `CoverageKind::as_operand_id` method that already exists, and is already used elsewhere in this file.

This slightly reduces the amount of code that manually pattern-matches on `CoverageKind`.
-rw-r--r--compiler/rustc_mir_transform/src/coverage/debug.rs17
1 files changed, 2 insertions, 15 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/debug.rs b/compiler/rustc_mir_transform/src/coverage/debug.rs
index 6a3d42511ac..7ad98144159 100644
--- a/compiler/rustc_mir_transform/src/coverage/debug.rs
+++ b/compiler/rustc_mir_transform/src/coverage/debug.rs
@@ -277,14 +277,7 @@ impl DebugCounters {
 
     pub fn add_counter(&mut self, counter_kind: &CoverageKind, some_block_label: Option<String>) {
         if let Some(counters) = &mut self.some_counters {
-            let id: ExpressionOperandId = match *counter_kind {
-                CoverageKind::Counter { id, .. } => id.into(),
-                CoverageKind::Expression { id, .. } => id.into(),
-                _ => bug!(
-                    "the given `CoverageKind` is not an counter or expression: {:?}",
-                    counter_kind
-                ),
-            };
+            let id = counter_kind.as_operand_id();
             counters
                 .try_insert(id, DebugCounter::new(counter_kind.clone(), some_block_label))
                 .expect("attempt to add the same counter_kind to DebugCounters more than once");
@@ -330,13 +323,7 @@ impl DebugCounters {
             }
         }
 
-        let id: ExpressionOperandId = match *counter_kind {
-            CoverageKind::Counter { id, .. } => id.into(),
-            CoverageKind::Expression { id, .. } => id.into(),
-            _ => {
-                bug!("the given `CoverageKind` is not an counter or expression: {:?}", counter_kind)
-            }
-        };
+        let id = counter_kind.as_operand_id();
         if self.some_counters.is_some() && (counter_format.block || !counter_format.id) {
             let counters = self.some_counters.as_ref().unwrap();
             if let Some(DebugCounter { some_block_label: Some(block_label), .. }) =