Skip to content

Commit

Permalink
Rollup merge of rust-lang#113079 - Zalathar:as-operand-id, r=oli-obk
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
TaKO8Ki authored Jun 27, 2023
2 parents b6cf0ac + fbb2079 commit 10f2b9b
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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), .. }) =
Expand Down

0 comments on commit 10f2b9b

Please sign in to comment.