Skip to content

Commit 49b5701

Browse files
committed
sync printing of MIR terminators with their new names (and dedup some to-str logic)
1 parent 807e5b8 commit 49b5701

File tree

2 files changed

+27
-44
lines changed

2 files changed

+27
-44
lines changed

compiler/rustc_middle/src/mir/spanview.rs

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -238,45 +238,6 @@ pub fn source_range_no_file(tcx: TyCtxt<'_>, span: Span) -> String {
238238
format!("{}:{}-{}:{}", start.line, start.col.to_usize() + 1, end.line, end.col.to_usize() + 1)
239239
}
240240

241-
pub fn statement_kind_name(statement: &Statement<'_>) -> &'static str {
242-
use StatementKind::*;
243-
match statement.kind {
244-
Assign(..) => "Assign",
245-
FakeRead(..) => "FakeRead",
246-
SetDiscriminant { .. } => "SetDiscriminant",
247-
Deinit(..) => "Deinit",
248-
StorageLive(..) => "StorageLive",
249-
StorageDead(..) => "StorageDead",
250-
Retag(..) => "Retag",
251-
PlaceMention(..) => "PlaceMention",
252-
AscribeUserType(..) => "AscribeUserType",
253-
Coverage(..) => "Coverage",
254-
Intrinsic(..) => "Intrinsic",
255-
ConstEvalCounter => "ConstEvalCounter",
256-
Nop => "Nop",
257-
}
258-
}
259-
260-
pub fn terminator_kind_name(term: &Terminator<'_>) -> &'static str {
261-
use TerminatorKind::*;
262-
match term.kind {
263-
Goto { .. } => "Goto",
264-
SwitchInt { .. } => "SwitchInt",
265-
UnwindResume => "Resume",
266-
UnwindTerminate => "Terminate",
267-
Return => "Return",
268-
Unreachable => "Unreachable",
269-
Drop { .. } => "Drop",
270-
Call { .. } => "Call",
271-
Assert { .. } => "Assert",
272-
Yield { .. } => "Yield",
273-
GeneratorDrop => "GeneratorDrop",
274-
FalseEdge { .. } => "FalseEdge",
275-
FalseUnwind { .. } => "FalseUnwind",
276-
InlineAsm { .. } => "InlineAsm",
277-
}
278-
}
279-
280241
fn statement_span_viewable<'tcx>(
281242
tcx: TyCtxt<'tcx>,
282243
body_span: Span,
@@ -304,7 +265,7 @@ fn terminator_span_viewable<'tcx>(
304265
if !body_span.contains(span) {
305266
return None;
306267
}
307-
let id = format!("{}:{}", bb.index(), terminator_kind_name(term));
268+
let id = format!("{}:{}", bb.index(), term.kind.name());
308269
let tooltip = tooltip(tcx, &id, span, vec![], &data.terminator);
309270
Some(SpanViewable { bb, span, id, tooltip })
310271
}
@@ -631,7 +592,7 @@ fn tooltip<'tcx>(
631592
"\n{}{}: {}: {:?}",
632593
TOOLTIP_INDENT,
633594
source_range,
634-
statement_kind_name(&statement),
595+
statement.kind.name(),
635596
statement
636597
));
637598
}
@@ -641,7 +602,7 @@ fn tooltip<'tcx>(
641602
"\n{}{}: {}: {:?}",
642603
TOOLTIP_INDENT,
643604
source_range,
644-
terminator_kind_name(term),
605+
term.kind.name(),
645606
term.kind
646607
));
647608
}

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,28 @@ pub enum StatementKind<'tcx> {
380380
Nop,
381381
}
382382

383+
impl StatementKind<'_> {
384+
/// Returns a simple string representation of a `StatementKind` variant, independent of any
385+
/// values it might hold (e.g. `StatementKind::Assign` always returns `"Assign"`).
386+
pub const fn name(&self) -> &'static str {
387+
match self {
388+
StatementKind::Assign(..) => "Assign",
389+
StatementKind::FakeRead(..) => "FakeRead",
390+
StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
391+
StatementKind::Deinit(..) => "Deinit",
392+
StatementKind::StorageLive(..) => "StorageLive",
393+
StatementKind::StorageDead(..) => "StorageDead",
394+
StatementKind::Retag(..) => "Retag",
395+
StatementKind::PlaceMention(..) => "PlaceMention",
396+
StatementKind::AscribeUserType(..) => "AscribeUserType",
397+
StatementKind::Coverage(..) => "Coverage",
398+
StatementKind::Intrinsic(..) => "Intrinsic",
399+
StatementKind::ConstEvalCounter => "ConstEvalCounter",
400+
StatementKind::Nop => "Nop",
401+
}
402+
}
403+
}
404+
383405
#[derive(
384406
Clone,
385407
TyEncodable,
@@ -790,8 +812,8 @@ impl TerminatorKind<'_> {
790812
match self {
791813
TerminatorKind::Goto { .. } => "Goto",
792814
TerminatorKind::SwitchInt { .. } => "SwitchInt",
793-
TerminatorKind::UnwindResume => "Resume",
794-
TerminatorKind::UnwindTerminate => "Terminate",
815+
TerminatorKind::UnwindResume => "UnwindResume",
816+
TerminatorKind::UnwindTerminate => "UnwindTerminate",
795817
TerminatorKind::Return => "Return",
796818
TerminatorKind::Unreachable => "Unreachable",
797819
TerminatorKind::Drop { .. } => "Drop",

0 commit comments

Comments
 (0)