Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r--crates/hir_ty/src/display.rs36
1 files changed, 24 insertions, 12 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index f02f4ac024..0e75ddeabc 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -1094,20 +1094,32 @@ impl HirDisplay for TypeRef {
inner.hir_fmt(f)?;
write!(f, "]")?;
}
- TypeRef::Fn(tys, is_varargs) => {
+ TypeRef::Fn(parameters, is_varargs) => {
// FIXME: Function pointer qualifiers.
write!(f, "fn(")?;
- f.write_joined(&tys[..tys.len() - 1], ", ")?;
- if *is_varargs {
- write!(f, "{}...", if tys.len() == 1 { "" } else { ", " })?;
- }
- write!(f, ")")?;
- let ret_ty = tys.last().unwrap();
- match ret_ty {
- TypeRef::Tuple(tup) if tup.is_empty() => {}
- _ => {
- write!(f, " -> ")?;
- ret_ty.hir_fmt(f)?;
+ if let Some(((_, return_type), function_parameters)) = parameters.split_last() {
+ for index in 0..function_parameters.len() {
+ let (param_name, param_type) = &function_parameters[index];
+ if let Some(name) = param_name {
+ write!(f, "{}: ", name)?;
+ }
+
+ param_type.hir_fmt(f)?;
+
+ if index != function_parameters.len() - 1 {
+ write!(f, ", ")?;
+ }
+ }
+ if *is_varargs {
+ write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?;
+ }
+ write!(f, ")")?;
+ match &return_type {
+ TypeRef::Tuple(tup) if tup.is_empty() => {}
+ _ => {
+ write!(f, " -> ")?;
+ return_type.hir_fmt(f)?;
+ }
}
}
}