X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir_ty%2Fsrc%2Fdisplay.rs;h=2ee4f5cf41bf351508ab8bf3143c1bd1f4bde481;hb=d1fc208c9ceb959d616fa790fca5d282bc8d820d;hp=f02f4ac02478c8962b8ec3ccb3faa70067b7eaf0;hpb=0808ade4e43157f96ddaca8fa39f436038c3ede0;p=rust.git diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index f02f4ac0247..2ee4f5cf41b 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -1094,20 +1094,33 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 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], ", ")?; + for index in 0..parameters.len() - 1 { + let (param_name, param_type) = ¶meters[index]; + if let Some(name) = param_name { + write!(f, "{}: ", name)?; + } + + param_type.hir_fmt(f)?; + + // Last index contains the return type so we stop writing commas on the second-to-last index + if index != parameters.len() - 2 { + write!(f, ", ")?; + } + } if *is_varargs { - write!(f, "{}...", if tys.len() == 1 { "" } else { ", " })?; + write!(f, "{}...", if parameters.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((_, ret_ty)) = ¶meters.last() { + match ret_ty { + TypeRef::Tuple(tup) if tup.is_empty() => {} + _ => { + write!(f, " -> ")?; + ret_ty.hir_fmt(f)?; + } } } }