Skip to content

Commit 3cd4112

Browse files
committed
Finalize const&static grammar
1 parent 6b25f64 commit 3cd4112

39 files changed

+138
-137
lines changed

crates/ra_assists/src/handlers/add_missing_impl_members.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn add_missing_impl_members_inner(
120120
match item {
121121
ast::AssocItem::Fn(def) => def.name(),
122122
ast::AssocItem::TypeAlias(def) => def.name(),
123-
ast::AssocItem::ConstDef(def) => def.name(),
123+
ast::AssocItem::Const(def) => def.name(),
124124
ast::AssocItem::MacroCall(_) => None,
125125
}
126126
.map(|it| it.text().clone())
@@ -131,7 +131,7 @@ fn add_missing_impl_members_inner(
131131
.map(|i| match i {
132132
hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(ctx.db()).value),
133133
hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(ctx.db()).value),
134-
hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db()).value),
134+
hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(ctx.db()).value),
135135
})
136136
.filter(|t| def_name(&t).is_some())
137137
.filter(|t| match t {

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ra_syntax::{
22
ast::{self, NameOwner, VisibilityOwner},
33
AstNode,
4-
SyntaxKind::{CONST_DEF, ENUM, FN, MODULE, STATIC_DEF, STRUCT, TRAIT_DEF, VISIBILITY},
4+
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT_DEF, VISIBILITY},
55
T,
66
};
77
use test_utils::mark;
@@ -36,7 +36,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
3636

3737
let (offset, target) = if let Some(keyword) = item_keyword {
3838
let parent = keyword.parent();
39-
let def_kws = vec![CONST_DEF, STATIC_DEF, FN, MODULE, STRUCT, ENUM, TRAIT_DEF];
39+
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT_DEF];
4040
// Parent is not a definition, can't add visibility
4141
if !def_kws.iter().any(|&def_kw| def_kw == parent.kind()) {
4242
return None;

crates/ra_assists/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn get_missing_assoc_items(
7878
}
7979
}
8080

81-
ast::AssocItem::ConstDef(c) => {
81+
ast::AssocItem::Const(c) => {
8282
if let Some(n) = c.name() {
8383
impl_fns_consts.insert(n.syntax().to_string());
8484
}

crates/ra_hir/src/has_source.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ impl HasSource for Function {
8787
}
8888
}
8989
impl HasSource for Const {
90-
type Ast = ast::ConstDef;
91-
fn source(self, db: &dyn HirDatabase) -> InFile<ast::ConstDef> {
90+
type Ast = ast::Const;
91+
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Const> {
9292
self.id.lookup(db.upcast()).source(db.upcast())
9393
}
9494
}
9595
impl HasSource for Static {
96-
type Ast = ast::StaticDef;
97-
fn source(self, db: &dyn HirDatabase) -> InFile<ast::StaticDef> {
96+
type Ast = ast::Static;
97+
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Static> {
9898
self.id.lookup(db.upcast()).source(db.upcast())
9999
}
100100
}

crates/ra_hir/src/semantics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ to_def_impls![
586586
(crate::Trait, ast::TraitDef, trait_to_def),
587587
(crate::ImplDef, ast::ImplDef, impl_to_def),
588588
(crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
589-
(crate::Const, ast::ConstDef, const_to_def),
590-
(crate::Static, ast::StaticDef, static_to_def),
589+
(crate::Const, ast::Const, const_to_def),
590+
(crate::Static, ast::Static, static_to_def),
591591
(crate::Function, ast::Fn, fn_to_def),
592592
(crate::Field, ast::RecordField, record_field_to_def),
593593
(crate::Field, ast::TupleField, tuple_field_to_def),

crates/ra_hir/src/semantics/source_to_def.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ impl SourceToDefCtx<'_, '_> {
8383
pub(super) fn union_to_def(&mut self, src: InFile<ast::Union>) -> Option<UnionId> {
8484
self.to_def(src, keys::UNION)
8585
}
86-
pub(super) fn static_to_def(&mut self, src: InFile<ast::StaticDef>) -> Option<StaticId> {
86+
pub(super) fn static_to_def(&mut self, src: InFile<ast::Static>) -> Option<StaticId> {
8787
self.to_def(src, keys::STATIC)
8888
}
89-
pub(super) fn const_to_def(&mut self, src: InFile<ast::ConstDef>) -> Option<ConstId> {
89+
pub(super) fn const_to_def(&mut self, src: InFile<ast::Const>) -> Option<ConstId> {
9090
self.to_def(src, keys::CONST)
9191
}
9292
pub(super) fn type_alias_to_def(&mut self, src: InFile<ast::TypeAlias>) -> Option<TypeAliasId> {
@@ -178,11 +178,11 @@ impl SourceToDefCtx<'_, '_> {
178178
let def = self.union_to_def(container.with_value(it))?;
179179
VariantId::from(def).into()
180180
},
181-
ast::StaticDef(it) => {
181+
ast::Static(it) => {
182182
let def = self.static_to_def(container.with_value(it))?;
183183
DefWithBodyId::from(def).into()
184184
},
185-
ast::ConstDef(it) => {
185+
ast::Const(it) => {
186186
let def = self.const_to_def(container.with_value(it))?;
187187
DefWithBodyId::from(def).into()
188188
},
@@ -222,8 +222,8 @@ impl SourceToDefCtx<'_, '_> {
222222
for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
223223
let res: DefWithBodyId = match_ast! {
224224
match (container.value) {
225-
ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(),
226-
ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(),
225+
ast::Const(it) => self.const_to_def(container.with_value(it))?.into(),
226+
ast::Static(it) => self.static_to_def(container.with_value(it))?.into(),
227227
ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
228228
_ => continue,
229229
}

crates/ra_hir_def/src/body/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,14 @@ impl ExprCollector<'_> {
641641
def.name(),
642642
)
643643
}
644-
ast::Item::ConstDef(def) => {
644+
ast::Item::Const(def) => {
645645
let id = self.find_inner_item(&def)?;
646646
(
647647
ConstLoc { container: container.into(), id }.intern(self.db).into(),
648648
def.name(),
649649
)
650650
}
651-
ast::Item::StaticDef(def) => {
651+
ast::Item::Static(def) => {
652652
let id = self.find_inner_item(&def)?;
653653
(StaticLoc { container, id }.intern(self.db).into(), def.name())
654654
}

crates/ra_hir_def/src/item_tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ mod_items! {
417417
Struct in structs -> ast::Struct,
418418
Union in unions -> ast::Union,
419419
Enum in enums -> ast::Enum,
420-
Const in consts -> ast::ConstDef,
421-
Static in statics -> ast::StaticDef,
420+
Const in consts -> ast::Const,
421+
Static in statics -> ast::Static,
422422
Trait in traits -> ast::TraitDef,
423423
Impl in impls -> ast::ImplDef,
424424
TypeAlias in type_aliases -> ast::TypeAlias,
@@ -552,7 +552,7 @@ pub struct Const {
552552
pub name: Option<Name>,
553553
pub visibility: RawVisibilityId,
554554
pub type_ref: TypeRef,
555-
pub ast_id: FileAstId<ast::ConstDef>,
555+
pub ast_id: FileAstId<ast::Const>,
556556
}
557557

558558
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -561,7 +561,7 @@ pub struct Static {
561561
pub visibility: RawVisibilityId,
562562
pub mutable: bool,
563563
pub type_ref: TypeRef,
564-
pub ast_id: FileAstId<ast::StaticDef>,
564+
pub ast_id: FileAstId<ast::Static>,
565565
}
566566

567567
#[derive(Debug, Clone, Eq, PartialEq)]

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ impl Ctx {
8383
| ast::Item::Enum(_)
8484
| ast::Item::Fn(_)
8585
| ast::Item::TypeAlias(_)
86-
| ast::Item::ConstDef(_)
87-
| ast::Item::StaticDef(_)
86+
| ast::Item::Const(_)
87+
| ast::Item::Static(_)
8888
| ast::Item::MacroCall(_) => {
8989
// Skip this if we're already collecting inner items. We'll descend into all nodes
9090
// already.
@@ -108,8 +108,8 @@ impl Ctx {
108108
ast::Item::Enum(ast) => self.lower_enum(ast).map(Into::into),
109109
ast::Item::Fn(ast) => self.lower_function(ast).map(Into::into),
110110
ast::Item::TypeAlias(ast) => self.lower_type_alias(ast).map(Into::into),
111-
ast::Item::StaticDef(ast) => self.lower_static(ast).map(Into::into),
112-
ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()),
111+
ast::Item::Static(ast) => self.lower_static(ast).map(Into::into),
112+
ast::Item::Const(ast) => Some(self.lower_const(ast).into()),
113113
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
114114
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
115115
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
@@ -160,7 +160,7 @@ impl Ctx {
160160
match item {
161161
ast::AssocItem::Fn(ast) => self.lower_function(ast).map(Into::into),
162162
ast::AssocItem::TypeAlias(ast) => self.lower_type_alias(ast).map(Into::into),
163-
ast::AssocItem::ConstDef(ast) => Some(self.lower_const(ast).into()),
163+
ast::AssocItem::Const(ast) => Some(self.lower_const(ast).into()),
164164
ast::AssocItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
165165
}
166166
}
@@ -368,7 +368,7 @@ impl Ctx {
368368
Some(id(self.data().type_aliases.alloc(res)))
369369
}
370370

371-
fn lower_static(&mut self, static_: &ast::StaticDef) -> Option<FileItemTreeId<Static>> {
371+
fn lower_static(&mut self, static_: &ast::Static) -> Option<FileItemTreeId<Static>> {
372372
let name = static_.name()?.as_name();
373373
let type_ref = self.lower_type_ref_opt(static_.ascribed_type());
374374
let visibility = self.lower_visibility(static_);
@@ -378,7 +378,7 @@ impl Ctx {
378378
Some(id(self.data().statics.alloc(res)))
379379
}
380380

381-
fn lower_const(&mut self, konst: &ast::ConstDef) -> FileItemTreeId<Const> {
381+
fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
382382
let name = konst.name().map(|it| it.as_name());
383383
let type_ref = self.lower_type_ref_opt(konst.ascribed_type());
384384
let visibility = self.lower_visibility(konst);
@@ -553,7 +553,7 @@ impl Ctx {
553553
self.data().functions[func.index].is_unsafe = true;
554554
func.into()
555555
}
556-
ast::ExternItem::StaticDef(ast) => {
556+
ast::ExternItem::Static(ast) => {
557557
let statik = self.lower_static(&ast)?;
558558
statik.into()
559559
}

crates/ra_hir_def/src/item_tree/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn smoke() {
238238
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
239239
> 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::<ra_syntax::ast::generated::nodes::TypeAlias>(8) }
240240
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
241-
> 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::<ra_syntax::ast::generated::nodes::ConstDef>(9) }
241+
> 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::<ra_syntax::ast::generated::nodes::Const>(9) }
242242
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]
243243
> 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::<ra_syntax::ast::generated::nodes::Fn>(10) }
244244
> #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }]

0 commit comments

Comments
 (0)