Skip to content

Commit c937fcc

Browse files
authored
Merge pull request #21047 from A4-Tacks/unsafe-attr
Add `unsafe(…)` attribute completion
2 parents 0af0141 + 64a34bc commit c937fcc

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

crates/ide-completion/src/completions/attribute.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const fn attr(
231231
macro_rules! attrs {
232232
// attributes applicable to all items
233233
[@ { item $($tt:tt)* } {$($acc:tt)*}] => {
234-
attrs!(@ { $($tt)* } { $($acc)*, "deprecated", "doc", "dochidden", "docalias", "docinclude", "must_use", "no_mangle" })
234+
attrs!(@ { $($tt)* } { $($acc)*, "deprecated", "doc", "dochidden", "docalias", "docinclude", "must_use", "no_mangle", "unsafe" })
235235
};
236236
// attributes applicable to all adts
237237
[@ { adt $($tt:tt)* } {$($acc:tt)*}] => {
@@ -395,6 +395,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[
395395
attr("track_caller", None, None),
396396
attr("type_length_limit = …", Some("type_length_limit"), Some("type_length_limit = ${0:128}"))
397397
.prefer_inner(),
398+
attr("unsafe(…)", Some("unsafe"), Some("unsafe($0)")),
398399
attr("used", None, None),
399400
attr("warn(…)", Some("warn"), Some("warn(${0:lint})")),
400401
attr(

crates/ide-completion/src/tests/attribute.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct Foo(#[m$0] i32);
6161
at target_feature(enable = "…")
6262
at test
6363
at track_caller
64+
at unsafe(…)
6465
at used
6566
at warn(…)
6667
md mac
@@ -95,6 +96,7 @@ struct Foo;
9596
at no_mangle
9697
at non_exhaustive
9798
at repr(…)
99+
at unsafe(…)
98100
at warn(…)
99101
md proc_macros
100102
kw crate::
@@ -173,6 +175,7 @@ fn attr_on_source_file() {
173175
at no_std
174176
at recursion_limit = "…"
175177
at type_length_limit = …
178+
at unsafe(…)
176179
at warn(…)
177180
at windows_subsystem = "…"
178181
kw crate::
@@ -201,6 +204,7 @@ fn attr_on_module() {
201204
at must_use
202205
at no_mangle
203206
at path = "…"
207+
at unsafe(…)
204208
at warn(…)
205209
kw crate::
206210
kw self::
@@ -224,6 +228,7 @@ fn attr_on_module() {
224228
at must_use
225229
at no_implicit_prelude
226230
at no_mangle
231+
at unsafe(…)
227232
at warn(…)
228233
kw crate::
229234
kw self::
@@ -252,6 +257,7 @@ fn attr_on_macro_rules() {
252257
at macro_use
253258
at must_use
254259
at no_mangle
260+
at unsafe(…)
255261
at warn(…)
256262
kw crate::
257263
kw self::
@@ -277,6 +283,7 @@ fn attr_on_macro_def() {
277283
at forbid(…)
278284
at must_use
279285
at no_mangle
286+
at unsafe(…)
280287
at warn(…)
281288
kw crate::
282289
kw self::
@@ -303,6 +310,7 @@ fn attr_on_extern_crate() {
303310
at macro_use
304311
at must_use
305312
at no_mangle
313+
at unsafe(…)
306314
at warn(…)
307315
kw crate::
308316
kw self::
@@ -328,6 +336,7 @@ fn attr_on_use() {
328336
at forbid(…)
329337
at must_use
330338
at no_mangle
339+
at unsafe(…)
331340
at warn(…)
332341
kw crate::
333342
kw self::
@@ -353,6 +362,7 @@ fn attr_on_type_alias() {
353362
at forbid(…)
354363
at must_use
355364
at no_mangle
365+
at unsafe(…)
356366
at warn(…)
357367
kw crate::
358368
kw self::
@@ -387,6 +397,7 @@ struct Foo;
387397
at no_mangle
388398
at non_exhaustive
389399
at repr(…)
400+
at unsafe(…)
390401
at warn(…)
391402
md core
392403
kw crate::
@@ -416,6 +427,7 @@ fn attr_on_enum() {
416427
at no_mangle
417428
at non_exhaustive
418429
at repr(…)
430+
at unsafe(…)
419431
at warn(…)
420432
kw crate::
421433
kw self::
@@ -441,6 +453,7 @@ fn attr_on_const() {
441453
at forbid(…)
442454
at must_use
443455
at no_mangle
456+
at unsafe(…)
444457
at warn(…)
445458
kw crate::
446459
kw self::
@@ -470,6 +483,7 @@ fn attr_on_static() {
470483
at link_section = "…"
471484
at must_use
472485
at no_mangle
486+
at unsafe(…)
473487
at used
474488
at warn(…)
475489
kw crate::
@@ -497,6 +511,7 @@ fn attr_on_trait() {
497511
at forbid(…)
498512
at must_use
499513
at no_mangle
514+
at unsafe(…)
500515
at warn(…)
501516
kw crate::
502517
kw self::
@@ -524,6 +539,7 @@ fn attr_on_impl() {
524539
at forbid(…)
525540
at must_use
526541
at no_mangle
542+
at unsafe(…)
527543
at warn(…)
528544
kw crate::
529545
kw self::
@@ -545,6 +561,7 @@ fn attr_on_impl() {
545561
at forbid(…)
546562
at must_use
547563
at no_mangle
564+
at unsafe(…)
548565
at warn(…)
549566
kw crate::
550567
kw self::
@@ -572,6 +589,7 @@ fn attr_with_qualifier() {
572589
at forbid(…)
573590
at must_use
574591
at no_mangle
592+
at unsafe(…)
575593
at warn(…)
576594
"#]],
577595
);
@@ -592,11 +610,43 @@ fn attr_with_qualifier() {
592610
at must_use
593611
at no_mangle
594612
at on_unimplemented
613+
at unsafe(…)
595614
at warn(…)
596615
"#]],
597616
);
598617
}
599618

619+
#[test]
620+
fn attr_on_unsafe_attr() {
621+
check(
622+
r#"#[unsafe($0)] static FOO: () = ()"#,
623+
expect![[r#"
624+
at allow(…)
625+
at cfg(…)
626+
at cfg_attr(…)
627+
at deny(…)
628+
at deprecated
629+
at doc = "…"
630+
at doc = include_str!("…")
631+
at doc(alias = "…")
632+
at doc(hidden)
633+
at expect(…)
634+
at export_name = "…"
635+
at forbid(…)
636+
at global_allocator
637+
at link_name = "…"
638+
at link_section = "…"
639+
at must_use
640+
at no_mangle
641+
at unsafe(…)
642+
at used
643+
at warn(…)
644+
kw crate::
645+
kw self::
646+
"#]],
647+
);
648+
}
649+
600650
#[test]
601651
fn attr_diagnostic_on_unimplemented() {
602652
check(
@@ -643,6 +693,7 @@ fn attr_on_extern_block() {
643693
at link
644694
at must_use
645695
at no_mangle
696+
at unsafe(…)
646697
at warn(…)
647698
kw crate::
648699
kw self::
@@ -665,6 +716,7 @@ fn attr_on_extern_block() {
665716
at link
666717
at must_use
667718
at no_mangle
719+
at unsafe(…)
668720
at warn(…)
669721
kw crate::
670722
kw self::
@@ -723,6 +775,7 @@ fn attr_on_fn() {
723775
at target_feature(enable = "…")
724776
at test
725777
at track_caller
778+
at unsafe(…)
726779
at warn(…)
727780
kw crate::
728781
kw self::
@@ -773,6 +826,7 @@ fn attr_in_source_file_end() {
773826
at target_feature(enable = "…")
774827
at test
775828
at track_caller
829+
at unsafe(…)
776830
at used
777831
at warn(…)
778832
kw crate::

0 commit comments

Comments
 (0)