Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/ra_hir_ty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 32 additions & 10 deletions crates/ra_hir_ty/src/traits/chalk/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
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};
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};

Expand Down Expand Up @@ -69,7 +70,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(())
Expand Down Expand Up @@ -113,14 +134,15 @@ impl DebugContext<'_> {
};
let trait_data = self.0.trait_data(trait_);
let params = alias.substitution.parameters(&Interner);
write!(
fmt,
"<{:?} as {}<{:?}>>::{}",
&params[0],
trait_data.name,
&params[1..],
type_alias_data.name
)
write!(fmt, "<{:?} as {}", &params[0], trait_data.name,)?;
if params.len() > 1 {
write!(
fmt,
"<{}>",
&params[1..].iter().format_with(", ", |x, f| f(&format_args!("{:?}", x))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that format and format_with are a thing. I wonder if that means that we should kill stdx::SepBy...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also just found them for this... don't actually remember how, maybe Chalk used them 🤔

)?;
}
write!(fmt, ">::{}", type_alias_data.name)
}

pub fn debug_ty(
Expand Down