From f3ac19e8cd8be78f1eb96893482edac038739bb1 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 24 Aug 2020 22:02:55 +0200 Subject: Support extern types --- crates/hir_def/src/item_tree/lower.rs | 4 ++++ crates/hir_def/src/nameres/tests.rs | 2 ++ crates/syntax/src/ast/generated/nodes.rs | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 391ab5d39..6a503d785 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -557,6 +557,10 @@ impl Ctx { let statik = self.lower_static(&ast)?; statik.into() } + ast::ExternItem::TypeAlias(ty) => { + let id = self.lower_type_alias(&ty)?; + id.into() + } ast::ExternItem::MacroCall(_) => return None, }; self.add_attrs(id.into(), attrs); diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs index 8aaf7a158..5ca30dac9 100644 --- a/crates/hir_def/src/nameres/tests.rs +++ b/crates/hir_def/src/nameres/tests.rs @@ -46,6 +46,7 @@ union U { to_be: bool, not_to_be: u8 } enum E { V } extern { + type Ext; static EXT: u8; fn ext(); } @@ -65,6 +66,7 @@ extern { Baz: t v E: t EXT: v + Ext: t U: t ext: v "#]], diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 6317407c6..d6af5755c 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -1380,6 +1380,7 @@ pub enum ExternItem { Fn(Fn), MacroCall(MacroCall), Static(Static), + TypeAlias(TypeAlias), } impl ast::AttrsOwner for ExternItem {} impl ast::NameOwner for ExternItem {} @@ -3339,10 +3340,13 @@ impl From for ExternItem { impl From for ExternItem { fn from(node: Static) -> ExternItem { ExternItem::Static(node) } } +impl From for ExternItem { + fn from(node: TypeAlias) -> ExternItem { ExternItem::TypeAlias(node) } +} impl AstNode for ExternItem { fn can_cast(kind: SyntaxKind) -> bool { match kind { - FN | MACRO_CALL | STATIC => true, + FN | MACRO_CALL | STATIC | TYPE_ALIAS => true, _ => false, } } @@ -3351,6 +3355,7 @@ impl AstNode for ExternItem { FN => ExternItem::Fn(Fn { syntax }), MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }), STATIC => ExternItem::Static(Static { syntax }), + TYPE_ALIAS => ExternItem::TypeAlias(TypeAlias { syntax }), _ => return None, }; Some(res) @@ -3360,6 +3365,7 @@ impl AstNode for ExternItem { ExternItem::Fn(it) => &it.syntax, ExternItem::MacroCall(it) => &it.syntax, ExternItem::Static(it) => &it.syntax, + ExternItem::TypeAlias(it) => &it.syntax, } } } -- cgit v1.2.3