Skip to content

Commit 965f46b

Browse files
committed
de-structure variable and add stables
1 parent c703af3 commit 965f46b

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+39-29
Original file line numberDiff line numberDiff line change
@@ -425,35 +425,9 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> {
425425
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
426426
stable_mir::mir::VarDebugInfo {
427427
name: self.name.to_string(),
428-
source_info: stable_mir::mir::SourceInfo {
429-
span: self.source_info.span.stable(tables),
430-
scope: self.source_info.scope.into(),
431-
},
432-
composite: {
433-
if let Some(composite) = &self.composite {
434-
Some(VarDebugInfoFragment {
435-
ty: composite.ty.stable(tables),
436-
projection: composite.projection.iter().map(|e| e.stable(tables)).collect(),
437-
})
438-
} else {
439-
None
440-
}
441-
},
442-
value: {
443-
match self.value {
444-
mir::VarDebugInfoContents::Place(place) => {
445-
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
446-
}
447-
mir::VarDebugInfoContents::Const(const_operand) => {
448-
let op = ConstOperand {
449-
span: const_operand.span.stable(tables),
450-
user_ty: const_operand.user_ty.map(|index| index.as_usize()),
451-
const_: const_operand.const_.stable(tables),
452-
};
453-
stable_mir::mir::VarDebugInfoContents::Const(op)
454-
}
455-
}
456-
},
428+
source_info: self.source_info.stable(tables),
429+
composite: self.composite.as_ref().map(|composite| composite.stable(tables)),
430+
value: self.value.stable(tables),
457431
argument_index: self.argument_index,
458432
}
459433
}
@@ -466,6 +440,42 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
466440
}
467441
}
468442

443+
impl<'tcx> Stable<'tcx> for mir::SourceInfo {
444+
type T = stable_mir::mir::SourceInfo;
445+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
446+
stable_mir::mir::SourceInfo { span: self.span.stable(tables), scope: self.scope.into() }
447+
}
448+
}
449+
450+
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> {
451+
type T = stable_mir::mir::VarDebugInfoFragment;
452+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
453+
VarDebugInfoFragment {
454+
ty: self.ty.stable(tables),
455+
projection: self.projection.iter().map(|e| e.stable(tables)).collect(),
456+
}
457+
}
458+
}
459+
460+
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> {
461+
type T = stable_mir::mir::VarDebugInfoContents;
462+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
463+
match self {
464+
mir::VarDebugInfoContents::Place(place) => {
465+
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
466+
}
467+
mir::VarDebugInfoContents::Const(const_operand) => {
468+
let op = ConstOperand {
469+
span: const_operand.span.stable(tables),
470+
user_ty: const_operand.user_ty.map(|index| index.as_usize()),
471+
const_: const_operand.const_.stable(tables),
472+
};
473+
stable_mir::mir::VarDebugInfoContents::Const(op)
474+
}
475+
}
476+
}
477+
}
478+
469479
impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {
470480
type T = stable_mir::mir::StatementKind;
471481
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {

compiler/stable_mir/src/mir/visit.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,14 @@ pub trait MirVisitor {
391391
}
392392

393393
fn super_var_debug_info(&mut self, var_debug_info: &VarDebugInfo) {
394-
self.visit_span(&var_debug_info.source_info.span);
395-
let location = Location(var_debug_info.source_info.span);
396-
if let Some(composite) = &var_debug_info.composite {
394+
let VarDebugInfo { source_info, composite, value, name: _, argument_index: _ } =
395+
var_debug_info;
396+
self.visit_span(&source_info.span);
397+
let location = Location(source_info.span);
398+
if let Some(composite) = composite {
397399
self.visit_ty(&composite.ty, location);
398400
}
399-
match &var_debug_info.value {
401+
match value {
400402
VarDebugInfoContents::Place(place) => {
401403
self.visit_place(place, PlaceContext::NON_USE, location);
402404
}

0 commit comments

Comments
 (0)