Specialize DestructuredConstant
to its one user (pretty printing)
This commit is contained in:
parent
4dcf988360
commit
a0eb348d38
3 changed files with 13 additions and 8 deletions
|
@ -115,7 +115,7 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
|
|||
.map(|i| {
|
||||
let field_op = ecx.operand_field(&down, i)?;
|
||||
let val = op_to_const(&ecx, &field_op);
|
||||
Ok(mir::ConstantKind::Val(val, field_op.layout.ty))
|
||||
Ok((val, field_op.layout.ty))
|
||||
})
|
||||
.collect::<InterpResult<'tcx, Vec<_>>>()?;
|
||||
let fields = tcx.arena.alloc_from_iter(fields_iter);
|
||||
|
|
|
@ -2806,13 +2806,16 @@ fn pretty_print_byte_str(fmt: &mut Formatter<'_>, byte_str: &[u8]) -> fmt::Resul
|
|||
write!(fmt, "b\"{}\"", byte_str.escape_ascii())
|
||||
}
|
||||
|
||||
fn comma_sep<'tcx>(fmt: &mut Formatter<'_>, elems: Vec<ConstantKind<'tcx>>) -> fmt::Result {
|
||||
fn comma_sep<'tcx>(
|
||||
fmt: &mut Formatter<'_>,
|
||||
elems: Vec<(ConstValue<'tcx>, Ty<'tcx>)>,
|
||||
) -> fmt::Result {
|
||||
let mut first = true;
|
||||
for elem in elems {
|
||||
for (ct, ty) in elems {
|
||||
if !first {
|
||||
fmt.write_str(", ")?;
|
||||
}
|
||||
fmt.write_str(&format!("{}", elem))?;
|
||||
pretty_print_const_value(ct, ty, fmt, true)?;
|
||||
first = false;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -2925,12 +2928,14 @@ fn pretty_print_const_value<'tcx>(
|
|||
None => {
|
||||
fmt.write_str(" {{ ")?;
|
||||
let mut first = true;
|
||||
for (field_def, field) in iter::zip(&variant_def.fields, fields)
|
||||
for (field_def, (ct, ty)) in
|
||||
iter::zip(&variant_def.fields, fields)
|
||||
{
|
||||
if !first {
|
||||
fmt.write_str(", ")?;
|
||||
}
|
||||
fmt.write_str(&format!("{}: {}", field_def.name, field))?;
|
||||
write!(fmt, "{}: ", field_def.name)?;
|
||||
pretty_print_const_value(ct, ty, fmt, true)?;
|
||||
first = false;
|
||||
}
|
||||
fmt.write_str(" }}")?;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Values computed by queries that use MIR.
|
||||
|
||||
use crate::mir::ConstantKind;
|
||||
use crate::mir::interpret::ConstValue;
|
||||
use crate::ty::{self, OpaqueHiddenType, Ty, TyCtxt};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
|
@ -444,7 +444,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
|
|||
#[derive(Copy, Clone, Debug, HashStable)]
|
||||
pub struct DestructuredConstant<'tcx> {
|
||||
pub variant: Option<VariantIdx>,
|
||||
pub fields: &'tcx [ConstantKind<'tcx>],
|
||||
pub fields: &'tcx [(ConstValue<'tcx>, Ty<'tcx>)],
|
||||
}
|
||||
|
||||
/// Coverage information summarized from a MIR if instrumented for source code coverage (see
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue