Unnamed repository; edit this file 'description' to name the repository.
fix: implement ir_print debug for next-solver predicate types
seven IrPrint::print_debug implementations in the next-solver were placeholder stubs that returned "TODO: <typename>" instead of meaningful output. these are called via the Display impl (and Debug for PatternKind) of these types, so any solver trace log containing them was unreadable. implemented proper formatting for each: - TraitPredicate -> "T: Trait" / "!T: Trait" - HostEffectPredicate -> "const T: Trait" / "[const] T: Trait" - NormalizesTo -> "AliasTerm(...) -> Term" - SubtypePredicate -> "A <: B" - CoercePredicate -> "A -> B" - FnSig -> "fn([inputs]) -> output" - PatternKind -> "start..=end" / "or([...])" / "!null" also removed the now-unused type_name_of_val import.
Albab-Hasan 2 months ago
parent a1b86d6 · commit d0c13b8
-rw-r--r--crates/hir-ty/src/next_solver/ir_print.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/crates/hir-ty/src/next_solver/ir_print.rs b/crates/hir-ty/src/next_solver/ir_print.rs
index 998aab5a3f..8569b828ae 100644
--- a/crates/hir-ty/src/next_solver/ir_print.rs
+++ b/crates/hir-ty/src/next_solver/ir_print.rs
@@ -1,7 +1,5 @@
//! Things related to IR printing in the next-trait-solver.
-use std::any::type_name_of_val;
-
use rustc_type_ir::{self as ty, ir_print::IrPrint};
use super::SolverDefId;
@@ -82,7 +80,10 @@ impl<'db> IrPrint<ty::TraitPredicate<Self>> for DbInterner<'db> {
t: &ty::TraitPredicate<Self>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ match t.polarity {
+ ty::PredicatePolarity::Positive => write!(fmt, "{:?}", t.trait_ref),
+ ty::PredicatePolarity::Negative => write!(fmt, "!{:?}", t.trait_ref),
+ }
}
}
impl<'db> IrPrint<rustc_type_ir::HostEffectPredicate<Self>> for DbInterner<'db> {
@@ -97,7 +98,11 @@ impl<'db> IrPrint<rustc_type_ir::HostEffectPredicate<Self>> for DbInterner<'db>
t: &rustc_type_ir::HostEffectPredicate<Self>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ let prefix = match t.constness {
+ ty::BoundConstness::Const => "const",
+ ty::BoundConstness::Maybe => "[const]",
+ };
+ write!(fmt, "{prefix} {:?}", t.trait_ref)
}
}
impl<'db> IrPrint<ty::ExistentialTraitRef<Self>> for DbInterner<'db> {
@@ -183,7 +188,7 @@ impl<'db> IrPrint<ty::NormalizesTo<Self>> for DbInterner<'db> {
t: &ty::NormalizesTo<Self>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ write!(fmt, "{} -> {:?}", t.alias, t.term)
}
}
impl<'db> IrPrint<ty::SubtypePredicate<Self>> for DbInterner<'db> {
@@ -198,7 +203,7 @@ impl<'db> IrPrint<ty::SubtypePredicate<Self>> for DbInterner<'db> {
t: &ty::SubtypePredicate<Self>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ write!(fmt, "{:?} <: {:?}", t.a, t.b)
}
}
impl<'db> IrPrint<ty::CoercePredicate<Self>> for DbInterner<'db> {
@@ -210,7 +215,7 @@ impl<'db> IrPrint<ty::CoercePredicate<Self>> for DbInterner<'db> {
t: &ty::CoercePredicate<Self>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ write!(fmt, "{:?} -> {:?}", t.a, t.b)
}
}
impl<'db> IrPrint<ty::FnSig<Self>> for DbInterner<'db> {
@@ -219,7 +224,9 @@ impl<'db> IrPrint<ty::FnSig<Self>> for DbInterner<'db> {
}
fn print_debug(t: &ty::FnSig<Self>, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ let tys = t.inputs_and_output.as_slice();
+ let (output, inputs) = tys.split_last().unwrap();
+ write!(fmt, "fn({:?}) -> {:?}", inputs, output)
}
}
@@ -235,6 +242,10 @@ impl<'db> IrPrint<rustc_type_ir::PatternKind<DbInterner<'db>>> for DbInterner<'d
t: &rustc_type_ir::PatternKind<DbInterner<'db>>,
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
- fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
+ match t {
+ ty::PatternKind::Range { start, end } => write!(fmt, "{:?}..={:?}", start, end),
+ ty::PatternKind::Or(list) => write!(fmt, "or({:?})", list),
+ ty::PatternKind::NotNull => fmt.write_str("!null"),
+ }
}
}