Skip to content

Commit d0dd19a

Browse files
committed
de-structure variable and add stables
1 parent 018b859 commit d0dd19a

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
@@ -457,35 +457,9 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> {
457457
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
458458
stable_mir::mir::VarDebugInfo {
459459
name: self.name.to_string(),
460-
source_info: stable_mir::mir::SourceInfo {
461-
span: self.source_info.span.stable(tables),
462-
scope: self.source_info.scope.into(),
463-
},
464-
composite: {
465-
if let Some(composite) = &self.composite {
466-
Some(VarDebugInfoFragment {
467-
ty: composite.ty.stable(tables),
468-
projection: composite.projection.iter().map(|e| e.stable(tables)).collect(),
469-
})
470-
} else {
471-
None
472-
}
473-
},
474-
value: {
475-
match self.value {
476-
mir::VarDebugInfoContents::Place(place) => {
477-
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
478-
}
479-
mir::VarDebugInfoContents::Const(const_operand) => {
480-
let op = ConstOperand {
481-
span: const_operand.span.stable(tables),
482-
user_ty: const_operand.user_ty.map(|index| index.as_usize()),
483-
const_: const_operand.const_.stable(tables),
484-
};
485-
stable_mir::mir::VarDebugInfoContents::Const(op)
486-
}
487-
}
488-
},
460+
source_info: self.source_info.stable(tables),
461+
composite: self.composite.as_ref().map(|composite| composite.stable(tables)),
462+
value: self.value.stable(tables),
489463
argument_index: self.argument_index,
490464
}
491465
}
@@ -498,6 +472,42 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
498472
}
499473
}
500474

475+
impl<'tcx> Stable<'tcx> for mir::SourceInfo {
476+
type T = stable_mir::mir::SourceInfo;
477+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
478+
stable_mir::mir::SourceInfo { span: self.span.stable(tables), scope: self.scope.into() }
479+
}
480+
}
481+
482+
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> {
483+
type T = stable_mir::mir::VarDebugInfoFragment;
484+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
485+
VarDebugInfoFragment {
486+
ty: self.ty.stable(tables),
487+
projection: self.projection.iter().map(|e| e.stable(tables)).collect(),
488+
}
489+
}
490+
}
491+
492+
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> {
493+
type T = stable_mir::mir::VarDebugInfoContents;
494+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
495+
match self {
496+
mir::VarDebugInfoContents::Place(place) => {
497+
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
498+
}
499+
mir::VarDebugInfoContents::Const(const_operand) => {
500+
let op = ConstOperand {
501+
span: const_operand.span.stable(tables),
502+
user_ty: const_operand.user_ty.map(|index| index.as_usize()),
503+
const_: const_operand.const_.stable(tables),
504+
};
505+
stable_mir::mir::VarDebugInfoContents::Const(op)
506+
}
507+
}
508+
}
509+
}
510+
501511
impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {
502512
type T = stable_mir::mir::StatementKind;
503513
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)