Nicer display of projections in Chalk logs

This commit is contained in:
Florian Diebold 2020-04-13 14:39:44 +02:00
parent 7886513f89
commit 2e7b88b525
3 changed files with 12 additions and 8 deletions

1
Cargo.lock generated
View file

@ -1013,6 +1013,7 @@ dependencies = [
"chalk-solve", "chalk-solve",
"ena", "ena",
"insta", "insta",
"itertools",
"log", "log",
"ra_arena", "ra_arena",
"ra_db", "ra_db",

View file

@ -8,6 +8,7 @@ authors = ["rust-analyzer developers"]
doctest = false doctest = false
[dependencies] [dependencies]
itertools = "0.9.0"
arrayvec = "0.5.1" arrayvec = "0.5.1"
smallvec = "1.2.0" smallvec = "1.2.0"
ena = "0.13.1" ena = "0.13.1"

View file

@ -2,6 +2,7 @@
use std::fmt; use std::fmt;
use chalk_ir::{AliasTy, Goal, Goals, Lifetime, Parameter, ProgramClauseImplication, TypeName}; use chalk_ir::{AliasTy, Goal, Goals, Lifetime, Parameter, ProgramClauseImplication, TypeName};
use itertools::Itertools;
use super::{from_chalk, Interner}; use super::{from_chalk, Interner};
use crate::{db::HirDatabase, CallableDef, TypeCtor}; use crate::{db::HirDatabase, CallableDef, TypeCtor};
@ -133,14 +134,15 @@ impl DebugContext<'_> {
}; };
let trait_data = self.0.trait_data(trait_); let trait_data = self.0.trait_data(trait_);
let params = alias.substitution.parameters(&Interner); let params = alias.substitution.parameters(&Interner);
write!( write!(fmt, "<{:?} as {}", &params[0], trait_data.name,)?;
fmt, if params.len() > 1 {
"<{:?} as {}<{:?}>>::{}", write!(
&params[0], fmt,
trait_data.name, "<{}>",
&params[1..], &params[1..].iter().format_with(", ", |x, f| f(&format_args!("{:?}", x))),
type_alias_data.name )?;
) }
write!(fmt, ">::{}", type_alias_data.name)
} }
pub fn debug_ty( pub fn debug_ty(