mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-23 04:57:37 +00:00
parameters.split_last()
This commit is contained in:
parent
d1fc208c9c
commit
9c6542f209
@ -1097,29 +1097,28 @@ impl HirDisplay for TypeRef {
|
|||||||
TypeRef::Fn(parameters, is_varargs) => {
|
TypeRef::Fn(parameters, is_varargs) => {
|
||||||
// FIXME: Function pointer qualifiers.
|
// FIXME: Function pointer qualifiers.
|
||||||
write!(f, "fn(")?;
|
write!(f, "fn(")?;
|
||||||
for index in 0..parameters.len() - 1 {
|
if let Some(((_, return_type), function_parameters)) = parameters.split_last() {
|
||||||
let (param_name, param_type) = ¶meters[index];
|
for index in 0..function_parameters.len() {
|
||||||
if let Some(name) = param_name {
|
let (param_name, param_type) = &function_parameters[index];
|
||||||
write!(f, "{}: ", name)?;
|
if let Some(name) = param_name {
|
||||||
}
|
write!(f, "{}: ", name)?;
|
||||||
|
}
|
||||||
|
|
||||||
param_type.hir_fmt(f)?;
|
param_type.hir_fmt(f)?;
|
||||||
|
|
||||||
// Last index contains the return type so we stop writing commas on the second-to-last index
|
if index != function_parameters.len() - 1 {
|
||||||
if index != parameters.len() - 2 {
|
write!(f, ", ")?;
|
||||||
write!(f, ", ")?;
|
}
|
||||||
}
|
}
|
||||||
}
|
if *is_varargs {
|
||||||
if *is_varargs {
|
write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?;
|
||||||
write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?;
|
}
|
||||||
}
|
write!(f, ")")?;
|
||||||
write!(f, ")")?;
|
match &return_type {
|
||||||
if let Some((_, ret_ty)) = ¶meters.last() {
|
|
||||||
match ret_ty {
|
|
||||||
TypeRef::Tuple(tup) if tup.is_empty() => {}
|
TypeRef::Tuple(tup) if tup.is_empty() => {}
|
||||||
_ => {
|
_ => {
|
||||||
write!(f, " -> ")?;
|
write!(f, " -> ")?;
|
||||||
ret_ty.hir_fmt(f)?;
|
return_type.hir_fmt(f)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user