This commit is contained in:
Jeroen Vannevel 2022-02-15 14:47:51 +00:00
parent c450d0ce41
commit 3bba811e92
No known key found for this signature in database
GPG key ID: 78EF5F52F38C49BD
2 changed files with 17 additions and 14 deletions

View file

@ -188,11 +188,18 @@ impl TypeRef {
is_varargs = param.dotdotdot_token().is_some(); is_varargs = param.dotdotdot_token().is_some();
} }
pl.params().map(|p| (p.pat(), p.ty())).map(|it| { pl.params()
let type_ref = TypeRef::from_ast_opt(ctx, it.1); .map(|p| (p.pat(), p.ty()))
let name = if it.0.is_some() { Some(it.0.unwrap().syntax().text().to_string()) } else { None }; .map(|it| {
(name, type_ref) let type_ref = TypeRef::from_ast_opt(ctx, it.1);
}).collect() let name = if it.0.is_some() {
Some(it.0.unwrap().syntax().text().to_string())
} else {
None
};
(name, type_ref)
})
.collect()
} else { } else {
Vec::new() Vec::new()
}; };
@ -234,12 +241,8 @@ impl TypeRef {
fn go(type_ref: &TypeRef, f: &mut impl FnMut(&TypeRef)) { fn go(type_ref: &TypeRef, f: &mut impl FnMut(&TypeRef)) {
f(type_ref); f(type_ref);
match type_ref { match type_ref {
TypeRef::Fn(types, _) => { TypeRef::Fn(types, _) => types.iter().for_each(|t| go(&t.1, f)),
types.iter().for_each(|t| go(&t.1, f)) TypeRef::Tuple(types) => types.iter().for_each(|t| go(t, f)),
}
TypeRef::Tuple(types) => {
types.iter().for_each(|t| go(t, f))
}
TypeRef::RawPtr(type_ref, _) TypeRef::RawPtr(type_ref, _)
| TypeRef::Reference(type_ref, ..) | TypeRef::Reference(type_ref, ..)
| TypeRef::Array(type_ref, _) | TypeRef::Array(type_ref, _)

View file

@ -340,7 +340,7 @@ impl HirDisplay for Ty {
if f.should_truncate() { if f.should_truncate() {
return write!(f, "{}", TYPE_HINT_TRUNCATION); return write!(f, "{}", TYPE_HINT_TRUNCATION);
} }
match self.kind(Interner) { match self.kind(Interner) {
TyKind::Never => write!(f, "!")?, TyKind::Never => write!(f, "!")?,
TyKind::Str => write!(f, "str")?, TyKind::Str => write!(f, "str")?,
@ -1097,12 +1097,12 @@ impl HirDisplay for TypeRef {
TypeRef::Fn(parameters, is_varargs) => { TypeRef::Fn(parameters, is_varargs) => {
write!(f, "fn(")?; write!(f, "fn(")?;
for index in 0..parameters.len() - 1 { for index in 0..parameters.len() - 1 {
let (param_name,param_type) = &parameters[index]; let (param_name, param_type) = &parameters[index];
match param_name { match param_name {
Some(name) => { Some(name) => {
write!(f, "{}: ", name)?; write!(f, "{}: ", name)?;
param_type.hir_fmt(f)?; param_type.hir_fmt(f)?;
}, }
None => write!(f, " : {:?}", param_type)?, None => write!(f, " : {:?}", param_type)?,
}; };