Implement Chalk's debug methods using TLS

Chalk now panics if we don't implement these methods and run with CHALK_DEBUG,
so I thought I'd try to implement them 'properly'. Sadly, it seems impossible to
do without transmuting lifetimes somewhere. The problem is that we need a `&dyn
HirDatabase` to get names etc., which we can't just put into TLS. I thought I
could just use `scoped-tls`, but that doesn't support references to unsized
types. So I put the `&dyn` into another struct and put the reference to *that*
into the TLS, but I have to transmute the lifetime to 'static for that to work.
This commit is contained in:
Florian Diebold 2020-03-27 18:56:18 +01:00 committed by Florian Diebold
parent 176f7f6117
commit a0a80a4103
6 changed files with 304 additions and 56 deletions

View file

@ -247,19 +247,21 @@ impl HirDisplay for ApplicationTy {
}
}
TypeCtor::Closure { .. } => {
let sig = self.parameters[0]
.callable_sig(f.db)
.expect("first closure parameter should contain signature");
if sig.params().is_empty() {
write!(f, "||")?;
} else if f.omit_verbose_types() {
write!(f, "|{}|", TYPE_HINT_TRUNCATION)?;
let sig = self.parameters[0].callable_sig(f.db);
if let Some(sig) = sig {
if sig.params().is_empty() {
write!(f, "||")?;
} else if f.omit_verbose_types() {
write!(f, "|{}|", TYPE_HINT_TRUNCATION)?;
} else {
write!(f, "|")?;
f.write_joined(sig.params(), ", ")?;
write!(f, "|")?;
};
write!(f, " -> {}", sig.ret().display(f.db))?;
} else {
write!(f, "|")?;
f.write_joined(sig.params(), ", ")?;
write!(f, "|")?;
};
write!(f, " -> {}", sig.ret().display(f.db))?;
write!(f, "{{closure}}")?;
}
}
}
Ok(())