From dedd88857045838265f89788aeaf610e07c77661 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 9 Dec 2020 18:06:56 +0100 Subject: Implement HirDisplay for FnSig This could be useful for diagnostics, but isn't used right now --- crates/hir_ty/src/display.rs | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 14e8c0633..e77481906 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -297,26 +297,7 @@ impl HirDisplay for ApplicationTy { } TypeCtor::FnPtr { is_varargs, .. } => { let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs); - write!(f, "fn(")?; - 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)?; - } + sig.hir_fmt(f)?; } TypeCtor::FnDef(def) => { 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( predicates: &[GenericPredicate], f: &mut HirFormatter, -- cgit v1.2.3