Skip to content

Commit 0f58055

Browse files
bors[bot]matklad
andauthored
Merge #5606
5606: Finalize impl Grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents c8e2d67 + c5798c4 commit 0f58055

File tree

74 files changed

+199
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+199
-193
lines changed

crates/ra_assists/src/ast_transform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a> SubstituteTypeParams<'a> {
4141
source_scope: &'a SemanticsScope<'a>,
4242
// FIXME: there's implicit invariant that `trait_` and `source_scope` match...
4343
trait_: hir::Trait,
44-
impl_def: ast::ImplDef,
44+
impl_def: ast::Impl,
4545
) -> SubstituteTypeParams<'a> {
4646
let substs = get_syntactic_substs(impl_def).unwrap_or_default();
4747
let generic_def: hir::GenericDef = trait_.into();
@@ -80,7 +80,7 @@ impl<'a> SubstituteTypeParams<'a> {
8080

8181
// FIXME: It would probably be nicer if we could get this via HIR (i.e. get the
8282
// trait ref, and then go from the types in the substs back to the syntax)
83-
fn get_syntactic_substs(impl_def: ast::ImplDef) -> Option<Vec<ast::TypeRef>> {
83+
fn get_syntactic_substs(impl_def: ast::Impl) -> Option<Vec<ast::TypeRef>> {
8484
let target_trait = impl_def.target_trait()?;
8585
let path_type = match target_trait {
8686
ast::TypeRef::PathType(path) => path,

crates/ra_assists/src/handlers/add_missing_impl_members.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn add_missing_impl_members_inner(
111111
label: &'static str,
112112
) -> Option<()> {
113113
let _p = ra_prof::profile("add_missing_impl_members_inner");
114-
let impl_def = ctx.find_node_at_offset::<ast::ImplDef>()?;
114+
let impl_def = ctx.find_node_at_offset::<ast::Impl>()?;
115115
let impl_item_list = impl_def.assoc_item_list()?;
116116

117117
let trait_ = resolve_target_trait(&ctx.sema, &impl_def)?;

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, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT_DEF, VISIBILITY},
4+
SyntaxKind::{CONST, ENUM, FN, MODULE, STATIC, STRUCT, TRAIT, 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, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT_DEF];
39+
let def_kws = vec![CONST, STATIC, FN, MODULE, STRUCT, ENUM, TRAIT];
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/handlers/generate_new.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String {
122122
//
123123
// FIXME: change the new fn checking to a more semantic approach when that's more
124124
// viable (e.g. we process proc macros, etc)
125-
fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option<Option<ast::ImplDef>> {
125+
fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option<Option<ast::Impl>> {
126126
let db = ctx.db();
127127
let module = strukt.syntax().ancestors().find(|node| {
128128
ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind())
129129
})?;
130130

131131
let struct_def = ctx.sema.to_def(strukt)?;
132132

133-
let block = module.descendants().filter_map(ast::ImplDef::cast).find_map(|impl_blk| {
133+
let block = module.descendants().filter_map(ast::Impl::cast).find_map(|impl_blk| {
134134
let blk = ctx.sema.to_def(&impl_blk)?;
135135

136136
// FIXME: handle e.g. `struct S<T>; impl<U> S<U> {}`
@@ -158,7 +158,7 @@ fn find_struct_impl(ctx: &AssistContext, strukt: &ast::Struct) -> Option<Option<
158158
Some(block)
159159
}
160160

161-
fn has_new_fn(imp: &ast::ImplDef) -> bool {
161+
fn has_new_fn(imp: &ast::Impl) -> bool {
162162
if let Some(il) = imp.assoc_item_list() {
163163
for item in il.assoc_items() {
164164
if let ast::AssocItem::Fn(f) = item {

crates/ra_assists/src/handlers/introduce_named_lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -
4040
.filter(|lifetime| lifetime.text() == "'_")?;
4141
if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::Fn::cast) {
4242
generate_fn_def_assist(acc, &fn_def, lifetime_token.text_range())
43-
} else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::ImplDef::cast) {
43+
} else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::Impl::cast) {
4444
generate_impl_def_assist(acc, &impl_def, lifetime_token.text_range())
4545
} else {
4646
None
@@ -93,7 +93,7 @@ fn generate_fn_def_assist(
9393
/// Generate the assist for the impl def case
9494
fn generate_impl_def_assist(
9595
acc: &mut Assists,
96-
impl_def: &ast::ImplDef,
96+
impl_def: &ast::Impl,
9797
lifetime_loc: TextRange,
9898
) -> Option<()> {
9999
let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.generic_param_list())?;

crates/ra_assists/src/handlers/move_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
3838
let anchor = match_ast! {
3939
match parent {
4040
ast::Fn(it) => it.body()?.syntax().clone().into(),
41-
ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(),
42-
ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(),
41+
ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(),
42+
ast::Impl(it) => it.assoc_item_list()?.syntax().clone().into(),
4343
ast::Enum(it) => it.variant_list()?.syntax().clone().into(),
4444
ast::Struct(it) => {
4545
it.syntax().children_with_tokens()

crates/ra_assists/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor
5656

5757
pub fn get_missing_assoc_items(
5858
sema: &Semantics<RootDatabase>,
59-
impl_def: &ast::ImplDef,
59+
impl_def: &ast::Impl,
6060
) -> Vec<hir::AssocItem> {
6161
// Names must be unique between constants and functions. However, type aliases
6262
// may share the same name as a function or constant.
@@ -109,7 +109,7 @@ pub fn get_missing_assoc_items(
109109

110110
pub(crate) fn resolve_target_trait(
111111
sema: &Semantics<RootDatabase>,
112-
impl_def: &ast::ImplDef,
112+
impl_def: &ast::Impl,
113113
) -> Option<hir::Trait> {
114114
let ast_path = impl_def
115115
.target_trait()

crates/ra_hir/src/has_source.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl HasSource for Static {
9999
}
100100
}
101101
impl HasSource for Trait {
102-
type Ast = ast::TraitDef;
103-
fn source(self, db: &dyn HirDatabase) -> InFile<ast::TraitDef> {
102+
type Ast = ast::Trait;
103+
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
104104
self.id.lookup(db.upcast()).source(db.upcast())
105105
}
106106
}
@@ -120,14 +120,14 @@ impl HasSource for MacroDef {
120120
}
121121
}
122122
impl HasSource for ImplDef {
123-
type Ast = ast::ImplDef;
124-
fn source(self, db: &dyn HirDatabase) -> InFile<ast::ImplDef> {
123+
type Ast = ast::Impl;
124+
fn source(self, db: &dyn HirDatabase) -> InFile<ast::Impl> {
125125
self.id.lookup(db.upcast()).source(db.upcast())
126126
}
127127
}
128128

129129
impl HasSource for TypeParam {
130-
type Ast = Either<ast::TraitDef, ast::TypeParam>;
130+
type Ast = Either<ast::Trait, ast::TypeParam>;
131131
fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
132132
let child_source = self.id.parent.child_source(db.upcast());
133133
child_source.map(|it| it[self.id.local_id].clone())

crates/ra_hir/src/semantics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ to_def_impls![
583583
(crate::Struct, ast::Struct, struct_to_def),
584584
(crate::Enum, ast::Enum, enum_to_def),
585585
(crate::Union, ast::Union, union_to_def),
586-
(crate::Trait, ast::TraitDef, trait_to_def),
587-
(crate::ImplDef, ast::ImplDef, impl_to_def),
586+
(crate::Trait, ast::Trait, trait_to_def),
587+
(crate::ImplDef, ast::Impl, impl_to_def),
588588
(crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
589589
(crate::Const, ast::Const, const_to_def),
590590
(crate::Static, ast::Static, static_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
@@ -65,10 +65,10 @@ impl SourceToDefCtx<'_, '_> {
6565
Some(ModuleId { krate: parent_module.krate, local_id: child_id })
6666
}
6767

68-
pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> {
68+
pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
6969
self.to_def(src, keys::TRAIT)
7070
}
71-
pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> {
71+
pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> {
7272
self.to_def(src, keys::IMPL)
7373
}
7474
pub(super) fn fn_to_def(&mut self, src: InFile<ast::Fn>) -> Option<FunctionId> {
@@ -154,11 +154,11 @@ impl SourceToDefCtx<'_, '_> {
154154
let def = self.module_to_def(container.with_value(it))?;
155155
def.into()
156156
},
157-
ast::TraitDef(it) => {
157+
ast::Trait(it) => {
158158
let def = self.trait_to_def(container.with_value(it))?;
159159
def.into()
160160
},
161-
ast::ImplDef(it) => {
161+
ast::Impl(it) => {
162162
let def = self.impl_to_def(container.with_value(it))?;
163163
def.into()
164164
},
@@ -207,9 +207,9 @@ impl SourceToDefCtx<'_, '_> {
207207
ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
208208
ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(),
209209
ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
210-
ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(),
210+
ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
211211
ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(),
212-
ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(),
212+
ast::Impl(it) => self.impl_to_def(container.with_value(it))?.into(),
213213
_ => continue,
214214
}
215215
};

0 commit comments

Comments
 (0)