From 1ae4721c9cfea746fce59a816b1c266bf373d6cf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:36:46 +0200 Subject: Finalize union grammar --- crates/ra_hir/src/has_source.rs | 4 +-- crates/ra_hir/src/semantics.rs | 2 +- crates/ra_hir/src/semantics/source_to_def.rs | 4 +-- crates/ra_hir_def/src/body/lower.rs | 2 +- crates/ra_hir_def/src/item_tree.rs | 4 +-- crates/ra_hir_def/src/item_tree/lower.rs | 6 ++-- crates/ra_hir_def/src/item_tree/tests.rs | 2 +- crates/ra_hir_def/src/keys.rs | 2 +- crates/ra_hir_expand/src/builtin_derive.rs | 2 +- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 2 +- crates/ra_ide/src/goto_implementation.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 2 +- crates/ra_ide_db/src/defs.rs | 2 +- crates/ra_parser/src/grammar/items/adt.rs | 2 +- crates/ra_parser/src/syntax_kind/generated.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 42 +++++++++++----------- crates/ra_syntax/src/ast/node_ext.rs | 2 +- .../parser/inline/ok/0068_union_items.rast | 4 +-- .../test_data/parser/ok/0035_weird_exprs.rast | 2 +- crates/rust-analyzer/src/handlers.rs | 2 +- 21 files changed, 47 insertions(+), 47 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 1557b7c83..3a3d82109 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs @@ -63,8 +63,8 @@ impl HasSource for Struct { } } impl HasSource for Union { - type Ast = ast::UnionDef; - fn source(self, db: &dyn HirDatabase) -> InFile { + type Ast = ast::Union; + fn source(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 3e9c54a39..6c8775402 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -582,7 +582,7 @@ to_def_impls![ (crate::Module, ast::Module, module_to_def), (crate::Struct, ast::StructDef, struct_to_def), (crate::Enum, ast::EnumDef, enum_to_def), - (crate::Union, ast::UnionDef, union_to_def), + (crate::Union, ast::Union, union_to_def), (crate::Trait, ast::TraitDef, trait_to_def), (crate::ImplDef, ast::ImplDef, impl_to_def), (crate::TypeAlias, ast::TypeAlias, type_alias_to_def), diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 4f90f588e..0093a8671 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -80,7 +80,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn enum_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::ENUM) } - pub(super) fn union_to_def(&mut self, src: InFile) -> Option { + pub(super) fn union_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::UNION) } pub(super) fn static_to_def(&mut self, src: InFile) -> Option { @@ -174,7 +174,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.enum_to_def(container.with_value(it))?; def.into() }, - ast::UnionDef(it) => { + ast::Union(it) => { let def = self.union_to_def(container.with_value(it))?; VariantId::from(def).into() }, diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 576342af9..d8963f63f 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -660,7 +660,7 @@ impl ExprCollector<'_> { let id = self.find_inner_item(&def)?; (EnumLoc { container, id }.intern(self.db).into(), def.name()) } - ast::Item::UnionDef(def) => { + ast::Item::Union(def) => { let id = self.find_inner_item(&def)?; (UnionLoc { container, id }.intern(self.db).into(), def.name()) } diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index ea61ac217..7bcc13b06 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -415,7 +415,7 @@ mod_items! { ExternCrate in extern_crates -> ast::ExternCrate, Function in functions -> ast::Fn, Struct in structs -> ast::StructDef, - Union in unions -> ast::UnionDef, + Union in unions -> ast::Union, Enum in enums -> ast::EnumDef, Const in consts -> ast::ConstDef, Static in statics -> ast::StaticDef, @@ -534,7 +534,7 @@ pub struct Union { pub visibility: RawVisibilityId, pub generic_params: GenericParamsId, pub fields: Fields, - pub ast_id: FileAstId, + pub ast_id: FileAstId, } #[derive(Debug, Clone, Eq, PartialEq)] diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index df909ee9e..2721a02a5 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -79,7 +79,7 @@ impl Ctx { // Collect inner items for 1-to-1-lowered items. match item { ast::Item::StructDef(_) - | ast::Item::UnionDef(_) + | ast::Item::Union(_) | ast::Item::EnumDef(_) | ast::Item::Fn(_) | ast::Item::TypeAlias(_) @@ -104,7 +104,7 @@ impl Ctx { let attrs = Attrs::new(item, &self.hygiene); let items = match item { ast::Item::StructDef(ast) => self.lower_struct(ast).map(Into::into), - ast::Item::UnionDef(ast) => self.lower_union(ast).map(Into::into), + ast::Item::Union(ast) => self.lower_union(ast).map(Into::into), ast::Item::EnumDef(ast) => self.lower_enum(ast).map(Into::into), ast::Item::Fn(ast) => self.lower_function(ast).map(Into::into), ast::Item::TypeAlias(ast) => self.lower_type_alias(ast).map(Into::into), @@ -233,7 +233,7 @@ impl Ctx { res } - fn lower_union(&mut self, union: &ast::UnionDef) -> Option> { + fn lower_union(&mut self, union: &ast::Union) -> Option> { let visibility = self.lower_visibility(union); let name = union.name()?.as_name(); let generic_params = self.lower_generic_params(GenericsOwner::Union, union); diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index a8f5da1c1..0be021948 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs @@ -252,7 +252,7 @@ fn smoke() { #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }] Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::(0..1), ast_id: FileAstId::(6) } #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }] - Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::(3..4)), ast_id: FileAstId::(7) } + Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::(3..4)), ast_id: FileAstId::(7) } "##]], ); } diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index 9ca276235..2282aed14 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs @@ -21,7 +21,7 @@ pub const TYPE_ALIAS: Key = Key::new(); pub const IMPL: Key = Key::new(); pub const TRAIT: Key = Key::new(); pub const STRUCT: Key = Key::new(); -pub const UNION: Key = Key::new(); +pub const UNION: Key = Key::new(); pub const ENUM: Key = Key::new(); pub const ENUM_VARIANT: Key = Key::new(); diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index 3e2f0a520..ef3508494 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs @@ -74,7 +74,7 @@ fn parse_adt(tt: &tt::Subtree) -> Result { match node { ast::StructDef(it) => (it.name(), it.generic_param_list()), ast::EnumDef(it) => (it.name(), it.generic_param_list()), - ast::UnionDef(it) => (it.name(), it.generic_param_list()), + ast::Union(it) => (it.name(), it.generic_param_list()), _ => { debug!("unexpected node is {:?}", node); return Err(mbe::ExpandError::ConversionError) diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 78a2598d6..730df1414 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -19,7 +19,7 @@ impl ShortLabel for ast::StructDef { } } -impl ShortLabel for ast::UnionDef { +impl ShortLabel for ast::Union { fn short_label(&self) -> Option { short_label_from_node(self, "union ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index a8fd1a2fd..874cf72ef 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -127,7 +127,7 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(it, Some(detail)) }, ast::StructDef(it) => decl(it), - ast::UnionDef(it) => decl(it), + ast::Union(it) => decl(it), ast::EnumDef(it) => decl(it), ast::EnumVariant(it) => decl(it), ast::TraitDef(it) => decl(it), diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 16a61d071..e41a4a12b 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -46,7 +46,7 @@ fn impls_for_def( let ty = match node { ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), - ast::AdtDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), }; let impls = ImplDef::all_in_crate(sema.db, krate); diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index a04b9d893..b0ab160ac 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -707,7 +707,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { let tag = match parent.kind() { STRUCT_DEF => HighlightTag::Struct, ENUM_DEF => HighlightTag::Enum, - UNION_DEF => HighlightTag::Union, + UNION => HighlightTag::Union, TRAIT_DEF => HighlightTag::Trait, TYPE_ALIAS => HighlightTag::TypeAlias, TYPE_PARAM => HighlightTag::TypeParam, diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 30f18b9cf..11de05958 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -154,7 +154,7 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option let def: hir::Struct = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, - ast::UnionDef(it) => { + ast::Union(it) => { let def: hir::Union = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, diff --git a/crates/ra_parser/src/grammar/items/adt.rs b/crates/ra_parser/src/grammar/items/adt.rs index 0e96bf77e..ec06e2d45 100644 --- a/crates/ra_parser/src/grammar/items/adt.rs +++ b/crates/ra_parser/src/grammar/items/adt.rs @@ -11,7 +11,7 @@ pub(super) fn struct_def(p: &mut Parser, m: Marker) { pub(super) fn union_def(p: &mut Parser, m: Marker) { assert!(p.at_contextual_kw("union")); p.bump_remap(T![union]); - struct_or_union(p, m, T![union], UNION_DEF); + struct_or_union(p, m, T![union], UNION); } fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 8586758b4..7efdeeac6 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -124,7 +124,7 @@ pub enum SyntaxKind { R_DOLLAR, SOURCE_FILE, STRUCT_DEF, - UNION_DEF, + UNION, ENUM_DEF, FN, RET_TYPE, diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 1776fb6e6..d153e8528 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -199,14 +199,14 @@ impl TypeAlias { pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UnionDef { +pub struct Union { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for UnionDef {} -impl ast::NameOwner for UnionDef {} -impl ast::VisibilityOwner for UnionDef {} -impl ast::GenericParamsOwner for UnionDef {} -impl UnionDef { +impl ast::AttrsOwner for Union {} +impl ast::NameOwner for Union {} +impl ast::VisibilityOwner for Union {} +impl ast::GenericParamsOwner for Union {} +impl Union { pub fn union_token(&self) -> Option { support::token(&self.syntax, T![union]) } pub fn record_field_list(&self) -> Option { support::child(&self.syntax) } } @@ -1284,7 +1284,7 @@ pub enum Item { StructDef(StructDef), TraitDef(TraitDef), TypeAlias(TypeAlias), - UnionDef(UnionDef), + Union(Union), Use(Use), } impl ast::AttrsOwner for Item {} @@ -1393,7 +1393,7 @@ impl ast::VisibilityOwner for ExternItem {} pub enum AdtDef { StructDef(StructDef), EnumDef(EnumDef), - UnionDef(UnionDef), + Union(Union), } impl ast::AttrsOwner for AdtDef {} impl ast::GenericParamsOwner for AdtDef {} @@ -1553,8 +1553,8 @@ impl AstNode for TypeAlias { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for UnionDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } +impl AstNode for Union { + fn can_cast(kind: SyntaxKind) -> bool { kind == UNION } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2810,8 +2810,8 @@ impl From for Item { impl From for Item { fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) } } -impl From for Item { - fn from(node: UnionDef) -> Item { Item::UnionDef(node) } +impl From for Item { + fn from(node: Union) -> Item { Item::Union(node) } } impl From for Item { fn from(node: Use) -> Item { Item::Use(node) } @@ -2820,7 +2820,7 @@ impl AstNode for Item { fn can_cast(kind: SyntaxKind) -> bool { match kind { CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL - | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS | UNION_DEF | USE => true, + | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS | UNION | USE => true, _ => false, } } @@ -2838,7 +2838,7 @@ impl AstNode for Item { STRUCT_DEF => Item::StructDef(StructDef { syntax }), TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }), - UNION_DEF => Item::UnionDef(UnionDef { syntax }), + UNION => Item::Union(Union { syntax }), USE => Item::Use(Use { syntax }), _ => return None, }; @@ -2858,7 +2858,7 @@ impl AstNode for Item { Item::StructDef(it) => &it.syntax, Item::TraitDef(it) => &it.syntax, Item::TypeAlias(it) => &it.syntax, - Item::UnionDef(it) => &it.syntax, + Item::Union(it) => &it.syntax, Item::Use(it) => &it.syntax, } } @@ -3378,13 +3378,13 @@ impl From for AdtDef { impl From for AdtDef { fn from(node: EnumDef) -> AdtDef { AdtDef::EnumDef(node) } } -impl From for AdtDef { - fn from(node: UnionDef) -> AdtDef { AdtDef::UnionDef(node) } +impl From for AdtDef { + fn from(node: Union) -> AdtDef { AdtDef::Union(node) } } impl AstNode for AdtDef { fn can_cast(kind: SyntaxKind) -> bool { match kind { - STRUCT_DEF | ENUM_DEF | UNION_DEF => true, + STRUCT_DEF | ENUM_DEF | UNION => true, _ => false, } } @@ -3392,7 +3392,7 @@ impl AstNode for AdtDef { let res = match syntax.kind() { STRUCT_DEF => AdtDef::StructDef(StructDef { syntax }), ENUM_DEF => AdtDef::EnumDef(EnumDef { syntax }), - UNION_DEF => AdtDef::UnionDef(UnionDef { syntax }), + UNION => AdtDef::Union(Union { syntax }), _ => return None, }; Some(res) @@ -3401,7 +3401,7 @@ impl AstNode for AdtDef { match self { AdtDef::StructDef(it) => &it.syntax, AdtDef::EnumDef(it) => &it.syntax, - AdtDef::UnionDef(it) => &it.syntax, + AdtDef::Union(it) => &it.syntax, } } } @@ -3525,7 +3525,7 @@ impl std::fmt::Display for TypeAlias { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for UnionDef { +impl std::fmt::Display for Union { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index ffe6746d3..ce11a7513 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -476,7 +476,7 @@ impl ast::TokenTree { impl ast::DocCommentsOwner for ast::SourceFile {} impl ast::DocCommentsOwner for ast::Fn {} impl ast::DocCommentsOwner for ast::StructDef {} -impl ast::DocCommentsOwner for ast::UnionDef {} +impl ast::DocCommentsOwner for ast::Union {} impl ast::DocCommentsOwner for ast::RecordField {} impl ast::DocCommentsOwner for ast::TupleField {} impl ast::DocCommentsOwner for ast::EnumDef {} diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast b/crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast index 2726516b8..6589e4795 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast +++ b/crates/ra_syntax/test_data/parser/inline/ok/0068_union_items.rast @@ -1,5 +1,5 @@ SOURCE_FILE@0..51 - UNION_DEF@0..12 + UNION@0..12 UNION_KW@0..5 "union" WHITESPACE@5..6 " " NAME@6..9 @@ -9,7 +9,7 @@ SOURCE_FILE@0..51 L_CURLY@10..11 "{" R_CURLY@11..12 "}" WHITESPACE@12..13 "\n" - UNION_DEF@13..50 + UNION@13..50 UNION_KW@13..18 "union" WHITESPACE@18..19 " " NAME@19..22 diff --git a/crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast b/crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast index 2aa075993..b04a505ea 100644 --- a/crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast +++ b/crates/ra_syntax/test_data/parser/ok/0035_weird_exprs.rast @@ -1560,7 +1560,7 @@ SOURCE_FILE@0..3813 BLOCK_EXPR@2845..2906 L_CURLY@2845..2846 "{" WHITESPACE@2846..2851 "\n " - UNION_DEF@2851..2904 + UNION@2851..2904 UNION_KW@2851..2856 "union" WHITESPACE@2856..2857 " " NAME@2857..2862 diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 3a0780eb5..6f9186127 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -927,7 +927,7 @@ pub(crate) fn handle_code_lens( SyntaxKind::TRAIT_DEF | SyntaxKind::STRUCT_DEF | SyntaxKind::ENUM_DEF - | SyntaxKind::UNION_DEF + | SyntaxKind::UNION ) }) .map(|it| { -- cgit v1.2.3