Skip to content

Commit baa4fa0

Browse files
committed
Add fallback for return type
1 parent fae9049 commit baa4fa0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crates/ide/src/signature_help.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ fn signature_help_for_call(
149149
}
150150
// APITs (argument position `impl Trait`s) are inferred as {unknown} as the user is
151151
// in the middle of entering call arguments.
152-
// In that case, fall back to render definition of the argument.
152+
// In that case, fall back to render definitions of the respective parameters.
153153
// This is overly conservative: we do not substitute known type vars
154-
// (see FIXME in tests::impl_trait).
154+
// (see FIXME in tests::impl_trait) and falling back on any unknowns.
155155
match (ty.contains_unknown(), fn_params.as_deref()) {
156156
(true, Some(fn_params)) => format_to!(buf, "{}", fn_params[idx].ty().display(db)),
157157
_ => format_to!(buf, "{}", ty.display(db)),
@@ -161,12 +161,17 @@ fn signature_help_for_call(
161161
}
162162
res.signature.push(')');
163163

164+
let mut render = |ret_type: hir::Type| {
165+
if !ret_type.is_unit() {
166+
format_to!(res.signature, " -> {}", ret_type.display(db));
167+
}
168+
};
164169
match callable.kind() {
170+
hir::CallableKind::Function(func) if callable.return_type().contains_unknown() => {
171+
render(func.ret_type(db))
172+
}
165173
hir::CallableKind::Function(_) | hir::CallableKind::Closure => {
166-
let ret_type = callable.return_type();
167-
if !ret_type.is_unit() {
168-
format_to!(res.signature, " -> {}", ret_type.display(db));
169-
}
174+
render(callable.return_type())
170175
}
171176
hir::CallableKind::TupleStruct(_) | hir::CallableKind::TupleEnumVariant(_) => {}
172177
}
@@ -444,7 +449,7 @@ fn foo<T>() -> T where T: Copy + Display {}
444449
fn bar() { foo($0); }
445450
"#,
446451
expect![[r#"
447-
fn foo() -> {unknown}
452+
fn foo() -> T
448453
"#]],
449454
);
450455
}

0 commit comments

Comments
 (0)