5601: Finalize union grammar r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-30 15:39:56 +00:00 committed by GitHub
commit 0c8944314c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 51 additions and 51 deletions

View file

@ -63,8 +63,8 @@ impl HasSource for Struct {
}
}
impl HasSource for Union {
type Ast = ast::UnionDef;
fn source(self, db: &dyn HirDatabase) -> InFile<ast::UnionDef> {
type Ast = ast::Union;
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Union> {
self.id.lookup(db.upcast()).source(db.upcast())
}
}

View file

@ -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),

View file

@ -80,7 +80,7 @@ impl SourceToDefCtx<'_, '_> {
pub(super) fn enum_to_def(&mut self, src: InFile<ast::EnumDef>) -> Option<EnumId> {
self.to_def(src, keys::ENUM)
}
pub(super) fn union_to_def(&mut self, src: InFile<ast::UnionDef>) -> Option<UnionId> {
pub(super) fn union_to_def(&mut self, src: InFile<ast::Union>) -> Option<UnionId> {
self.to_def(src, keys::UNION)
}
pub(super) fn static_to_def(&mut self, src: InFile<ast::StaticDef>) -> Option<StaticId> {
@ -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()
},

View file

@ -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())
}

View file

@ -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<ast::UnionDef>,
pub ast_id: FileAstId<ast::Union>,
}
#[derive(Debug, Clone, Eq, PartialEq)]

View file

@ -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<FileItemTreeId<Union>> {
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
let visibility = self.lower_visibility(union);
let name = union.name()?.as_name();
let generic_params = self.lower_generic_params(GenericsOwner::Union, union);

View file

@ -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::<ra_hir_def::item_tree::Variant>(0..1), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::EnumDef>(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::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UnionDef>(7) }
Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::<ra_hir_def::item_tree::Field>(3..4)), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Union>(7) }
"##]],
);
}

View file

@ -21,7 +21,7 @@ pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
pub const IMPL: Key<ast::ImplDef, ImplId> = Key::new();
pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new();
pub const STRUCT: Key<ast::StructDef, StructId> = Key::new();
pub const UNION: Key<ast::UnionDef, UnionId> = Key::new();
pub const UNION: Key<ast::Union, UnionId> = Key::new();
pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new();
pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();

View file

@ -74,7 +74,7 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, mbe::ExpandError> {
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)

View file

@ -19,7 +19,7 @@ impl ShortLabel for ast::StructDef {
}
}
impl ShortLabel for ast::UnionDef {
impl ShortLabel for ast::Union {
fn short_label(&self) -> Option<String> {
short_label_from_node(self, "union ")
}

View file

@ -127,7 +127,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
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),

View file

@ -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);

View file

@ -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,

View file

@ -154,7 +154,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, 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())))
},

View file

@ -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) {

View file

@ -124,7 +124,7 @@ pub enum SyntaxKind {
R_DOLLAR,
SOURCE_FILE,
STRUCT_DEF,
UNION_DEF,
UNION,
ENUM_DEF,
FN,
RET_TYPE,

View file

@ -199,14 +199,14 @@ impl TypeAlias {
pub fn semicolon_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![union]) }
pub fn record_field_list(&self) -> Option<RecordFieldList> { 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<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
@ -2810,8 +2810,8 @@ impl From<TraitDef> for Item {
impl From<TypeAlias> for Item {
fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) }
}
impl From<UnionDef> for Item {
fn from(node: UnionDef) -> Item { Item::UnionDef(node) }
impl From<Union> for Item {
fn from(node: Union) -> Item { Item::Union(node) }
}
impl From<Use> 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<StructDef> for AdtDef {
impl From<EnumDef> for AdtDef {
fn from(node: EnumDef) -> AdtDef { AdtDef::EnumDef(node) }
}
impl From<UnionDef> for AdtDef {
fn from(node: UnionDef) -> AdtDef { AdtDef::UnionDef(node) }
impl From<Union> 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)
}

View file

@ -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 {}

View file

@ -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

View file

@ -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

View file

@ -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| {

View file

@ -94,7 +94,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
nodes: &[
"SOURCE_FILE",
"STRUCT_DEF",
"UNION_DEF",
"UNION",
"ENUM_DEF",
"FN",
"RET_TYPE",

View file

@ -16,7 +16,7 @@ Item =
| StructDef
| TraitDef
| TypeAlias
| UnionDef
| Union
| Use
Module =
@ -98,7 +98,7 @@ FieldList =
RecordFieldList
| TupleFieldList
UnionDef =
Union =
Attr* Visibility? 'union' Name GenericParamList? WhereClause?
RecordFieldList
@ -455,7 +455,7 @@ MetaItem =
AdtDef =
StructDef
| EnumDef
| UnionDef
| Union
TypeRef =
ParenType