diff options
author | bors <bors@rust-lang.org> | 2023-05-17 03:37:54 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2023-05-17 03:37:54 +0000 |
commit | 6c64870fa67f0227f40f6adc25a6944e95c2959f (patch) | |
tree | e6be882190a0f88a8e3d3ba28cc2badb1746d393 /compiler/rustc_middle/src/ty/structural_impls.rs | |
parent | c0784db3deddfb09f52c65373ef50b14d82494cc (diff) | |
parent | 2a554eb40677a659092c5b95a52821275924c4bf (diff) | |
download | rust-6c64870fa67f0227f40f6adc25a6944e95c2959f.tar.gz |
Auto merge of #111630 - BoxyUwU:ty_const_debug_formatting, r=compiler-errors
debug format `Const`'s less verbosely
Not user visible change only visible to people debugging const generics.
Currently debug output for `ty::Const` is super verbose (even for `-Zverbose` lol), things like printing infer vars as `Infer(Var(?0c))` instead of just `?0c`, bound vars and placeholders not using `^0_1` or `!0_1` syntax respectively. With these changes its imo better but not perfect:
`Const { ty: usize, kind: ^0_1 }`
is still a lot for not much information. not entirely sure what to do about that so not dealing with it yet.
Need to do formatting for `ConstKind::Expr` at some point too since rn it sucks (doesn't even print anything with `Display`) not gonna do that in this PR either.
r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_middle/src/ty/structural_impls.rs')
-rw-r--r-- | compiler/rustc_middle/src/ty/structural_impls.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index e73208b877f..16cb6c91046 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -192,6 +192,44 @@ impl<'tcx> fmt::Debug for AliasTy<'tcx> { } } +impl<'tcx> fmt::Debug for ty::InferConst<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + InferConst::Var(var) => write!(f, "{var:?}"), + InferConst::Fresh(var) => write!(f, "Fresh({var:?})"), + } + } +} + +impl<'tcx> fmt::Debug for ty::Const<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // This reflects what `Const` looked liked before `Interned` was + // introduced. We print it like this to avoid having to update expected + // output in a lot of tests. + write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty(), self.kind()) + } +} + +impl<'tcx> fmt::Debug for ty::ConstKind<'tcx> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use ty::ConstKind::*; + match self { + Param(param) => write!(f, "{param:?}"), + Infer(var) => write!(f, "{var:?}"), + Bound(debruijn, var) => ty::print::debug_bound_var(f, *debruijn, *var), + Placeholder(placeholder) => { + ty::print::debug_placeholder_var(f, placeholder.universe, placeholder.bound) + } + Unevaluated(uv) => { + f.debug_tuple("Unevaluated").field(&uv.substs).field(&uv.def).finish() + } + Value(valtree) => write!(f, "{valtree:?}"), + Error(_) => write!(f, "[const error]"), + Expr(expr) => write!(f, "{expr:?}"), + } + } +} + /////////////////////////////////////////////////////////////////////////// // Atomic structs // |