X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir_ty%2Fsrc%2Fdisplay.rs;h=2ee4f5cf41bf351508ab8bf3143c1bd1f4bde481;hb=d1fc208c9ceb959d616fa790fca5d282bc8d820d;hp=cd898a45d214f79c93a3cb0fd95924a92e75606c;hpb=0add6e95e58633fde2fff0bccaf6c7d71ebc130f;p=rust.git diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index cd898a45d21..2ee4f5cf41b 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -151,6 +151,12 @@ pub fn write_joined( write!(self, "{}", sep)?; } first = false; + + // Abbreviate multiple omitted types with a single ellipsis. + if self.should_truncate() { + return write!(self, "{}", TYPE_HINT_TRUNCATION); + } + e.hir_fmt(self)?; } Ok(()) @@ -567,7 +573,27 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { }; if !parameters_to_write.is_empty() { write!(f, "<")?; - f.write_joined(parameters_to_write, ", ")?; + + if f.display_target.is_source_code() { + let mut first = true; + for generic_arg in parameters_to_write { + if !first { + write!(f, ", ")?; + } + first = false; + + if generic_arg.ty(Interner).map(|ty| ty.kind(Interner)) + == Some(&TyKind::Error) + { + write!(f, "_")?; + } else { + generic_arg.hir_fmt(f)?; + } + } + } else { + f.write_joined(parameters_to_write, ", ")?; + } + write!(f, ">")?; } } @@ -1068,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)?; + } } } }