Skip to content

Commit 7b2284c

Browse files
Register define_opaque builtin attribute macro
So that we'll correctly treat it as an attribute. I don't like that we have to register every builtin macro even if we don't need it, but that's what we got.
1 parent b657006 commit 7b2284c

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/tools/rust-analyzer/crates/hir-expand/src/builtin/attr_macro.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{ExpandResult, MacroCallId, MacroCallKind, db::ExpandDatabase, name,
77
use super::quote;
88

99
macro_rules! register_builtin {
10-
($(($name:ident, $variant:ident) => $expand:ident),* ) => {
10+
($(($name:ident, $variant:ident) => $expand:ident),* $(,)? ) => {
1111
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1212
pub enum BuiltinAttrExpander {
1313
$($variant),*
@@ -65,7 +65,8 @@ register_builtin! {
6565
(derive_const, DeriveConst) => derive_expand,
6666
(global_allocator, GlobalAllocator) => dummy_attr_expand,
6767
(test, Test) => dummy_gate_test_expand,
68-
(test_case, TestCase) => dummy_gate_test_expand
68+
(test_case, TestCase) => dummy_gate_test_expand,
69+
(define_opaque, DefineOpaque) => dummy_attr_expand,
6970
}
7071

7172
pub fn find_builtin_attr(ident: &name::Name) -> Option<BuiltinAttrExpander> {

src/tools/rust-analyzer/crates/ide-completion/src/tests/attribute.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,3 +1508,55 @@ extern crate dep;
15081508
)
15091509
}
15101510
}
1511+
1512+
#[test]
1513+
fn builtin_macro_completed_only_as_its_kind() {
1514+
check(
1515+
r#"
1516+
#[rustc_builtin_macro]
1517+
pub macro define_opaque($($tt:tt)*) {
1518+
/* compiler built-in */
1519+
}
1520+
1521+
fn foo() {
1522+
def$0
1523+
}
1524+
"#,
1525+
expect![[r#"
1526+
fn foo() fn()
1527+
bt u32 u32
1528+
kw async
1529+
kw const
1530+
kw crate::
1531+
kw enum
1532+
kw extern
1533+
kw false
1534+
kw fn
1535+
kw for
1536+
kw if
1537+
kw if let
1538+
kw impl
1539+
kw impl for
1540+
kw let
1541+
kw letm
1542+
kw loop
1543+
kw match
1544+
kw mod
1545+
kw return
1546+
kw self::
1547+
kw static
1548+
kw struct
1549+
kw trait
1550+
kw true
1551+
kw type
1552+
kw union
1553+
kw unsafe
1554+
kw use
1555+
kw while
1556+
kw while let
1557+
sn macro_rules
1558+
sn pd
1559+
sn ppd
1560+
"#]],
1561+
);
1562+
}

src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,5 @@ define_symbols! {
524524
arbitrary_self_types,
525525
arbitrary_self_types_pointers,
526526
supertrait_item_shadowing,
527+
define_opaque,
527528
}

0 commit comments

Comments
 (0)