mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Render closure fn trait kind in siganture help
This commit is contained in:
parent
7c6f31a45b
commit
ff79903cf6
3 changed files with 79 additions and 27 deletions
|
@ -201,7 +201,10 @@ fn signature_help_for_call(
|
|||
variant.name(db).display(db)
|
||||
);
|
||||
}
|
||||
hir::CallableKind::Closure | hir::CallableKind::FnPtr | hir::CallableKind::Other => (),
|
||||
hir::CallableKind::Closure(closure) => {
|
||||
format_to!(res.signature, "impl {}", closure.fn_trait(db));
|
||||
}
|
||||
hir::CallableKind::FnPtr | hir::CallableKind::Other => (),
|
||||
}
|
||||
|
||||
res.signature.push('(');
|
||||
|
@ -245,7 +248,7 @@ fn signature_help_for_call(
|
|||
render(func.ret_type(db))
|
||||
}
|
||||
hir::CallableKind::Function(_)
|
||||
| hir::CallableKind::Closure
|
||||
| hir::CallableKind::Closure(_)
|
||||
| hir::CallableKind::FnPtr
|
||||
| hir::CallableKind::Other => render(callable.return_type()),
|
||||
hir::CallableKind::TupleStruct(_) | hir::CallableKind::TupleEnumVariant(_) => {}
|
||||
|
@ -1348,15 +1351,43 @@ fn test() { S.foo($0); }
|
|||
r#"
|
||||
struct S;
|
||||
fn foo(s: S) -> i32 { 92 }
|
||||
fn main() {
|
||||
let _move = S;
|
||||
(|s| {{_move}; foo(s)})($0)
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
impl FnOnce(s: S) -> i32
|
||||
^^^^
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
r#"
|
||||
struct S;
|
||||
fn foo(s: S) -> i32 { 92 }
|
||||
fn main() {
|
||||
(|s| foo(s))($0)
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
(s: S) -> i32
|
||||
^^^^
|
||||
impl Fn(s: S) -> i32
|
||||
^^^^
|
||||
"#]],
|
||||
)
|
||||
);
|
||||
check(
|
||||
r#"
|
||||
struct S;
|
||||
fn foo(s: S) -> i32 { 92 }
|
||||
fn main() {
|
||||
let mut mutate = 0;
|
||||
(|s| { mutate = 1; foo(s) })($0)
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
impl FnMut(s: S) -> i32
|
||||
^^^^
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue