Implement HirDisplay for FnSig

This could be useful for diagnostics, but isn't used right now
This commit is contained in:
Jonas Schievink 2020-12-09 18:06:56 +01:00
parent 243ba330dd
commit dedd888570

View file

@ -297,26 +297,7 @@ impl HirDisplay for ApplicationTy {
} }
TypeCtor::FnPtr { is_varargs, .. } => { TypeCtor::FnPtr { is_varargs, .. } => {
let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs); let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs);
write!(f, "fn(")?; sig.hir_fmt(f)?;
f.write_joined(sig.params(), ", ")?;
if is_varargs {
if sig.params().is_empty() {
write!(f, "...")?;
} else {
write!(f, ", ...")?;
}
}
write!(f, ")")?;
let ret = sig.ret();
if *ret != Ty::unit() {
let ret_display = ret.into_displayable(
f.db,
f.max_size,
f.omit_verbose_types,
f.display_target,
);
write!(f, " -> {}", ret_display)?;
}
} }
TypeCtor::FnDef(def) => { TypeCtor::FnDef(def) => {
let sig = f.db.callable_item_signature(def).subst(&self.parameters); let sig = f.db.callable_item_signature(def).subst(&self.parameters);
@ -584,6 +565,28 @@ impl HirDisplay for Ty {
} }
} }
impl HirDisplay for FnSig {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
write!(f, "fn(")?;
f.write_joined(self.params(), ", ")?;
if self.is_varargs {
if self.params().is_empty() {
write!(f, "...")?;
} else {
write!(f, ", ...")?;
}
}
write!(f, ")")?;
let ret = self.ret();
if *ret != Ty::unit() {
let ret_display =
ret.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target);
write!(f, " -> {}", ret_display)?;
}
Ok(())
}
}
fn write_bounds_like_dyn_trait( fn write_bounds_like_dyn_trait(
predicates: &[GenericPredicate], predicates: &[GenericPredicate],
f: &mut HirFormatter, f: &mut HirFormatter,