Skip to content

Commit dedd888

Browse files
Implement HirDisplay for FnSig
This could be useful for diagnostics, but isn't used right now
1 parent 243ba33 commit dedd888

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

crates/hir_ty/src/display.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,7 @@ impl HirDisplay for ApplicationTy {
297297
}
298298
TypeCtor::FnPtr { is_varargs, .. } => {
299299
let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs);
300-
write!(f, "fn(")?;
301-
f.write_joined(sig.params(), ", ")?;
302-
if is_varargs {
303-
if sig.params().is_empty() {
304-
write!(f, "...")?;
305-
} else {
306-
write!(f, ", ...")?;
307-
}
308-
}
309-
write!(f, ")")?;
310-
let ret = sig.ret();
311-
if *ret != Ty::unit() {
312-
let ret_display = ret.into_displayable(
313-
f.db,
314-
f.max_size,
315-
f.omit_verbose_types,
316-
f.display_target,
317-
);
318-
write!(f, " -> {}", ret_display)?;
319-
}
300+
sig.hir_fmt(f)?;
320301
}
321302
TypeCtor::FnDef(def) => {
322303
let sig = f.db.callable_item_signature(def).subst(&self.parameters);
@@ -584,6 +565,28 @@ impl HirDisplay for Ty {
584565
}
585566
}
586567

568+
impl HirDisplay for FnSig {
569+
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
570+
write!(f, "fn(")?;
571+
f.write_joined(self.params(), ", ")?;
572+
if self.is_varargs {
573+
if self.params().is_empty() {
574+
write!(f, "...")?;
575+
} else {
576+
write!(f, ", ...")?;
577+
}
578+
}
579+
write!(f, ")")?;
580+
let ret = self.ret();
581+
if *ret != Ty::unit() {
582+
let ret_display =
583+
ret.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target);
584+
write!(f, " -> {}", ret_display)?;
585+
}
586+
Ok(())
587+
}
588+
}
589+
587590
fn write_bounds_like_dyn_trait(
588591
predicates: &[GenericPredicate],
589592
f: &mut HirFormatter,

0 commit comments

Comments
 (0)