X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir_ty%2Fsrc%2Fdisplay.rs;h=2ee4f5cf41bf351508ab8bf3143c1bd1f4bde481;hb=d1fc208c9ceb959d616fa790fca5d282bc8d820d;hp=4b077c2c8af2babd62863c063f5d33706ed8d322;hpb=3bba811e925e8eb5d53a58b7cb8a10fa29f71caa;p=rust.git diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 4b077c2c8af..2ee4f5cf41b 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -1095,17 +1095,17 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { write!(f, "]")?; } TypeRef::Fn(parameters, is_varargs) => { + // FIXME: Function pointer qualifiers. write!(f, "fn(")?; for index in 0..parameters.len() - 1 { let (param_name, param_type) = ¶meters[index]; - match param_name { - Some(name) => { - write!(f, "{}: ", name)?; - param_type.hir_fmt(f)?; - } - None => write!(f, " : {:?}", param_type)?, - }; + 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, ", ")?; } @@ -1114,12 +1114,13 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?; } write!(f, ")")?; - let ret_ty = ¶meters.last().unwrap().1; - 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)?; + } } } }