Skip to content

Commit c5798c4

Browse files
committed
Finalize impl Grammar
1 parent c834677 commit c5798c4

Some content is hidden

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

54 files changed

+103
-100
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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
3939
match parent {
4040
ast::Fn(it) => it.body()?.syntax().clone().into(),
4141
ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(),
42-
ast::ImplDef(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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ 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
}

crates/ra_hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ to_def_impls![
584584
(crate::Enum, ast::Enum, enum_to_def),
585585
(crate::Union, ast::Union, union_to_def),
586586
(crate::Trait, ast::Trait, trait_to_def),
587-
(crate::ImplDef, ast::ImplDef, impl_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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl SourceToDefCtx<'_, '_> {
6868
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> {
@@ -158,7 +158,7 @@ impl SourceToDefCtx<'_, '_> {
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
},
@@ -209,7 +209,7 @@ impl SourceToDefCtx<'_, '_> {
209209
ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
210210
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
};

crates/ra_hir_def/src/body/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ impl ExprCollector<'_> {
669669
(TraitLoc { container, id }.intern(self.db).into(), def.name())
670670
}
671671
ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672-
ast::Item::ImplDef(_)
672+
ast::Item::Impl(_)
673673
| ast::Item::Use(_)
674674
| ast::Item::ExternCrate(_)
675675
| ast::Item::Module(_)

0 commit comments

Comments
 (0)