1
Fork 0

Rollup merge of #96581 - RalfJung:debug-size-align, r=oli-obk

make Size and Align debug-printing a bit more compact

In particular in `{:#?}`-mode, these take up a lot of space, so I think this is the better alternative (even though it is a bit longer in `{:?}` mode, I think it is still more readable).

We could make it even smaller by deviating further from what the actual code looks like, e.g. via something like `Size(4 bytes)`. Not sure what people would think about that?

Cc `````@oli-obk`````
This commit is contained in:
Guillaume Gomez 2022-05-07 15:23:44 +02:00 committed by GitHub
commit c29f8575ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 244 additions and 555 deletions

View file

@ -448,6 +448,12 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
self.push(&format!("+ user_ty: {:?}", user_ty));
}
let fmt_val = |val: &ConstValue<'tcx>| match val {
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
ConstValue::Slice { .. } => format!("Slice(..)"),
ConstValue::ByRef { .. } => format!("ByRef(..)"),
};
let val = match literal {
ConstantKind::Ty(ct) => match ct.val() {
ty::ConstKind::Param(p) => format!("Param({})", p),
@ -457,7 +463,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
uv.substs,
uv.promoted,
),
ty::ConstKind::Value(val) => format!("Value({:?})", val),
ty::ConstKind::Value(val) => format!("Value({})", fmt_val(&val)),
ty::ConstKind::Error(_) => "Error".to_string(),
// These variants shouldn't exist in the MIR.
ty::ConstKind::Placeholder(_)
@ -467,7 +473,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
// To keep the diffs small, we render this like we render `ty::Const::Value`.
//
// This changes once `ty::Const::Value` is represented using valtrees.
ConstantKind::Val(val, _) => format!("Value({:?})", val),
ConstantKind::Val(val, _) => format!("Value({})", fmt_val(&val)),
};
self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), val));