diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-17 12:01:52 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-17 12:01:52 +0100 |
commit | 9b5ac1d82fa3b9b810656e5b4a44d471b9923ce7 (patch) | |
tree | ed3930e18000f7ee5ebd7a3b81de2098fc595f7f /crates/ra_ide | |
parent | 6ae6c1460e1e0524664af39fd0dbe3b1af3fac50 (diff) | |
parent | 393b7119bd5341bffb166e0dadcff9124e28b888 (diff) |
Merge #5417
5417: Mismatched arg count works for lambdas r=jonas-schievink a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 35 | ||||
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 4 |
2 files changed, 37 insertions, 2 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 35a8a0dc5..14980afdd 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -70,6 +70,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
70 | variant.name(db) | 70 | variant.name(db) |
71 | ); | 71 | ); |
72 | } | 72 | } |
73 | hir::CallableKind::Closure => (), | ||
73 | } | 74 | } |
74 | 75 | ||
75 | res.signature.push('('); | 76 | res.signature.push('('); |
@@ -93,7 +94,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
93 | res.signature.push(')'); | 94 | res.signature.push(')'); |
94 | 95 | ||
95 | match callable.kind() { | 96 | match callable.kind() { |
96 | hir::CallableKind::Function(_) => { | 97 | hir::CallableKind::Function(_) | hir::CallableKind::Closure => { |
97 | let ret_type = callable.return_type(); | 98 | let ret_type = callable.return_type(); |
98 | if !ret_type.is_unit() { | 99 | if !ret_type.is_unit() { |
99 | format_to!(res.signature, " -> {}", ret_type.display(db)); | 100 | format_to!(res.signature, " -> {}", ret_type.display(db)); |
@@ -702,4 +703,36 @@ id! { | |||
702 | "#]], | 703 | "#]], |
703 | ); | 704 | ); |
704 | } | 705 | } |
706 | |||
707 | #[test] | ||
708 | fn call_info_for_lambdas() { | ||
709 | check( | ||
710 | r#" | ||
711 | struct S; | ||
712 | fn foo(s: S) -> i32 { 92 } | ||
713 | fn main() { | ||
714 | (|s| foo(s))(<|>) | ||
715 | } | ||
716 | "#, | ||
717 | expect![[r#" | ||
718 | (S) -> i32 | ||
719 | (<S>) | ||
720 | "#]], | ||
721 | ) | ||
722 | } | ||
723 | |||
724 | #[test] | ||
725 | fn call_info_for_fn_ptr() { | ||
726 | check( | ||
727 | r#" | ||
728 | fn main(f: fn(i32, f64) -> char) { | ||
729 | f(0, <|>) | ||
730 | } | ||
731 | "#, | ||
732 | expect![[r#" | ||
733 | (i32, f64) -> char | ||
734 | (i32, <f64>) | ||
735 | "#]], | ||
736 | ) | ||
737 | } | ||
705 | } | 738 | } |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index cec3b04e8..43a5e29b5 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -262,7 +262,9 @@ fn should_show_param_name_hint( | |||
262 | let param_name = param_name.trim_start_matches('_'); | 262 | let param_name = param_name.trim_start_matches('_'); |
263 | let fn_name = match callable.kind() { | 263 | let fn_name = match callable.kind() { |
264 | hir::CallableKind::Function(it) => Some(it.name(sema.db).to_string()), | 264 | hir::CallableKind::Function(it) => Some(it.name(sema.db).to_string()), |
265 | hir::CallableKind::TupleStruct(_) | hir::CallableKind::TupleEnumVariant(_) => None, | 265 | hir::CallableKind::TupleStruct(_) |
266 | | hir::CallableKind::TupleEnumVariant(_) | ||
267 | | hir::CallableKind::Closure => None, | ||
266 | }; | 268 | }; |
267 | if param_name.is_empty() | 269 | if param_name.is_empty() |
268 | || Some(param_name) == fn_name.as_ref().map(|s| s.trim_start_matches('_')) | 270 | || Some(param_name) == fn_name.as_ref().map(|s| s.trim_start_matches('_')) |