From 7886513f89795e06eef258e0c54dbd1224c98317 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 10 Apr 2020 22:05:31 +0200 Subject: [PATCH 1/2] Nicer display of closures in Chalk logs --- crates/ra_hir_ty/src/traits/chalk/tls.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index d9bbb54a5bc5..0a8932dae09c 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -5,7 +5,7 @@ use chalk_ir::{AliasTy, Goal, Goals, Lifetime, Parameter, ProgramClauseImplicati use super::{from_chalk, Interner}; use crate::{db::HirDatabase, CallableDef, TypeCtor}; -use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId}; +use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; pub use unsafe_tls::{set_current_program, with_current_program}; @@ -69,7 +69,27 @@ impl DebugContext<'_> { write!(f, "{}::{}", trait_name, name)?; } TypeCtor::Closure { def, expr } => { - write!(f, "{{closure {:?} in {:?}}}", expr.into_raw(), def)?; + write!(f, "{{closure {:?} in ", expr.into_raw())?; + match def { + DefWithBodyId::FunctionId(func) => { + write!(f, "fn {}", self.0.function_data(func).name)? + } + DefWithBodyId::StaticId(s) => { + if let Some(name) = self.0.static_data(s).name.as_ref() { + write!(f, "body of static {}", name)?; + } else { + write!(f, "body of unnamed static {:?}", s)?; + } + } + DefWithBodyId::ConstId(c) => { + if let Some(name) = self.0.const_data(c).name.as_ref() { + write!(f, "body of const {}", name)?; + } else { + write!(f, "body of unnamed const {:?}", c)?; + } + } + }; + write!(f, "}}")?; } } Ok(()) From 2e7b88b5256bd6c51226b63b93481a77ac901e14 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 13 Apr 2020 14:39:44 +0200 Subject: [PATCH 2/2] Nicer display of projections in Chalk logs --- Cargo.lock | 1 + crates/ra_hir_ty/Cargo.toml | 1 + crates/ra_hir_ty/src/traits/chalk/tls.rs | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 975c1aef8683..c2779afc2b4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1013,6 +1013,7 @@ dependencies = [ "chalk-solve", "ena", "insta", + "itertools", "log", "ra_arena", "ra_db", diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 59efc1c31d8c..c863112c0f3f 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -8,6 +8,7 @@ authors = ["rust-analyzer developers"] doctest = false [dependencies] +itertools = "0.9.0" arrayvec = "0.5.1" smallvec = "1.2.0" ena = "0.13.1" diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index 0a8932dae09c..fa8e4d1ad182 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -2,6 +2,7 @@ use std::fmt; use chalk_ir::{AliasTy, Goal, Goals, Lifetime, Parameter, ProgramClauseImplication, TypeName}; +use itertools::Itertools; use super::{from_chalk, Interner}; use crate::{db::HirDatabase, CallableDef, TypeCtor}; @@ -133,14 +134,15 @@ impl DebugContext<'_> { }; let trait_data = self.0.trait_data(trait_); let params = alias.substitution.parameters(&Interner); - write!( - fmt, - "<{:?} as {}<{:?}>>::{}", - ¶ms[0], - trait_data.name, - ¶ms[1..], - type_alias_data.name - ) + write!(fmt, "<{:?} as {}", ¶ms[0], trait_data.name,)?; + if params.len() > 1 { + write!( + fmt, + "<{}>", + ¶ms[1..].iter().format_with(", ", |x, f| f(&format_args!("{:?}", x))), + )?; + } + write!(fmt, ">::{}", type_alias_data.name) } pub fn debug_ty(