Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21047 from A4-Tacks/unsafe-attr
Add `unsafe(…)` attribute completion
Lukas Wirth 5 months ago
parent 0af0141 · parent 64a34bc · commit c937fcc
-rw-r--r--crates/ide-completion/src/completions/attribute.rs3
-rw-r--r--crates/ide-completion/src/tests/attribute.rs54
2 files changed, 56 insertions, 1 deletions
diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs
index 297ce3339e..20776f6c49 100644
--- a/crates/ide-completion/src/completions/attribute.rs
+++ b/crates/ide-completion/src/completions/attribute.rs
@@ -231,7 +231,7 @@ const fn attr(
macro_rules! attrs {
// attributes applicable to all items
[@ { item $($tt:tt)* } {$($acc:tt)*}] => {
- attrs!(@ { $($tt)* } { $($acc)*, "deprecated", "doc", "dochidden", "docalias", "docinclude", "must_use", "no_mangle" })
+ attrs!(@ { $($tt)* } { $($acc)*, "deprecated", "doc", "dochidden", "docalias", "docinclude", "must_use", "no_mangle", "unsafe" })
};
// attributes applicable to all adts
[@ { adt $($tt:tt)* } {$($acc:tt)*}] => {
@@ -395,6 +395,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[
attr("track_caller", None, None),
attr("type_length_limit = …", Some("type_length_limit"), Some("type_length_limit = ${0:128}"))
.prefer_inner(),
+ attr("unsafe(…)", Some("unsafe"), Some("unsafe($0)")),
attr("used", None, None),
attr("warn(…)", Some("warn"), Some("warn(${0:lint})")),
attr(
diff --git a/crates/ide-completion/src/tests/attribute.rs b/crates/ide-completion/src/tests/attribute.rs
index 2a6238997b..3538dac2bb 100644
--- a/crates/ide-completion/src/tests/attribute.rs
+++ b/crates/ide-completion/src/tests/attribute.rs
@@ -61,6 +61,7 @@ pub struct Foo(#[m$0] i32);
at target_feature(enable = "…")
at test
at track_caller
+ at unsafe(…)
at used
at warn(…)
md mac
@@ -95,6 +96,7 @@ struct Foo;
at no_mangle
at non_exhaustive
at repr(…)
+ at unsafe(…)
at warn(…)
md proc_macros
kw crate::
@@ -173,6 +175,7 @@ fn attr_on_source_file() {
at no_std
at recursion_limit = "…"
at type_length_limit = …
+ at unsafe(…)
at warn(…)
at windows_subsystem = "…"
kw crate::
@@ -201,6 +204,7 @@ fn attr_on_module() {
at must_use
at no_mangle
at path = "…"
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -224,6 +228,7 @@ fn attr_on_module() {
at must_use
at no_implicit_prelude
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -252,6 +257,7 @@ fn attr_on_macro_rules() {
at macro_use
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -277,6 +283,7 @@ fn attr_on_macro_def() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -303,6 +310,7 @@ fn attr_on_extern_crate() {
at macro_use
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -328,6 +336,7 @@ fn attr_on_use() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -353,6 +362,7 @@ fn attr_on_type_alias() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -387,6 +397,7 @@ struct Foo;
at no_mangle
at non_exhaustive
at repr(…)
+ at unsafe(…)
at warn(…)
md core
kw crate::
@@ -416,6 +427,7 @@ fn attr_on_enum() {
at no_mangle
at non_exhaustive
at repr(…)
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -441,6 +453,7 @@ fn attr_on_const() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -470,6 +483,7 @@ fn attr_on_static() {
at link_section = "…"
at must_use
at no_mangle
+ at unsafe(…)
at used
at warn(…)
kw crate::
@@ -497,6 +511,7 @@ fn attr_on_trait() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -524,6 +539,7 @@ fn attr_on_impl() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -545,6 +561,7 @@ fn attr_on_impl() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -572,6 +589,7 @@ fn attr_with_qualifier() {
at forbid(…)
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
"#]],
);
@@ -592,12 +610,44 @@ fn attr_with_qualifier() {
at must_use
at no_mangle
at on_unimplemented
+ at unsafe(…)
at warn(…)
"#]],
);
}
#[test]
+fn attr_on_unsafe_attr() {
+ check(
+ r#"#[unsafe($0)] static FOO: () = ()"#,
+ expect![[r#"
+ at allow(…)
+ at cfg(…)
+ at cfg_attr(…)
+ at deny(…)
+ at deprecated
+ at doc = "…"
+ at doc = include_str!("…")
+ at doc(alias = "…")
+ at doc(hidden)
+ at expect(…)
+ at export_name = "…"
+ at forbid(…)
+ at global_allocator
+ at link_name = "…"
+ at link_section = "…"
+ at must_use
+ at no_mangle
+ at unsafe(…)
+ at used
+ at warn(…)
+ kw crate::
+ kw self::
+ "#]],
+ );
+}
+
+#[test]
fn attr_diagnostic_on_unimplemented() {
check(
r#"#[diagnostic::on_unimplemented($0)] trait Foo {}"#,
@@ -643,6 +693,7 @@ fn attr_on_extern_block() {
at link
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -665,6 +716,7 @@ fn attr_on_extern_block() {
at link
at must_use
at no_mangle
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -723,6 +775,7 @@ fn attr_on_fn() {
at target_feature(enable = "…")
at test
at track_caller
+ at unsafe(…)
at warn(…)
kw crate::
kw self::
@@ -773,6 +826,7 @@ fn attr_in_source_file_end() {
at target_feature(enable = "…")
at test
at track_caller
+ at unsafe(…)
at used
at warn(…)
kw crate::