Skip to content

Commit a0eb348

Browse files
committed
Specialize DestructuredConstant to its one user (pretty printing)
1 parent 4dcf988 commit a0eb348

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
115115
.map(|i| {
116116
let field_op = ecx.operand_field(&down, i)?;
117117
let val = op_to_const(&ecx, &field_op);
118-
Ok(mir::ConstantKind::Val(val, field_op.layout.ty))
118+
Ok((val, field_op.layout.ty))
119119
})
120120
.collect::<InterpResult<'tcx, Vec<_>>>()?;
121121
let fields = tcx.arena.alloc_from_iter(fields_iter);

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,13 +2806,16 @@ fn pretty_print_byte_str(fmt: &mut Formatter<'_>, byte_str: &[u8]) -> fmt::Resul
28062806
write!(fmt, "b\"{}\"", byte_str.escape_ascii())
28072807
}
28082808

2809-
fn comma_sep<'tcx>(fmt: &mut Formatter<'_>, elems: Vec<ConstantKind<'tcx>>) -> fmt::Result {
2809+
fn comma_sep<'tcx>(
2810+
fmt: &mut Formatter<'_>,
2811+
elems: Vec<(ConstValue<'tcx>, Ty<'tcx>)>,
2812+
) -> fmt::Result {
28102813
let mut first = true;
2811-
for elem in elems {
2814+
for (ct, ty) in elems {
28122815
if !first {
28132816
fmt.write_str(", ")?;
28142817
}
2815-
fmt.write_str(&format!("{}", elem))?;
2818+
pretty_print_const_value(ct, ty, fmt, true)?;
28162819
first = false;
28172820
}
28182821
Ok(())
@@ -2925,12 +2928,14 @@ fn pretty_print_const_value<'tcx>(
29252928
None => {
29262929
fmt.write_str(" {{ ")?;
29272930
let mut first = true;
2928-
for (field_def, field) in iter::zip(&variant_def.fields, fields)
2931+
for (field_def, (ct, ty)) in
2932+
iter::zip(&variant_def.fields, fields)
29292933
{
29302934
if !first {
29312935
fmt.write_str(", ")?;
29322936
}
2933-
fmt.write_str(&format!("{}: {}", field_def.name, field))?;
2937+
write!(fmt, "{}: ", field_def.name)?;
2938+
pretty_print_const_value(ct, ty, fmt, true)?;
29342939
first = false;
29352940
}
29362941
fmt.write_str(" }}")?;

compiler/rustc_middle/src/mir/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Values computed by queries that use MIR.
22
3-
use crate::mir::ConstantKind;
3+
use crate::mir::interpret::ConstValue;
44
use crate::ty::{self, OpaqueHiddenType, Ty, TyCtxt};
55
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_data_structures::unord::UnordSet;
@@ -444,7 +444,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
444444
#[derive(Copy, Clone, Debug, HashStable)]
445445
pub struct DestructuredConstant<'tcx> {
446446
pub variant: Option<VariantIdx>,
447-
pub fields: &'tcx [ConstantKind<'tcx>],
447+
pub fields: &'tcx [(ConstValue<'tcx>, Ty<'tcx>)],
448448
}
449449

450450
/// Coverage information summarized from a MIR if instrumented for source code coverage (see

0 commit comments

Comments
 (0)