Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/signature_help.rs')
-rw-r--r--crates/ide/src/signature_help.rs80
1 files changed, 79 insertions, 1 deletions
diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs
index edcf0dc22b..0022c1148a 100644
--- a/crates/ide/src/signature_help.rs
+++ b/crates/ide/src/signature_help.rs
@@ -174,9 +174,15 @@ fn signature_help_for_call(
match callable.kind() {
hir::CallableKind::Function(func) => {
res.doc = func.docs(db).map(Documentation::into_owned);
+ if func.is_const(db) {
+ format_to!(res.signature, "const ");
+ }
if func.is_async(db) {
format_to!(res.signature, "async ");
}
+ if func.is_unsafe(db) {
+ format_to!(res.signature, "unsafe ");
+ }
format_to!(res.signature, "fn {}", func.name(db).display(db, edition));
let generic_params = GenericDef::Function(func)
@@ -529,7 +535,7 @@ fn signature_help_for_tuple_struct_pat(
pat.syntax(),
token,
pat.fields(),
- fields.into_iter().map(|it| it.ty(db).to_type(db)),
+ fields.into_iter().map(|it| it.ty(db)),
display_target,
))
}
@@ -2664,4 +2670,76 @@ fn main() {
"#]],
);
}
+
+ #[test]
+ fn test_const_function() {
+ check(
+ r#"
+//- minicore: sized, fn
+pub const fn foo(x: u32, y: u32) -> u32 { x + y }
+
+fn main() {
+ foo($0)
+}
+ "#,
+ expect![[r#"
+ const fn foo(x: u32, y: u32) -> u32
+ ^^^^^^ ------
+ "#]],
+ );
+ }
+
+ #[test]
+ fn test_unsafe_function() {
+ check(
+ r#"
+//- minicore: sized, fn
+pub unsafe fn foo(x: u32, y: u32) -> u32 { x + y }
+
+fn main() {
+ unsafe { foo($0) }
+}
+ "#,
+ expect![[r#"
+ unsafe fn foo(x: u32, y: u32) -> u32
+ ^^^^^^ ------
+ "#]],
+ );
+ }
+
+ #[test]
+ fn test_const_unsafe_function() {
+ check(
+ r#"
+//- minicore: sized, fn
+pub const unsafe fn foo(x: u32, y: u32) -> u32 { x + y }
+
+fn main() {
+ unsafe { foo($0) }
+}
+ "#,
+ expect![[r#"
+ const unsafe fn foo(x: u32, y: u32) -> u32
+ ^^^^^^ ------
+ "#]],
+ );
+ }
+
+ #[test]
+ fn test_async_unsafe_function() {
+ check(
+ r#"
+//- minicore: sized, fn, future
+pub async unsafe fn foo(x: u32, y: u32) -> u32 { x + y }
+
+fn main() {
+ unsafe { foo($0) }
+}
+ "#,
+ expect![[r#"
+ async unsafe fn foo(x: u32, y: u32) -> u32
+ ^^^^^^ ------
+ "#]],
+ );
+ }
}