Skip to content

Commit f542778

Browse files
committed
Drive-by cleanup: debug::term_type => TerminatorKind::name
1 parent 03d5f9b commit f542778

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,29 @@ pub enum TerminatorKind<'tcx> {
749749
},
750750
}
751751

752+
impl TerminatorKind<'_> {
753+
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
754+
/// values it might hold (e.g. `TerminatorKind::Call` always returns `"Call"`).
755+
pub const fn name(&self) -> &'static str {
756+
match self {
757+
TerminatorKind::Goto { .. } => "Goto",
758+
TerminatorKind::SwitchInt { .. } => "SwitchInt",
759+
TerminatorKind::Resume => "Resume",
760+
TerminatorKind::Terminate => "Terminate",
761+
TerminatorKind::Return => "Return",
762+
TerminatorKind::Unreachable => "Unreachable",
763+
TerminatorKind::Drop { .. } => "Drop",
764+
TerminatorKind::Call { .. } => "Call",
765+
TerminatorKind::Assert { .. } => "Assert",
766+
TerminatorKind::Yield { .. } => "Yield",
767+
TerminatorKind::GeneratorDrop => "GeneratorDrop",
768+
TerminatorKind::FalseEdge { .. } => "FalseEdge",
769+
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
770+
TerminatorKind::InlineAsm { .. } => "InlineAsm",
771+
}
772+
}
773+
}
774+
752775
/// Action to be taken when a stack unwind happens.
753776
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
754777
#[derive(TypeFoldable, TypeVisitable)]

compiler/rustc_mir_transform/src/coverage/debug.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ use rustc_middle::mir::spanview::{self, SpanViewable};
118118

119119
use rustc_data_structures::fx::FxHashMap;
120120
use rustc_middle::mir::coverage::*;
121-
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
121+
use rustc_middle::mir::{self, BasicBlock};
122122
use rustc_middle::ty::TyCtxt;
123123
use rustc_span::Span;
124124

@@ -796,36 +796,15 @@ fn bcb_to_string_sections<'tcx>(
796796
}
797797
let non_term_blocks = bcb_data.basic_blocks[0..len - 1]
798798
.iter()
799-
.map(|&bb| format!("{:?}: {}", bb, term_type(&mir_body[bb].terminator().kind)))
799+
.map(|&bb| format!("{:?}: {}", bb, mir_body[bb].terminator().kind.name()))
800800
.collect::<Vec<_>>();
801801
if non_term_blocks.len() > 0 {
802802
sections.push(non_term_blocks.join("\n"));
803803
}
804804
sections.push(format!(
805805
"{:?}: {}",
806806
bcb_data.basic_blocks.last().unwrap(),
807-
term_type(&bcb_data.terminator(mir_body).kind)
807+
bcb_data.terminator(mir_body).kind.name(),
808808
));
809809
sections
810810
}
811-
812-
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
813-
/// values it might hold.
814-
pub(super) fn term_type(kind: &TerminatorKind<'_>) -> &'static str {
815-
match kind {
816-
TerminatorKind::Goto { .. } => "Goto",
817-
TerminatorKind::SwitchInt { .. } => "SwitchInt",
818-
TerminatorKind::Resume => "Resume",
819-
TerminatorKind::Terminate => "Terminate",
820-
TerminatorKind::Return => "Return",
821-
TerminatorKind::Unreachable => "Unreachable",
822-
TerminatorKind::Drop { .. } => "Drop",
823-
TerminatorKind::Call { .. } => "Call",
824-
TerminatorKind::Assert { .. } => "Assert",
825-
TerminatorKind::Yield { .. } => "Yield",
826-
TerminatorKind::GeneratorDrop => "GeneratorDrop",
827-
TerminatorKind::FalseEdge { .. } => "FalseEdge",
828-
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
829-
TerminatorKind::InlineAsm { .. } => "InlineAsm",
830-
}
831-
}

compiler/rustc_mir_transform/src/coverage/spans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::debug::term_type;
21
use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph, START_BCB};
32

43
use itertools::Itertools;
@@ -40,7 +39,7 @@ impl CoverageStatement {
4039
"{}: @{}.{}: {:?}",
4140
source_range_no_file(tcx, span),
4241
bb.index(),
43-
term_type(&term.kind),
42+
term.kind.name(),
4443
term.kind
4544
)
4645
}

compiler/rustc_mir_transform/src/coverage/tests.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
//! to: `rustc_span::create_default_session_globals_then(|| { test_here(); })`.
2626
2727
use super::counters;
28-
use super::debug;
2928
use super::graph;
3029
use super::spans;
3130

@@ -188,12 +187,12 @@ fn debug_basic_blocks(mir_body: &Body<'_>) -> String {
188187
| TerminatorKind::Goto { target }
189188
| TerminatorKind::InlineAsm { destination: Some(target), .. }
190189
| TerminatorKind::Yield { resume: target, .. } => {
191-
format!("{}{:?}:{} -> {:?}", sp, bb, debug::term_type(kind), target)
190+
format!("{}{:?}:{} -> {:?}", sp, bb, kind.name(), target)
192191
}
193192
TerminatorKind::SwitchInt { targets, .. } => {
194-
format!("{}{:?}:{} -> {:?}", sp, bb, debug::term_type(kind), targets)
193+
format!("{}{:?}:{} -> {:?}", sp, bb, kind.name(), targets)
195194
}
196-
_ => format!("{}{:?}:{}", sp, bb, debug::term_type(kind)),
195+
_ => format!("{}{:?}:{}", sp, bb, kind.name()),
197196
}
198197
})
199198
.collect::<Vec<_>>()
@@ -215,7 +214,7 @@ fn print_mir_graphviz(name: &str, mir_body: &Body<'_>) {
215214
" {:?} [label=\"{:?}: {}\"];\n{}",
216215
bb,
217216
bb,
218-
debug::term_type(&data.terminator().kind),
217+
data.terminator().kind.name(),
219218
mir_body
220219
.basic_blocks
221220
.successors(bb)
@@ -244,7 +243,7 @@ fn print_coverage_graphviz(
244243
" {:?} [label=\"{:?}: {}\"];\n{}",
245244
bcb,
246245
bcb,
247-
debug::term_type(&bcb_data.terminator(mir_body).kind),
246+
bcb_data.terminator(mir_body).kind.name(),
248247
basic_coverage_blocks
249248
.successors(bcb)
250249
.map(|successor| { format!(" {:?} -> {:?};", bcb, successor) })

0 commit comments

Comments
 (0)