Skip to content

Commit 2a5380a

Browse files
committed
de-structure variable and add stables
1 parent 6a73ad5 commit 2a5380a

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
@@ -326,35 +326,9 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> {
326326
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
327327
stable_mir::mir::VarDebugInfo {
328328
name: self.name.to_string(),
329-
source_info: stable_mir::mir::SourceInfo {
330-
span: self.source_info.span.stable(tables),
331-
scope: self.source_info.scope.into(),
332-
},
333-
composite: {
334-
if let Some(composite) = &self.composite {
335-
Some(VarDebugInfoFragment {
336-
ty: composite.ty.stable(tables),
337-
projection: composite.projection.iter().map(|e| e.stable(tables)).collect(),
338-
})
339-
} else {
340-
None
341-
}
342-
},
343-
value: {
344-
match self.value {
345-
mir::VarDebugInfoContents::Place(place) => {
346-
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
347-
}
348-
mir::VarDebugInfoContents::Const(const_operand) => {
349-
let op = ConstOperand {
350-
span: const_operand.span.stable(tables),
351-
user_ty: const_operand.user_ty.map(|index| index.as_usize()),
352-
const_: const_operand.const_.stable(tables),
353-
};
354-
stable_mir::mir::VarDebugInfoContents::Const(op)
355-
}
356-
}
357-
},
329+
source_info: self.source_info.stable(tables),
330+
composite: self.composite.as_ref().map(|composite| composite.stable(tables)),
331+
value: self.value.stable(tables),
358332
argument_index: self.argument_index,
359333
}
360334
}
@@ -367,6 +341,42 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
367341
}
368342
}
369343

344+
impl<'tcx> Stable<'tcx> for mir::SourceInfo {
345+
type T = stable_mir::mir::SourceInfo;
346+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
347+
stable_mir::mir::SourceInfo { span: self.span.stable(tables), scope: self.scope.into() }
348+
}
349+
}
350+
351+
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> {
352+
type T = stable_mir::mir::VarDebugInfoFragment;
353+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
354+
VarDebugInfoFragment {
355+
ty: self.ty.stable(tables),
356+
projection: self.projection.iter().map(|e| e.stable(tables)).collect(),
357+
}
358+
}
359+
}
360+
361+
impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> {
362+
type T = stable_mir::mir::VarDebugInfoContents;
363+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
364+
match self {
365+
mir::VarDebugInfoContents::Place(place) => {
366+
stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables))
367+
}
368+
mir::VarDebugInfoContents::Const(const_operand) => {
369+
let op = ConstOperand {
370+
span: const_operand.span.stable(tables),
371+
user_ty: const_operand.user_ty.map(|index| index.as_usize()),
372+
const_: const_operand.const_.stable(tables),
373+
};
374+
stable_mir::mir::VarDebugInfoContents::Const(op)
375+
}
376+
}
377+
}
378+
}
379+
370380
impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {
371381
type T = stable_mir::mir::StatementKind;
372382
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)