aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-25 14:30:50 +0000
committerAleksey Kladov <[email protected]>2019-11-25 14:50:49 +0000
commit5fd68b592938b6a4c074146c1b22ea0f6908fe26 (patch)
tree3403f802366b9ddf9c9e1c1ff59af3d81e476ad1 /crates/ra_syntax/src/ast
parente1c0bdaf75f8d88a5c28b3e44def17d91d4f46b3 (diff)
Fix hir for ast::UnionDef
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs11
-rw-r--r--crates/ra_syntax/src/ast/generated.rs28
2 files changed, 24 insertions, 15 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 513ed7920..a8f625176 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -196,17 +196,6 @@ impl StructKind {
196} 196}
197 197
198impl ast::StructDef { 198impl ast::StructDef {
199 pub fn is_union(&self) -> bool {
200 for child in self.syntax().children_with_tokens() {
201 match child.kind() {
202 T![struct] => return false,
203 T![union] => return true,
204 _ => (),
205 }
206 }
207 false
208 }
209
210 pub fn kind(&self) -> StructKind { 199 pub fn kind(&self) -> StructKind {
211 StructKind::from_node(self) 200 StructKind::from_node(self)
212 } 201 }
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 1a03ae56c..c06076e3d 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1856,6 +1856,7 @@ impl Module {
1856#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1856#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1857pub enum ModuleItem { 1857pub enum ModuleItem {
1858 StructDef(StructDef), 1858 StructDef(StructDef),
1859 UnionDef(UnionDef),
1859 EnumDef(EnumDef), 1860 EnumDef(EnumDef),
1860 FnDef(FnDef), 1861 FnDef(FnDef),
1861 TraitDef(TraitDef), 1862 TraitDef(TraitDef),
@@ -1872,6 +1873,11 @@ impl From<StructDef> for ModuleItem {
1872 ModuleItem::StructDef(node) 1873 ModuleItem::StructDef(node)
1873 } 1874 }
1874} 1875}
1876impl From<UnionDef> for ModuleItem {
1877 fn from(node: UnionDef) -> ModuleItem {
1878 ModuleItem::UnionDef(node)
1879 }
1880}
1875impl From<EnumDef> for ModuleItem { 1881impl From<EnumDef> for ModuleItem {
1876 fn from(node: EnumDef) -> ModuleItem { 1882 fn from(node: EnumDef) -> ModuleItem {
1877 ModuleItem::EnumDef(node) 1883 ModuleItem::EnumDef(node)
@@ -1925,14 +1931,15 @@ impl From<Module> for ModuleItem {
1925impl AstNode for ModuleItem { 1931impl AstNode for ModuleItem {
1926 fn can_cast(kind: SyntaxKind) -> bool { 1932 fn can_cast(kind: SyntaxKind) -> bool {
1927 match kind { 1933 match kind {
1928 STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM 1934 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF
1929 | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, 1935 | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1930 _ => false, 1936 _ => false,
1931 } 1937 }
1932 } 1938 }
1933 fn cast(syntax: SyntaxNode) -> Option<Self> { 1939 fn cast(syntax: SyntaxNode) -> Option<Self> {
1934 let res = match syntax.kind() { 1940 let res = match syntax.kind() {
1935 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }), 1941 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
1942 UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
1936 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }), 1943 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
1937 FN_DEF => ModuleItem::FnDef(FnDef { syntax }), 1944 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
1938 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }), 1945 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
@@ -1950,6 +1957,7 @@ impl AstNode for ModuleItem {
1950 fn syntax(&self) -> &SyntaxNode { 1957 fn syntax(&self) -> &SyntaxNode {
1951 match self { 1958 match self {
1952 ModuleItem::StructDef(it) => &it.syntax, 1959 ModuleItem::StructDef(it) => &it.syntax,
1960 ModuleItem::UnionDef(it) => &it.syntax,
1953 ModuleItem::EnumDef(it) => &it.syntax, 1961 ModuleItem::EnumDef(it) => &it.syntax,
1954 ModuleItem::FnDef(it) => &it.syntax, 1962 ModuleItem::FnDef(it) => &it.syntax,
1955 ModuleItem::TraitDef(it) => &it.syntax, 1963 ModuleItem::TraitDef(it) => &it.syntax,
@@ -2038,6 +2046,7 @@ impl NeverType {}
2038pub enum NominalDef { 2046pub enum NominalDef {
2039 StructDef(StructDef), 2047 StructDef(StructDef),
2040 EnumDef(EnumDef), 2048 EnumDef(EnumDef),
2049 UnionDef(UnionDef),
2041} 2050}
2042impl From<StructDef> for NominalDef { 2051impl From<StructDef> for NominalDef {
2043 fn from(node: StructDef) -> NominalDef { 2052 fn from(node: StructDef) -> NominalDef {
@@ -2049,10 +2058,15 @@ impl From<EnumDef> for NominalDef {
2049 NominalDef::EnumDef(node) 2058 NominalDef::EnumDef(node)
2050 } 2059 }
2051} 2060}
2061impl From<UnionDef> for NominalDef {
2062 fn from(node: UnionDef) -> NominalDef {
2063 NominalDef::UnionDef(node)
2064 }
2065}
2052impl AstNode for NominalDef { 2066impl AstNode for NominalDef {
2053 fn can_cast(kind: SyntaxKind) -> bool { 2067 fn can_cast(kind: SyntaxKind) -> bool {
2054 match kind { 2068 match kind {
2055 STRUCT_DEF | ENUM_DEF => true, 2069 STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
2056 _ => false, 2070 _ => false,
2057 } 2071 }
2058 } 2072 }
@@ -2060,6 +2074,7 @@ impl AstNode for NominalDef {
2060 let res = match syntax.kind() { 2074 let res = match syntax.kind() {
2061 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }), 2075 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
2062 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }), 2076 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
2077 UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
2063 _ => return None, 2078 _ => return None,
2064 }; 2079 };
2065 Some(res) 2080 Some(res)
@@ -2068,6 +2083,7 @@ impl AstNode for NominalDef {
2068 match self { 2083 match self {
2069 NominalDef::StructDef(it) => &it.syntax, 2084 NominalDef::StructDef(it) => &it.syntax,
2070 NominalDef::EnumDef(it) => &it.syntax, 2085 NominalDef::EnumDef(it) => &it.syntax,
2086 NominalDef::UnionDef(it) => &it.syntax,
2071 } 2087 }
2072 } 2088 }
2073} 2089}
@@ -3815,7 +3831,11 @@ impl ast::NameOwner for UnionDef {}
3815impl ast::TypeParamsOwner for UnionDef {} 3831impl ast::TypeParamsOwner for UnionDef {}
3816impl ast::AttrsOwner for UnionDef {} 3832impl ast::AttrsOwner for UnionDef {}
3817impl ast::DocCommentsOwner for UnionDef {} 3833impl ast::DocCommentsOwner for UnionDef {}
3818impl UnionDef {} 3834impl UnionDef {
3835 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
3836 AstChildren::new(&self.syntax).next()
3837 }
3838}
3819#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3839#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3820pub struct UseItem { 3840pub struct UseItem {
3821 pub(crate) syntax: SyntaxNode, 3841 pub(crate) syntax: SyntaxNode,