From 3cd4112bdc924c132cb0eab9d064511a215421ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:02:20 +0200 Subject: Finalize const&static grammar --- .../src/handlers/add_missing_impl_members.rs | 4 +- .../ra_assists/src/handlers/change_visibility.rs | 4 +- crates/ra_assists/src/utils.rs | 2 +- crates/ra_hir/src/has_source.rs | 8 +- crates/ra_hir/src/semantics.rs | 4 +- crates/ra_hir/src/semantics/source_to_def.rs | 12 +-- crates/ra_hir_def/src/body/lower.rs | 4 +- crates/ra_hir_def/src/item_tree.rs | 8 +- crates/ra_hir_def/src/item_tree/lower.rs | 16 ++-- crates/ra_hir_def/src/item_tree/tests.rs | 2 +- crates/ra_hir_def/src/keys.rs | 4 +- .../ra_ide/src/completion/complete_trait_impl.rs | 8 +- crates/ra_ide/src/display.rs | 2 +- crates/ra_ide/src/display/navigation_target.rs | 8 +- crates/ra_ide/src/display/short_label.rs | 4 +- crates/ra_ide/src/file_structure.rs | 8 +- crates/ra_ide/src/syntax_highlighting.rs | 4 +- crates/ra_ide_db/src/defs.rs | 4 +- crates/ra_ide_db/src/symbol_index.rs | 4 +- crates/ra_parser/src/grammar/items/consts.rs | 4 +- crates/ra_parser/src/syntax_kind/generated.rs | 4 +- crates/ra_syntax/src/ast.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 85 +++++++++++----------- crates/ra_syntax/src/ast/node_ext.rs | 4 +- crates/ra_syntax/src/parsing/text_tree_sink.rs | 4 +- crates/ra_syntax/src/validation.rs | 4 +- .../parser/err/0037_visibility_in_traits.rast | 2 +- .../test_data/parser/err/0043_default_const.rast | 2 +- .../parser/inline/err/0010_wrong_order_fns.rast | 2 +- .../parser/inline/err/0013_static_underscore.rast | 2 +- .../parser/inline/ok/0001_trait_item_list.rast | 2 +- .../parser/inline/ok/0021_impl_item_list.rast | 2 +- .../parser/inline/ok/0150_array_attrs.rast | 2 +- .../test_data/parser/ok/0023_static_items.rast | 4 +- .../test_data/parser/ok/0024_const_item.rast | 6 +- .../test_data/parser/ok/0066_default_const.rast | 2 +- crates/rust-analyzer/src/to_proto.rs | 4 +- xtask/src/ast_src.rs | 4 +- xtask/src/codegen/rust.ungram | 24 +++--- 39 files changed, 138 insertions(+), 137 deletions(-) diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index 1e4d4748c..1ab176c26 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs @@ -120,7 +120,7 @@ fn add_missing_impl_members_inner( match item { ast::AssocItem::Fn(def) => def.name(), ast::AssocItem::TypeAlias(def) => def.name(), - ast::AssocItem::ConstDef(def) => def.name(), + ast::AssocItem::Const(def) => def.name(), ast::AssocItem::MacroCall(_) => None, } .map(|it| it.text().clone()) @@ -131,7 +131,7 @@ fn add_missing_impl_members_inner( .map(|i| match i { hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(ctx.db()).value), hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(ctx.db()).value), - hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db()).value), + hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(ctx.db()).value), }) .filter(|t| def_name(&t).is_some()) .filter(|t| match t { diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index 44f3e8ee3..76144d7d2 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs @@ -1,7 +1,7 @@ use ra_syntax::{ ast::{self, NameOwner, VisibilityOwner}, AstNode, - SyntaxKind::{CONST_DEF, ENUM, FN, MODULE, STATIC_DEF, STRUCT, TRAIT_DEF, VISIBILITY}, + SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT_DEF, VISIBILITY}, T, }; use test_utils::mark; @@ -36,7 +36,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let (offset, target) = if let Some(keyword) = item_keyword { let parent = keyword.parent(); - let def_kws = vec![CONST_DEF, STATIC_DEF, FN, MODULE, STRUCT, ENUM, TRAIT_DEF]; + let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT_DEF]; // Parent is not a definition, can't add visibility if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) { return None; diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 748be011b..337e3474f 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs @@ -78,7 +78,7 @@ pub fn get_missing_assoc_items( } } - ast::AssocItem::ConstDef(c) => { + ast::AssocItem::Const(c) => { if let Some(n) = c.name() { impl_fns_consts.insert(n.syntax().to_string()); } diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 1c5747581..9581552e5 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs @@ -87,14 +87,14 @@ impl HasSource for Function { } } impl HasSource for Const { - type Ast = ast::ConstDef; - fn source(self, db: &dyn HirDatabase) -> InFile { + type Ast = ast::Const; + fn source(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Static { - type Ast = ast::StaticDef; - fn source(self, db: &dyn HirDatabase) -> InFile { + type Ast = ast::Static; + 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 e18df2537..32a60b789 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -586,8 +586,8 @@ to_def_impls![ (crate::Trait, ast::TraitDef, trait_to_def), (crate::ImplDef, ast::ImplDef, impl_to_def), (crate::TypeAlias, ast::TypeAlias, type_alias_to_def), - (crate::Const, ast::ConstDef, const_to_def), - (crate::Static, ast::StaticDef, static_to_def), + (crate::Const, ast::Const, const_to_def), + (crate::Static, ast::Static, static_to_def), (crate::Function, ast::Fn, fn_to_def), (crate::Field, ast::RecordField, record_field_to_def), (crate::Field, ast::TupleField, tuple_field_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 b85a12680..782a03f9e 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -83,10 +83,10 @@ impl SourceToDefCtx<'_, '_> { 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 { + pub(super) fn static_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::STATIC) } - pub(super) fn const_to_def(&mut self, src: InFile) -> Option { + pub(super) fn const_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::CONST) } pub(super) fn type_alias_to_def(&mut self, src: InFile) -> Option { @@ -178,11 +178,11 @@ impl SourceToDefCtx<'_, '_> { let def = self.union_to_def(container.with_value(it))?; VariantId::from(def).into() }, - ast::StaticDef(it) => { + ast::Static(it) => { let def = self.static_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, - ast::ConstDef(it) => { + ast::Const(it) => { let def = self.const_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, @@ -222,8 +222,8 @@ impl SourceToDefCtx<'_, '_> { for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { let res: DefWithBodyId = match_ast! { match (container.value) { - ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(), - ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(), + ast::Const(it) => self.const_to_def(container.with_value(it))?.into(), + ast::Static(it) => self.static_to_def(container.with_value(it))?.into(), ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), _ => continue, } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 105299f70..4a26e6397 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -641,14 +641,14 @@ impl ExprCollector<'_> { def.name(), ) } - ast::Item::ConstDef(def) => { + ast::Item::Const(def) => { let id = self.find_inner_item(&def)?; ( ConstLoc { container: container.into(), id }.intern(self.db).into(), def.name(), ) } - ast::Item::StaticDef(def) => { + ast::Item::Static(def) => { let id = self.find_inner_item(&def)?; (StaticLoc { 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 24ad41187..c478a9909 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -417,8 +417,8 @@ mod_items! { Struct in structs -> ast::Struct, Union in unions -> ast::Union, Enum in enums -> ast::Enum, - Const in consts -> ast::ConstDef, - Static in statics -> ast::StaticDef, + Const in consts -> ast::Const, + Static in statics -> ast::Static, Trait in traits -> ast::TraitDef, Impl in impls -> ast::ImplDef, TypeAlias in type_aliases -> ast::TypeAlias, @@ -552,7 +552,7 @@ pub struct Const { pub name: Option, pub visibility: RawVisibilityId, pub type_ref: TypeRef, - pub ast_id: FileAstId, + pub ast_id: FileAstId, } #[derive(Debug, Clone, Eq, PartialEq)] @@ -561,7 +561,7 @@ pub struct Static { pub visibility: RawVisibilityId, pub mutable: bool, pub type_ref: TypeRef, - 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 6d963c852..a94548e5d 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -83,8 +83,8 @@ impl Ctx { | ast::Item::Enum(_) | ast::Item::Fn(_) | ast::Item::TypeAlias(_) - | ast::Item::ConstDef(_) - | ast::Item::StaticDef(_) + | ast::Item::Const(_) + | ast::Item::Static(_) | ast::Item::MacroCall(_) => { // Skip this if we're already collecting inner items. We'll descend into all nodes // already. @@ -108,8 +108,8 @@ impl Ctx { ast::Item::Enum(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), - ast::Item::StaticDef(ast) => self.lower_static(ast).map(Into::into), - ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()), + ast::Item::Static(ast) => self.lower_static(ast).map(Into::into), + ast::Item::Const(ast) => Some(self.lower_const(ast).into()), ast::Item::Module(ast) => self.lower_module(ast).map(Into::into), ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into), ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into), @@ -160,7 +160,7 @@ impl Ctx { match item { ast::AssocItem::Fn(ast) => self.lower_function(ast).map(Into::into), ast::AssocItem::TypeAlias(ast) => self.lower_type_alias(ast).map(Into::into), - ast::AssocItem::ConstDef(ast) => Some(self.lower_const(ast).into()), + ast::AssocItem::Const(ast) => Some(self.lower_const(ast).into()), ast::AssocItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into), } } @@ -368,7 +368,7 @@ impl Ctx { Some(id(self.data().type_aliases.alloc(res))) } - fn lower_static(&mut self, static_: &ast::StaticDef) -> Option> { + fn lower_static(&mut self, static_: &ast::Static) -> Option> { let name = static_.name()?.as_name(); let type_ref = self.lower_type_ref_opt(static_.ascribed_type()); let visibility = self.lower_visibility(static_); @@ -378,7 +378,7 @@ impl Ctx { Some(id(self.data().statics.alloc(res))) } - fn lower_const(&mut self, konst: &ast::ConstDef) -> FileItemTreeId { + fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId { let name = konst.name().map(|it| it.as_name()); let type_ref = self.lower_type_ref_opt(konst.ascribed_type()); let visibility = self.lower_visibility(konst); @@ -553,7 +553,7 @@ impl Ctx { self.data().functions[func.index].is_unsafe = true; func.into() } - ast::ExternItem::StaticDef(ast) => { + ast::ExternItem::Static(ast) => { let statik = self.lower_static(&ast)?; statik.into() } diff --git a/crates/ra_hir_def/src/item_tree/tests.rs b/crates/ra_hir_def/src/item_tree/tests.rs index bf3474c51..e61ce58bc 100644 --- a/crates/ra_hir_def/src/item_tree/tests.rs +++ b/crates/ra_hir_def/src/item_tree/tests.rs @@ -238,7 +238,7 @@ fn smoke() { > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }] > TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::(8) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }] - > Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::(9) } + > Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::(9) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }] > Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(10) } > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }] diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index c2a03dfed..f75e3bb50 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs @@ -15,8 +15,8 @@ use crate::{ pub type Key = crate::dyn_map::Key, V, AstPtrPolicy>; pub const FUNCTION: Key = Key::new(); -pub const CONST: Key = Key::new(); -pub const STATIC: Key = Key::new(); +pub const CONST: Key = Key::new(); +pub const STATIC: Key = Key::new(); pub const TYPE_ALIAS: Key = Key::new(); pub const IMPL: Key = Key::new(); pub const TRAIT: Key = Key::new(); diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 7d9050a6b..88679f3bd 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -87,7 +87,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } - SyntaxKind::CONST_DEF => { + SyntaxKind::CONST => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -108,7 +108,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN | SyntaxKind::TYPE_ALIAS - | SyntaxKind::CONST_DEF + | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => Some((p, 2)), SyntaxKind::NAME_REF => Some((p, 5)), _ => None, @@ -201,7 +201,7 @@ fn add_const_impl( } } -fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { +fn make_const_compl_syntax(const_: &ast::Const) -> String { let const_ = edit::remove_attrs_and_docs(const_); let const_start = const_.syntax().text_range().start(); diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index e81e8436f..3efca0649 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -54,7 +54,7 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String { buf } -pub(crate) fn const_label(node: &ast::ConstDef) -> String { +pub(crate) fn const_label(node: &ast::Const) -> String { let label: String = node .syntax() .children_with_tokens() diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index c30b91fe0..9e2c01245 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -385,8 +385,8 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), - ast::ConstDef(it) => it.doc_comment_text(), - ast::StaticDef(it) => it.doc_comment_text(), + ast::Const(it) => it.doc_comment_text(), + ast::Static(it) => it.doc_comment_text(), ast::RecordField(it) => it.doc_comment_text(), ast::Variant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), @@ -410,8 +410,8 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), - ast::ConstDef(it) => it.short_label(), - ast::StaticDef(it) => it.short_label(), + ast::Const(it) => it.short_label(), + ast::Static(it) => it.short_label(), ast::RecordField(it) => it.short_label(), ast::Variant(it) => it.short_label(), _ => None, diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index ddf1059ee..282f362f2 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -53,13 +53,13 @@ impl ShortLabel for ast::TypeAlias { } } -impl ShortLabel for ast::ConstDef { +impl ShortLabel for ast::Const { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "const ") } } -impl ShortLabel for ast::StaticDef { +impl ShortLabel for ast::Static { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "static ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 43202499d..77384b6ec 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -137,8 +137,8 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_type_ref(it, ty) }, ast::RecordField(it) => decl_with_ascription(it), - ast::ConstDef(it) => decl_with_ascription(it), - ast::StaticDef(it) => decl_with_ascription(it), + ast::Const(it) => decl_with_ascription(it), + ast::Static(it) => decl_with_ascription(it), ast::ImplDef(it) => { let target_type = it.target_type()?; let target_trait = it.target_trait(); @@ -350,7 +350,7 @@ fn very_obsolete() {} label: "S", navigation_range: 201..202, node_range: 194..213, - kind: STATIC_DEF, + kind: STATIC, detail: Some( "i32", ), @@ -361,7 +361,7 @@ fn very_obsolete() {} label: "C", navigation_range: 220..221, node_range: 214..232, - kind: CONST_DEF, + kind: CONST, detail: Some( "i32", ), diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index ce890c816..19ec73d2a 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -714,8 +714,8 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { RECORD_FIELD => HighlightTag::Field, MODULE => HighlightTag::Module, FN => HighlightTag::Function, - CONST_DEF => HighlightTag::Constant, - STATIC_DEF => HighlightTag::Static, + CONST => HighlightTag::Constant, + STATIC => HighlightTag::Static, VARIANT => HighlightTag::EnumVariant, BIND_PAT => HighlightTag::Local, _ => default, diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 635cf706c..b908bd741 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -166,7 +166,7 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option let def: hir::Trait = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, - ast::StaticDef(it) => { + ast::Static(it) => { let def: hir::Static = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, @@ -178,7 +178,7 @@ pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option let def: hir::Function = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, - ast::ConstDef(it) => { + ast::Const(it) => { let def: hir::Const = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index 646d338ae..41b8d07f4 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs @@ -403,8 +403,8 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { ast::TraitDef(it) => decl(it), ast::Module(it) => decl(it), ast::TypeAlias(it) => decl(it), - ast::ConstDef(it) => decl(it), - ast::StaticDef(it) => decl(it), + ast::Const(it) => decl(it), + ast::Static(it) => decl(it), ast::MacroCall(it) => { if it.is_macro_rules().is_some() { decl(it) diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs index 742a7e056..35ad766dc 100644 --- a/crates/ra_parser/src/grammar/items/consts.rs +++ b/crates/ra_parser/src/grammar/items/consts.rs @@ -3,11 +3,11 @@ use super::*; pub(super) fn static_def(p: &mut Parser, m: Marker) { - const_or_static(p, m, T![static], STATIC_DEF) + const_or_static(p, m, T![static], STATIC) } pub(super) fn const_def(p: &mut Parser, m: Marker) { - const_or_static(p, m, T![const], CONST_DEF) + const_or_static(p, m, T![const], CONST) } fn const_or_static(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 3b82347f3..64889676e 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -131,8 +131,8 @@ pub enum SyntaxKind { EXTERN_CRATE, MODULE, USE, - STATIC_DEF, - CONST_DEF, + STATIC, + CONST, TRAIT_DEF, IMPL_DEF, TYPE_ALIAS, diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index b69b6e85e..fd426ece9 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -139,7 +139,7 @@ fn test_doc_comment_of_statics() { ) .ok() .unwrap(); - let st = file.syntax().descendants().find_map(StaticDef::cast).unwrap(); + let st = file.syntax().descendants().find_map(Static::cast).unwrap(); assert_eq!("Number of levels", st.doc_comment_text().unwrap()); } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 6613b54ba..00a70fce0 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -28,16 +28,17 @@ impl Attr { pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ConstDef { +pub struct Const { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for ConstDef {} -impl ast::NameOwner for ConstDef {} -impl ast::VisibilityOwner for ConstDef {} -impl ast::TypeAscriptionOwner for ConstDef {} -impl ConstDef { +impl ast::AttrsOwner for Const {} +impl ast::NameOwner for Const {} +impl ast::VisibilityOwner for Const {} +impl ast::TypeAscriptionOwner for Const {} +impl Const { pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } pub fn body(&self) -> Option { support::child(&self.syntax) } @@ -139,14 +140,14 @@ impl Module { pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct StaticDef { +pub struct Static { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for StaticDef {} -impl ast::NameOwner for StaticDef {} -impl ast::VisibilityOwner for StaticDef {} -impl ast::TypeAscriptionOwner for StaticDef {} -impl StaticDef { +impl ast::AttrsOwner for Static {} +impl ast::NameOwner for Static {} +impl ast::VisibilityOwner for Static {} +impl ast::TypeAscriptionOwner for Static {} +impl Static { pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } @@ -1272,7 +1273,7 @@ impl MetaItem { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Item { - ConstDef(ConstDef), + Const(Const), Enum(Enum), ExternBlock(ExternBlock), ExternCrate(ExternCrate), @@ -1280,7 +1281,7 @@ pub enum Item { ImplDef(ImplDef), MacroCall(MacroCall), Module(Module), - StaticDef(StaticDef), + Static(Static), Struct(Struct), TraitDef(TraitDef), TypeAlias(TypeAlias), @@ -1365,7 +1366,7 @@ pub enum Expr { pub enum AssocItem { Fn(Fn), TypeAlias(TypeAlias), - ConstDef(ConstDef), + Const(Const), MacroCall(MacroCall), } impl ast::AttrsOwner for AssocItem {} @@ -1384,7 +1385,7 @@ pub enum AttrInput { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ExternItem { Fn(Fn), - StaticDef(StaticDef), + Static(Static), } impl ast::AttrsOwner for ExternItem {} impl ast::NameOwner for ExternItem {} @@ -1421,8 +1422,8 @@ impl AstNode for Attr { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ConstDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } +impl AstNode for Const { + fn can_cast(kind: SyntaxKind) -> bool { kind == CONST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1509,8 +1510,8 @@ impl AstNode for Module { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for StaticDef { - fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC_DEF } +impl AstNode for Static { + fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2774,8 +2775,8 @@ impl AstNode for MetaItem { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl From for Item { - fn from(node: ConstDef) -> Item { Item::ConstDef(node) } +impl From for Item { + fn from(node: Const) -> Item { Item::Const(node) } } impl From for Item { fn from(node: Enum) -> Item { Item::Enum(node) } @@ -2798,8 +2799,8 @@ impl From for Item { impl From for Item { fn from(node: Module) -> Item { Item::Module(node) } } -impl From for Item { - fn from(node: StaticDef) -> Item { Item::StaticDef(node) } +impl From for Item { + fn from(node: Static) -> Item { Item::Static(node) } } impl From for Item { fn from(node: Struct) -> Item { Item::Struct(node) } @@ -2819,14 +2820,14 @@ impl From for Item { impl AstNode for Item { fn can_cast(kind: SyntaxKind) -> bool { match kind { - CONST_DEF | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL - | MODULE | STATIC_DEF | STRUCT | TRAIT_DEF | TYPE_ALIAS | UNION | USE => true, + CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL_DEF | MACRO_CALL | MODULE + | STATIC | STRUCT | TRAIT_DEF | TYPE_ALIAS | UNION | USE => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - CONST_DEF => Item::ConstDef(ConstDef { syntax }), + CONST => Item::Const(Const { syntax }), ENUM => Item::Enum(Enum { syntax }), EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), @@ -2834,7 +2835,7 @@ impl AstNode for Item { IMPL_DEF => Item::ImplDef(ImplDef { syntax }), MACRO_CALL => Item::MacroCall(MacroCall { syntax }), MODULE => Item::Module(Module { syntax }), - STATIC_DEF => Item::StaticDef(StaticDef { syntax }), + STATIC => Item::Static(Static { syntax }), STRUCT => Item::Struct(Struct { syntax }), TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }), @@ -2846,7 +2847,7 @@ impl AstNode for Item { } fn syntax(&self) -> &SyntaxNode { match self { - Item::ConstDef(it) => &it.syntax, + Item::Const(it) => &it.syntax, Item::Enum(it) => &it.syntax, Item::ExternBlock(it) => &it.syntax, Item::ExternCrate(it) => &it.syntax, @@ -2854,7 +2855,7 @@ impl AstNode for Item { Item::ImplDef(it) => &it.syntax, Item::MacroCall(it) => &it.syntax, Item::Module(it) => &it.syntax, - Item::StaticDef(it) => &it.syntax, + Item::Static(it) => &it.syntax, Item::Struct(it) => &it.syntax, Item::TraitDef(it) => &it.syntax, Item::TypeAlias(it) => &it.syntax, @@ -3256,8 +3257,8 @@ impl From for AssocItem { impl From for AssocItem { fn from(node: TypeAlias) -> AssocItem { AssocItem::TypeAlias(node) } } -impl From for AssocItem { - fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } +impl From for AssocItem { + fn from(node: Const) -> AssocItem { AssocItem::Const(node) } } impl From for AssocItem { fn from(node: MacroCall) -> AssocItem { AssocItem::MacroCall(node) } @@ -3265,7 +3266,7 @@ impl From for AssocItem { impl AstNode for AssocItem { fn can_cast(kind: SyntaxKind) -> bool { match kind { - FN | TYPE_ALIAS | CONST_DEF | MACRO_CALL => true, + FN | TYPE_ALIAS | CONST | MACRO_CALL => true, _ => false, } } @@ -3273,7 +3274,7 @@ impl AstNode for AssocItem { let res = match syntax.kind() { FN => AssocItem::Fn(Fn { syntax }), TYPE_ALIAS => AssocItem::TypeAlias(TypeAlias { syntax }), - CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), + CONST => AssocItem::Const(Const { syntax }), MACRO_CALL => AssocItem::MacroCall(MacroCall { syntax }), _ => return None, }; @@ -3283,7 +3284,7 @@ impl AstNode for AssocItem { match self { AssocItem::Fn(it) => &it.syntax, AssocItem::TypeAlias(it) => &it.syntax, - AssocItem::ConstDef(it) => &it.syntax, + AssocItem::Const(it) => &it.syntax, AssocItem::MacroCall(it) => &it.syntax, } } @@ -3347,20 +3348,20 @@ impl AstNode for AttrInput { impl From for ExternItem { fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) } } -impl From for ExternItem { - fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } +impl From for ExternItem { + fn from(node: Static) -> ExternItem { ExternItem::Static(node) } } impl AstNode for ExternItem { fn can_cast(kind: SyntaxKind) -> bool { match kind { - FN | STATIC_DEF => true, + FN | STATIC => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { FN => ExternItem::Fn(Fn { syntax }), - STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), + STATIC => ExternItem::Static(Static { syntax }), _ => return None, }; Some(res) @@ -3368,7 +3369,7 @@ impl AstNode for ExternItem { fn syntax(&self) -> &SyntaxNode { match self { ExternItem::Fn(it) => &it.syntax, - ExternItem::StaticDef(it) => &it.syntax, + ExternItem::Static(it) => &it.syntax, } } } @@ -3465,7 +3466,7 @@ impl std::fmt::Display for Attr { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ConstDef { +impl std::fmt::Display for Const { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3505,7 +3506,7 @@ impl std::fmt::Display for Module { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for StaticDef { +impl std::fmt::Display for Static { 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 05ec49cec..4da1d5c11 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -483,8 +483,8 @@ impl ast::DocCommentsOwner for ast::Enum {} impl ast::DocCommentsOwner for ast::Variant {} impl ast::DocCommentsOwner for ast::TraitDef {} impl ast::DocCommentsOwner for ast::Module {} -impl ast::DocCommentsOwner for ast::StaticDef {} -impl ast::DocCommentsOwner for ast::ConstDef {} +impl ast::DocCommentsOwner for ast::Static {} +impl ast::DocCommentsOwner for ast::Const {} impl ast::DocCommentsOwner for ast::TypeAlias {} impl ast::DocCommentsOwner for ast::ImplDef {} impl ast::DocCommentsOwner for ast::MacroCall {} diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs index c586dc320..f7edd86ce 100644 --- a/crates/ra_syntax/src/parsing/text_tree_sink.rs +++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs @@ -146,8 +146,8 @@ fn n_attached_trivias<'a>( trivias: impl Iterator, ) -> usize { match kind { - MACRO_CALL | CONST_DEF | TYPE_ALIAS | STRUCT | ENUM | VARIANT | FN | TRAIT_DEF - | MODULE | RECORD_FIELD | STATIC_DEF => { + MACRO_CALL | CONST | TYPE_ALIAS | STRUCT | ENUM | VARIANT | FN | TRAIT_DEF + | MODULE | RECORD_FIELD | STATIC => { let mut res = 0; let mut trivias = trivias.enumerate().peekable(); diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 5b4e14676..a666b18db 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -4,7 +4,7 @@ mod block; use crate::{ ast, match_ast, AstNode, SyntaxError, - SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST_DEF, FN, INT_NUMBER, STRING, TYPE_ALIAS}, + SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST, FN, INT_NUMBER, STRING, TYPE_ALIAS}, SyntaxNode, SyntaxToken, TextSize, T, }; use rustc_lexer::unescape::{ @@ -200,7 +200,7 @@ fn validate_visibility(vis: ast::Visibility, errors: &mut Vec) { None => return, }; match parent.kind() { - FN | CONST_DEF | TYPE_ALIAS => (), + FN | CONST | TYPE_ALIAS => (), _ => return, } diff --git a/crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast b/crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast index c0ba4fba9..b1400aa5f 100644 --- a/crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast +++ b/crates/ra_syntax/test_data/parser/err/0037_visibility_in_traits.rast @@ -65,7 +65,7 @@ SOURCE_FILE@0..118 R_PAREN@79..80 ")" SEMICOLON@80..81 ";" WHITESPACE@81..86 "\n " - CONST_DEF@86..115 + CONST@86..115 VISIBILITY@86..96 PUB_KW@86..89 "pub" L_PAREN@89..90 "(" diff --git a/crates/ra_syntax/test_data/parser/err/0043_default_const.rast b/crates/ra_syntax/test_data/parser/err/0043_default_const.rast index 6ca1a4870..f041fa6f7 100644 --- a/crates/ra_syntax/test_data/parser/err/0043_default_const.rast +++ b/crates/ra_syntax/test_data/parser/err/0043_default_const.rast @@ -14,7 +14,7 @@ SOURCE_FILE@0..39 NAME_REF@12..19 IDENT@12..19 "default" WHITESPACE@19..20 " " - CONST_DEF@20..36 + CONST@20..36 CONST_KW@20..25 "const" WHITESPACE@25..26 " " NAME@26..27 diff --git a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast b/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast index d2a18330f..a6e6552a9 100644 --- a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast +++ b/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast @@ -17,7 +17,7 @@ SOURCE_FILE@0..50 L_CURLY@22..23 "{" R_CURLY@23..24 "}" WHITESPACE@24..25 "\n" - CONST_DEF@25..46 + CONST@25..46 UNSAFE_KW@25..31 "unsafe" WHITESPACE@31..32 " " CONST_KW@32..37 "const" diff --git a/crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast b/crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast index ebcc26e0d..8d761b907 100644 --- a/crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast +++ b/crates/ra_syntax/test_data/parser/inline/err/0013_static_underscore.rast @@ -1,5 +1,5 @@ SOURCE_FILE@0..19 - STATIC_DEF@0..18 + STATIC@0..18 STATIC_KW@0..6 "static" WHITESPACE@6..7 " " ERROR@7..8 diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast b/crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast index a62ce23e6..955e00dde 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast +++ b/crates/ra_syntax/test_data/parser/inline/ok/0001_trait_item_list.rast @@ -27,7 +27,7 @@ SOURCE_FILE@0..83 IDENT@21..26 "Clone" SEMICOLON@26..27 ";" WHITESPACE@27..32 "\n " - CONST_DEF@32..45 + CONST@32..45 CONST_KW@32..37 "const" WHITESPACE@37..38 " " NAME@38..39 diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast b/crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast index 3ae870e17..52181ca0c 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast +++ b/crates/ra_syntax/test_data/parser/inline/ok/0021_impl_item_list.rast @@ -26,7 +26,7 @@ SOURCE_FILE@0..89 IDENT@22..25 "i32" SEMICOLON@25..26 ";" WHITESPACE@26..31 "\n " - CONST_DEF@31..49 + CONST@31..49 CONST_KW@31..36 "const" WHITESPACE@36..37 " " NAME@37..38 diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast b/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast index 3c00a2647..0c35bf2b7 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast +++ b/crates/ra_syntax/test_data/parser/inline/ok/0150_array_attrs.rast @@ -1,5 +1,5 @@ SOURCE_FILE@0..40 - CONST_DEF@0..39 + CONST@0..39 CONST_KW@0..5 "const" WHITESPACE@5..6 " " NAME@6..7 diff --git a/crates/ra_syntax/test_data/parser/ok/0023_static_items.rast b/crates/ra_syntax/test_data/parser/ok/0023_static_items.rast index 97d90dc75..9374cf5e9 100644 --- a/crates/ra_syntax/test_data/parser/ok/0023_static_items.rast +++ b/crates/ra_syntax/test_data/parser/ok/0023_static_items.rast @@ -1,5 +1,5 @@ SOURCE_FILE@0..47 - STATIC_DEF@0..20 + STATIC@0..20 STATIC_KW@0..6 "static" WHITESPACE@6..7 " " NAME@7..10 @@ -18,7 +18,7 @@ SOURCE_FILE@0..47 INT_NUMBER@18..19 "1" SEMICOLON@19..20 ";" WHITESPACE@20..21 "\n" - STATIC_DEF@21..46 + STATIC@21..46 STATIC_KW@21..27 "static" WHITESPACE@27..28 " " MUT_KW@28..31 "mut" diff --git a/crates/ra_syntax/test_data/parser/ok/0024_const_item.rast b/crates/ra_syntax/test_data/parser/ok/0024_const_item.rast index d241f034c..dd1b9c9a0 100644 --- a/crates/ra_syntax/test_data/parser/ok/0024_const_item.rast +++ b/crates/ra_syntax/test_data/parser/ok/0024_const_item.rast @@ -1,5 +1,5 @@ SOURCE_FILE@0..64 - CONST_DEF@0..17 + CONST@0..17 CONST_KW@0..5 "const" WHITESPACE@5..6 " " UNDERSCORE@6..7 "_" @@ -17,7 +17,7 @@ SOURCE_FILE@0..64 INT_NUMBER@15..16 "0" SEMICOLON@16..17 ";" WHITESPACE@17..18 "\n" - CONST_DEF@18..38 + CONST@18..38 CONST_KW@18..23 "const" WHITESPACE@23..24 " " NAME@24..27 @@ -36,7 +36,7 @@ SOURCE_FILE@0..64 INT_NUMBER@35..37 "92" SEMICOLON@37..38 ";" WHITESPACE@38..39 "\n" - CONST_DEF@39..63 + CONST@39..63 CONST_KW@39..44 "const" WHITESPACE@44..45 " " MUT_KW@45..48 "mut" diff --git a/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast b/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast index 584b2faf1..485efe20c 100644 --- a/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast +++ b/crates/ra_syntax/test_data/parser/ok/0066_default_const.rast @@ -19,7 +19,7 @@ SOURCE_FILE@0..46 ASSOC_ITEM_LIST@15..45 L_CURLY@15..16 "{" WHITESPACE@16..19 "\n " - CONST_DEF@19..43 + CONST@19..43 DEFAULT_KW@19..26 "default" WHITESPACE@26..27 " " CONST_KW@27..32 "const" diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index dcd81da6e..fd5123301 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -40,8 +40,8 @@ pub(crate) fn symbol_kind(syntax_kind: SyntaxKind) -> lsp_types::SymbolKind { SyntaxKind::MODULE => lsp_types::SymbolKind::Module, SyntaxKind::TYPE_ALIAS => lsp_types::SymbolKind::TypeParameter, SyntaxKind::RECORD_FIELD => lsp_types::SymbolKind::Field, - SyntaxKind::STATIC_DEF => lsp_types::SymbolKind::Constant, - SyntaxKind::CONST_DEF => lsp_types::SymbolKind::Constant, + SyntaxKind::STATIC => lsp_types::SymbolKind::Constant, + SyntaxKind::CONST => lsp_types::SymbolKind::Constant, SyntaxKind::IMPL_DEF => lsp_types::SymbolKind::Object, _ => lsp_types::SymbolKind::Variable, } diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 94f4d17aa..56e3f4b0a 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -101,8 +101,8 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc { "EXTERN_CRATE", "MODULE", "USE", - "STATIC_DEF", - "CONST_DEF", + "STATIC", + "CONST", "TRAIT_DEF", "IMPL_DEF", "TYPE_ALIAS", diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index b653c14a7..ef7c3e50e 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -4,7 +4,7 @@ SourceFile = Item* Item = - ConstDef + Const | Enum | ExternBlock | ExternCrate @@ -12,7 +12,7 @@ Item = | ImplDef | MacroCall | Module -| StaticDef +| Static | Struct | TraitDef | TypeAlias @@ -112,6 +112,14 @@ Union = Attr* Visibility? 'union' Name GenericParamList? WhereClause? RecordFieldList +Const = + Attr* Visibility? 'default'? 'const' (Name | '_') ':' ascribed_type:TypeRef + '=' body:Expr ';' + +Static = + Attr* Visibility? 'static'? 'mut'? Name ':' ascribed_type:TypeRef + '=' body:Expr ';' + TraitDef = Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name GenericParamList (':' TypeBoundList?)? WhereClause @@ -120,14 +128,6 @@ TraitDef = AssocItemList = '{' AssocItem* '}' -ConstDef = - Attr* Visibility? 'default'? 'const' Name ':' ascribed_type:TypeRef - '=' body:Expr ';' - -StaticDef = - Attr* Visibility? 'static'? 'mut'? 'static' Name ':' ascribed_type:TypeRef - '=' body:Expr ';' - ImplDef = Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' GenericParamList? '!'? 'for' WhereClause? @@ -475,11 +475,11 @@ TypeRef = AssocItem = Fn | TypeAlias -| ConstDef +| Const | MacroCall ExternItem = - Fn | StaticDef + Fn | Static AttrInput = Literal -- cgit v1.2.3