Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/ide-completion/src/completions/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*}] => {
Expand Down Expand Up @@ -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(
Expand Down
54 changes: 54 additions & 0 deletions crates/ide-completion/src/tests/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,6 +96,7 @@ struct Foo;
at no_mangle
at non_exhaustive
at repr(…)
at unsafe(…)
at warn(…)
md proc_macros
kw crate::
Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -201,6 +204,7 @@ fn attr_on_module() {
at must_use
at no_mangle
at path = "…"
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand All @@ -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::
Expand Down Expand Up @@ -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::
Expand All @@ -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::
Expand All @@ -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::
Expand All @@ -328,6 +336,7 @@ fn attr_on_use() {
at forbid(…)
at must_use
at no_mangle
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand All @@ -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::
Expand Down Expand Up @@ -387,6 +397,7 @@ struct Foo;
at no_mangle
at non_exhaustive
at repr(…)
at unsafe(…)
at warn(…)
md core
kw crate::
Expand Down Expand Up @@ -416,6 +427,7 @@ fn attr_on_enum() {
at no_mangle
at non_exhaustive
at repr(…)
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand All @@ -441,6 +453,7 @@ fn attr_on_const() {
at forbid(…)
at must_use
at no_mangle
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -497,6 +511,7 @@ fn attr_on_trait() {
at forbid(…)
at must_use
at no_mangle
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand Down Expand Up @@ -524,6 +539,7 @@ fn attr_on_impl() {
at forbid(…)
at must_use
at no_mangle
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand All @@ -545,6 +561,7 @@ fn attr_on_impl() {
at forbid(…)
at must_use
at no_mangle
at unsafe(…)
at warn(…)
kw crate::
kw self::
Expand Down Expand Up @@ -572,6 +589,7 @@ fn attr_with_qualifier() {
at forbid(…)
at must_use
at no_mangle
at unsafe(…)
at warn(…)
"#]],
);
Expand All @@ -592,11 +610,43 @@ 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(
Expand Down Expand Up @@ -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::
Expand All @@ -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::
Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -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::
Expand Down