diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-05 17:13:57 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-05 17:13:57 +0100 |
commit | 58f64313fdbb215b29cceb843e06d2c1541d9f56 (patch) | |
tree | 0c95a20510f832ec5f208a1ede39f8aad8ffcd86 | |
parent | 756e91732b7a92d9156f5c1d8ffcaf5155cf4680 (diff) | |
parent | 92665358cd98913e3fef8294e1889cc0bb919e3f (diff) |
Merge #4321
4321: Rename ImplItem to AssocItem r=matklad a=edwin0cheng
Related discussion: https://github.com/rust-analyzer/rust-analyzer/pull/4283#discussion_r419352265
Co-authored-by: Edwin Cheng <[email protected]>
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 26 | ||||
-rw-r--r-- | crates/ra_assists/src/handlers/add_new.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/utils.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_qualified_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 46 | ||||
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 36 | ||||
-rw-r--r-- | xtask/src/ast_src.rs | 4 |
12 files changed, 83 insertions, 77 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 e466c9a86..e47feda71 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, | 12 | ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams}, |
13 | utils::{get_missing_impl_items, resolve_target_trait}, | 13 | utils::{get_missing_assoc_items, resolve_target_trait}, |
14 | Assist, AssistCtx, AssistId, | 14 | Assist, AssistCtx, AssistId, |
15 | }; | 15 | }; |
16 | 16 | ||
@@ -112,25 +112,25 @@ fn add_missing_impl_members_inner( | |||
112 | 112 | ||
113 | let trait_ = resolve_target_trait(&ctx.sema, &impl_node)?; | 113 | let trait_ = resolve_target_trait(&ctx.sema, &impl_node)?; |
114 | 114 | ||
115 | let def_name = |item: &ast::ImplItem| -> Option<SmolStr> { | 115 | let def_name = |item: &ast::AssocItem| -> Option<SmolStr> { |
116 | match item { | 116 | match item { |
117 | ast::ImplItem::FnDef(def) => def.name(), | 117 | ast::AssocItem::FnDef(def) => def.name(), |
118 | ast::ImplItem::TypeAliasDef(def) => def.name(), | 118 | ast::AssocItem::TypeAliasDef(def) => def.name(), |
119 | ast::ImplItem::ConstDef(def) => def.name(), | 119 | ast::AssocItem::ConstDef(def) => def.name(), |
120 | } | 120 | } |
121 | .map(|it| it.text().clone()) | 121 | .map(|it| it.text().clone()) |
122 | }; | 122 | }; |
123 | 123 | ||
124 | let missing_items = get_missing_impl_items(&ctx.sema, &impl_node) | 124 | let missing_items = get_missing_assoc_items(&ctx.sema, &impl_node) |
125 | .iter() | 125 | .iter() |
126 | .map(|i| match i { | 126 | .map(|i| match i { |
127 | hir::AssocItem::Function(i) => ast::ImplItem::FnDef(i.source(ctx.db).value), | 127 | hir::AssocItem::Function(i) => ast::AssocItem::FnDef(i.source(ctx.db).value), |
128 | hir::AssocItem::TypeAlias(i) => ast::ImplItem::TypeAliasDef(i.source(ctx.db).value), | 128 | hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAliasDef(i.source(ctx.db).value), |
129 | hir::AssocItem::Const(i) => ast::ImplItem::ConstDef(i.source(ctx.db).value), | 129 | hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db).value), |
130 | }) | 130 | }) |
131 | .filter(|t| def_name(&t).is_some()) | 131 | .filter(|t| def_name(&t).is_some()) |
132 | .filter(|t| match t { | 132 | .filter(|t| match t { |
133 | ast::ImplItem::FnDef(def) => match mode { | 133 | ast::AssocItem::FnDef(def) => match mode { |
134 | AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), | 134 | AddMissingImplMembersMode::DefaultMethodsOnly => def.body().is_some(), |
135 | AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), | 135 | AddMissingImplMembersMode::NoDefaultMethods => def.body().is_none(), |
136 | }, | 136 | }, |
@@ -145,7 +145,7 @@ fn add_missing_impl_members_inner( | |||
145 | let sema = ctx.sema; | 145 | let sema = ctx.sema; |
146 | 146 | ||
147 | ctx.add_assist(AssistId(assist_id), label, |edit| { | 147 | ctx.add_assist(AssistId(assist_id), label, |edit| { |
148 | let n_existing_items = impl_item_list.impl_items().count(); | 148 | let n_existing_items = impl_item_list.assoc_items().count(); |
149 | let source_scope = sema.scope_for_def(trait_); | 149 | let source_scope = sema.scope_for_def(trait_); |
150 | let target_scope = sema.scope(impl_item_list.syntax()); | 150 | let target_scope = sema.scope(impl_item_list.syntax()); |
151 | let ast_transform = QualifyPaths::new(&target_scope, &source_scope) | 151 | let ast_transform = QualifyPaths::new(&target_scope, &source_scope) |
@@ -154,13 +154,13 @@ fn add_missing_impl_members_inner( | |||
154 | .into_iter() | 154 | .into_iter() |
155 | .map(|it| ast_transform::apply(&*ast_transform, it)) | 155 | .map(|it| ast_transform::apply(&*ast_transform, it)) |
156 | .map(|it| match it { | 156 | .map(|it| match it { |
157 | ast::ImplItem::FnDef(def) => ast::ImplItem::FnDef(add_body(def)), | 157 | ast::AssocItem::FnDef(def) => ast::AssocItem::FnDef(add_body(def)), |
158 | _ => it, | 158 | _ => it, |
159 | }) | 159 | }) |
160 | .map(|it| edit::remove_attrs_and_docs(&it)); | 160 | .map(|it| edit::remove_attrs_and_docs(&it)); |
161 | let new_impl_item_list = impl_item_list.append_items(items); | 161 | let new_impl_item_list = impl_item_list.append_items(items); |
162 | let cursor_position = { | 162 | let cursor_position = { |
163 | let first_new_item = new_impl_item_list.impl_items().nth(n_existing_items).unwrap(); | 163 | let first_new_item = new_impl_item_list.assoc_items().nth(n_existing_items).unwrap(); |
164 | first_new_item.syntax().text_range().start() | 164 | first_new_item.syntax().text_range().start() |
165 | }; | 165 | }; |
166 | 166 | ||
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 0f9174a29..e8a36c7de 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs | |||
@@ -162,8 +162,8 @@ fn find_struct_impl(ctx: &AssistCtx, strukt: &ast::StructDef) -> Option<Option<a | |||
162 | 162 | ||
163 | fn has_new_fn(imp: &ast::ImplDef) -> bool { | 163 | fn has_new_fn(imp: &ast::ImplDef) -> bool { |
164 | if let Some(il) = imp.item_list() { | 164 | if let Some(il) = imp.item_list() { |
165 | for item in il.impl_items() { | 165 | for item in il.assoc_items() { |
166 | if let ast::ImplItem::FnDef(f) = item { | 166 | if let ast::AssocItem::FnDef(f) = item { |
167 | if let Some(name) = f.name() { | 167 | if let Some(name) = f.name() { |
168 | if name.text().eq_ignore_ascii_case("new") { | 168 | if name.text().eq_ignore_ascii_case("new") { |
169 | return true; | 169 | return true; |
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 6be704ce3..2f15a3f15 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -13,7 +13,7 @@ use rustc_hash::FxHashSet; | |||
13 | 13 | ||
14 | pub(crate) use insert_use::insert_use_statement; | 14 | pub(crate) use insert_use::insert_use_statement; |
15 | 15 | ||
16 | pub fn get_missing_impl_items( | 16 | pub fn get_missing_assoc_items( |
17 | sema: &Semantics<RootDatabase>, | 17 | sema: &Semantics<RootDatabase>, |
18 | impl_def: &ast::ImplDef, | 18 | impl_def: &ast::ImplDef, |
19 | ) -> Vec<hir::AssocItem> { | 19 | ) -> Vec<hir::AssocItem> { |
@@ -23,21 +23,21 @@ pub fn get_missing_impl_items( | |||
23 | let mut impl_type = FxHashSet::default(); | 23 | let mut impl_type = FxHashSet::default(); |
24 | 24 | ||
25 | if let Some(item_list) = impl_def.item_list() { | 25 | if let Some(item_list) = impl_def.item_list() { |
26 | for item in item_list.impl_items() { | 26 | for item in item_list.assoc_items() { |
27 | match item { | 27 | match item { |
28 | ast::ImplItem::FnDef(f) => { | 28 | ast::AssocItem::FnDef(f) => { |
29 | if let Some(n) = f.name() { | 29 | if let Some(n) = f.name() { |
30 | impl_fns_consts.insert(n.syntax().to_string()); | 30 | impl_fns_consts.insert(n.syntax().to_string()); |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | ast::ImplItem::TypeAliasDef(t) => { | 34 | ast::AssocItem::TypeAliasDef(t) => { |
35 | if let Some(n) = t.name() { | 35 | if let Some(n) = t.name() { |
36 | impl_type.insert(n.syntax().to_string()); | 36 | impl_type.insert(n.syntax().to_string()); |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | ast::ImplItem::ConstDef(c) => { | 40 | ast::AssocItem::ConstDef(c) => { |
41 | if let Some(n) = c.name() { | 41 | if let Some(n) = c.name() { |
42 | impl_fns_consts.insert(n.syntax().to_string()); | 42 | impl_fns_consts.insert(n.syntax().to_string()); |
43 | } | 43 | } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index a004363ee..5f480c304 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -1211,7 +1211,7 @@ impl Type { | |||
1211 | 1211 | ||
1212 | // This would be nicer if it just returned an iterator, but that runs into | 1212 | // This would be nicer if it just returned an iterator, but that runs into |
1213 | // lifetime problems, because we need to borrow temp `CrateImplDefs`. | 1213 | // lifetime problems, because we need to borrow temp `CrateImplDefs`. |
1214 | pub fn iterate_impl_items<T>( | 1214 | pub fn iterate_assoc_items<T>( |
1215 | self, | 1215 | self, |
1216 | db: &dyn HirDatabase, | 1216 | db: &dyn HirDatabase, |
1217 | krate: Crate, | 1217 | krate: Crate, |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 2dbae04d3..e7eb2bb11 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -9,7 +9,7 @@ use hir_expand::{ | |||
9 | }; | 9 | }; |
10 | use ra_prof::profile; | 10 | use ra_prof::profile; |
11 | use ra_syntax::ast::{ | 11 | use ra_syntax::ast::{ |
12 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, TypeBoundsOwner, | 12 | self, AssocItem, AstNode, ModuleItemOwner, NameOwner, TypeAscriptionOwner, TypeBoundsOwner, |
13 | VisibilityOwner, | 13 | VisibilityOwner, |
14 | }; | 14 | }; |
15 | 15 | ||
@@ -164,7 +164,7 @@ impl TraitData { | |||
164 | items.extend(collect_items( | 164 | items.extend(collect_items( |
165 | db, | 165 | db, |
166 | &mut expander, | 166 | &mut expander, |
167 | item_list.impl_items(), | 167 | item_list.assoc_items(), |
168 | src.file_id, | 168 | src.file_id, |
169 | container, | 169 | container, |
170 | )); | 170 | )); |
@@ -219,7 +219,7 @@ impl ImplData { | |||
219 | if let Some(item_list) = src.value.item_list() { | 219 | if let Some(item_list) = src.value.item_list() { |
220 | let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); | 220 | let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); |
221 | items.extend( | 221 | items.extend( |
222 | collect_items(db, &mut expander, item_list.impl_items(), src.file_id, container) | 222 | collect_items(db, &mut expander, item_list.assoc_items(), src.file_id, container) |
223 | .into_iter() | 223 | .into_iter() |
224 | .map(|(_, item)| item), | 224 | .map(|(_, item)| item), |
225 | ); | 225 | ); |
@@ -304,7 +304,7 @@ fn collect_items_in_macro( | |||
304 | let mut res = collect_items( | 304 | let mut res = collect_items( |
305 | db, | 305 | db, |
306 | expander, | 306 | expander, |
307 | items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())), | 307 | items.value.items().filter_map(|it| AssocItem::cast(it.syntax().clone())), |
308 | items.file_id, | 308 | items.file_id, |
309 | container, | 309 | container, |
310 | ); | 310 | ); |
@@ -325,15 +325,15 @@ fn collect_items_in_macro( | |||
325 | fn collect_items( | 325 | fn collect_items( |
326 | db: &dyn DefDatabase, | 326 | db: &dyn DefDatabase, |
327 | expander: &mut Expander, | 327 | expander: &mut Expander, |
328 | impl_items: impl Iterator<Item = ImplItem>, | 328 | assoc_items: impl Iterator<Item = AssocItem>, |
329 | file_id: crate::HirFileId, | 329 | file_id: crate::HirFileId, |
330 | container: AssocContainerId, | 330 | container: AssocContainerId, |
331 | ) -> Vec<(Name, AssocItemId)> { | 331 | ) -> Vec<(Name, AssocItemId)> { |
332 | let items = db.ast_id_map(file_id); | 332 | let items = db.ast_id_map(file_id); |
333 | 333 | ||
334 | impl_items | 334 | assoc_items |
335 | .filter_map(|item_node| match item_node { | 335 | .filter_map(|item_node| match item_node { |
336 | ast::ImplItem::FnDef(it) => { | 336 | ast::AssocItem::FnDef(it) => { |
337 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); | 337 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
338 | if !expander.is_cfg_enabled(&it) { | 338 | if !expander.is_cfg_enabled(&it) { |
339 | return None; | 339 | return None; |
@@ -342,13 +342,13 @@ fn collect_items( | |||
342 | .intern(db); | 342 | .intern(db); |
343 | Some((name, def.into())) | 343 | Some((name, def.into())) |
344 | } | 344 | } |
345 | ast::ImplItem::ConstDef(it) => { | 345 | ast::AssocItem::ConstDef(it) => { |
346 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); | 346 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
347 | let def = ConstLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } | 347 | let def = ConstLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } |
348 | .intern(db); | 348 | .intern(db); |
349 | Some((name, def.into())) | 349 | Some((name, def.into())) |
350 | } | 350 | } |
351 | ast::ImplItem::TypeAliasDef(it) => { | 351 | ast::AssocItem::TypeAliasDef(it) => { |
352 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); | 352 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
353 | let def = | 353 | let def = |
354 | TypeAliasLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } | 354 | TypeAliasLoc { container, ast_id: AstId::new(file_id, items.ast_id(&it)) } |
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 29e38a06c..07398ddcc 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -269,7 +269,7 @@ fn test() { S.foo()<|>; } | |||
269 | } | 269 | } |
270 | 270 | ||
271 | #[test] | 271 | #[test] |
272 | fn infer_impl_items_generated_by_macros() { | 272 | fn infer_assoc_items_generated_by_macros() { |
273 | let t = type_at( | 273 | let t = type_at( |
274 | r#" | 274 | r#" |
275 | //- /main.rs | 275 | //- /main.rs |
@@ -288,7 +288,7 @@ fn test() { S.foo()<|>; } | |||
288 | } | 288 | } |
289 | 289 | ||
290 | #[test] | 290 | #[test] |
291 | fn infer_impl_items_generated_by_macros_chain() { | 291 | fn infer_assoc_items_generated_by_macros_chain() { |
292 | let t = type_at( | 292 | let t = type_at( |
293 | r#" | 293 | r#" |
294 | //- /main.rs | 294 | //- /main.rs |
diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index d9ea92ef8..7fcd22525 100644 --- a/crates/ra_ide/src/completion/complete_qualified_path.rs +++ b/crates/ra_ide/src/completion/complete_qualified_path.rs | |||
@@ -84,7 +84,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon | |||
84 | }); | 84 | }); |
85 | 85 | ||
86 | // Iterate assoc types separately | 86 | // Iterate assoc types separately |
87 | ty.iterate_impl_items(ctx.db, krate, |item| { | 87 | ty.iterate_assoc_items(ctx.db, krate, |item| { |
88 | if context_module.map_or(false, |m| !item.is_visible_from(ctx.db, m)) { | 88 | if context_module.map_or(false, |m| !item.is_visible_from(ctx.db, m)) { |
89 | return None; | 89 | return None; |
90 | } | 90 | } |
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index ee32d1ff6..039df03e0 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -32,7 +32,7 @@ | |||
32 | //! ``` | 32 | //! ``` |
33 | 33 | ||
34 | use hir::{self, Docs, HasSource}; | 34 | use hir::{self, Docs, HasSource}; |
35 | use ra_assists::utils::get_missing_impl_items; | 35 | use ra_assists::utils::get_missing_assoc_items; |
36 | use ra_syntax::{ | 36 | use ra_syntax::{ |
37 | ast::{self, edit, ImplDef}, | 37 | ast::{self, edit, ImplDef}, |
38 | AstNode, SyntaxKind, SyntaxNode, TextRange, T, | 38 | AstNode, SyntaxKind, SyntaxNode, TextRange, T, |
@@ -50,7 +50,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext | |||
50 | if let Some((trigger, impl_def)) = completion_match(ctx) { | 50 | if let Some((trigger, impl_def)) = completion_match(ctx) { |
51 | match trigger.kind() { | 51 | match trigger.kind() { |
52 | SyntaxKind::NAME_REF => { | 52 | SyntaxKind::NAME_REF => { |
53 | get_missing_impl_items(&ctx.sema, &impl_def).iter().for_each(|item| match item { | 53 | get_missing_assoc_items(&ctx.sema, &impl_def).iter().for_each(|item| match item { |
54 | hir::AssocItem::Function(fn_item) => { | 54 | hir::AssocItem::Function(fn_item) => { |
55 | add_function_impl(&trigger, acc, ctx, &fn_item) | 55 | add_function_impl(&trigger, acc, ctx, &fn_item) |
56 | } | 56 | } |
@@ -64,34 +64,40 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext | |||
64 | } | 64 | } |
65 | 65 | ||
66 | SyntaxKind::FN_DEF => { | 66 | SyntaxKind::FN_DEF => { |
67 | for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map( | 67 | for missing_fn in |
68 | |item| match item { | 68 | get_missing_assoc_items(&ctx.sema, &impl_def).iter().filter_map(|item| { |
69 | hir::AssocItem::Function(fn_item) => Some(fn_item), | 69 | match item { |
70 | _ => None, | 70 | hir::AssocItem::Function(fn_item) => Some(fn_item), |
71 | }, | 71 | _ => None, |
72 | ) { | 72 | } |
73 | }) | ||
74 | { | ||
73 | add_function_impl(&trigger, acc, ctx, &missing_fn); | 75 | add_function_impl(&trigger, acc, ctx, &missing_fn); |
74 | } | 76 | } |
75 | } | 77 | } |
76 | 78 | ||
77 | SyntaxKind::TYPE_ALIAS_DEF => { | 79 | SyntaxKind::TYPE_ALIAS_DEF => { |
78 | for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map( | 80 | for missing_fn in |
79 | |item| match item { | 81 | get_missing_assoc_items(&ctx.sema, &impl_def).iter().filter_map(|item| { |
80 | hir::AssocItem::TypeAlias(type_item) => Some(type_item), | 82 | match item { |
81 | _ => None, | 83 | hir::AssocItem::TypeAlias(type_item) => Some(type_item), |
82 | }, | 84 | _ => None, |
83 | ) { | 85 | } |
86 | }) | ||
87 | { | ||
84 | add_type_alias_impl(&trigger, acc, ctx, &missing_fn); | 88 | add_type_alias_impl(&trigger, acc, ctx, &missing_fn); |
85 | } | 89 | } |
86 | } | 90 | } |
87 | 91 | ||
88 | SyntaxKind::CONST_DEF => { | 92 | SyntaxKind::CONST_DEF => { |
89 | for missing_fn in get_missing_impl_items(&ctx.sema, &impl_def).iter().filter_map( | 93 | for missing_fn in |
90 | |item| match item { | 94 | get_missing_assoc_items(&ctx.sema, &impl_def).iter().filter_map(|item| { |
91 | hir::AssocItem::Const(const_item) => Some(const_item), | 95 | match item { |
92 | _ => None, | 96 | hir::AssocItem::Const(const_item) => Some(const_item), |
93 | }, | 97 | _ => None, |
94 | ) { | 98 | } |
99 | }) | ||
100 | { | ||
95 | add_const_impl(&trigger, acc, ctx, &missing_fn); | 101 | add_const_impl(&trigger, acc, ctx, &missing_fn); |
96 | } | 102 | } |
97 | } | 103 | } |
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index bb28acfd9..fc4133a67 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -63,7 +63,7 @@ pub fn syntax_node_to_token_tree(node: &SyntaxNode) -> Option<(tt::Subtree, Toke | |||
63 | // * Items(SmallVec<[P<ast::Item>; 1]>) -> token_tree_to_items | 63 | // * Items(SmallVec<[P<ast::Item>; 1]>) -> token_tree_to_items |
64 | // | 64 | // |
65 | // * TraitItems(SmallVec<[ast::TraitItem; 1]>) | 65 | // * TraitItems(SmallVec<[ast::TraitItem; 1]>) |
66 | // * ImplItems(SmallVec<[ast::ImplItem; 1]>) | 66 | // * AssocItems(SmallVec<[ast::AssocItem; 1]>) |
67 | // * ForeignItems(SmallVec<[ast::ForeignItem; 1]> | 67 | // * ForeignItems(SmallVec<[ast::ForeignItem; 1]> |
68 | 68 | ||
69 | pub fn token_tree_to_syntax_node( | 69 | pub fn token_tree_to_syntax_node( |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index c507dc683..3e6dd6061 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -79,7 +79,7 @@ where | |||
79 | 79 | ||
80 | impl ast::ItemList { | 80 | impl ast::ItemList { |
81 | #[must_use] | 81 | #[must_use] |
82 | pub fn append_items(&self, items: impl IntoIterator<Item = ast::ImplItem>) -> ast::ItemList { | 82 | pub fn append_items(&self, items: impl IntoIterator<Item = ast::AssocItem>) -> ast::ItemList { |
83 | let mut res = self.clone(); | 83 | let mut res = self.clone(); |
84 | if !self.syntax().text().contains_char('\n') { | 84 | if !self.syntax().text().contains_char('\n') { |
85 | res = make_multiline(res); | 85 | res = make_multiline(res); |
@@ -89,8 +89,8 @@ impl ast::ItemList { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | #[must_use] | 91 | #[must_use] |
92 | pub fn append_item(&self, item: ast::ImplItem) -> ast::ItemList { | 92 | pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { |
93 | let (indent, position) = match self.impl_items().last() { | 93 | let (indent, position) = match self.assoc_items().last() { |
94 | Some(it) => ( | 94 | Some(it) => ( |
95 | leading_indent(it.syntax()).unwrap_or_default().to_string(), | 95 | leading_indent(it.syntax()).unwrap_or_default().to_string(), |
96 | InsertPosition::After(it.syntax().clone().into()), | 96 | InsertPosition::After(it.syntax().clone().into()), |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index c2cc25958..b00c15608 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -196,7 +196,7 @@ pub struct ItemList { | |||
196 | impl ast::ModuleItemOwner for ItemList {} | 196 | impl ast::ModuleItemOwner for ItemList {} |
197 | impl ItemList { | 197 | impl ItemList { |
198 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 198 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
199 | pub fn impl_items(&self) -> AstChildren<ImplItem> { support::children(&self.syntax) } | 199 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } |
200 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 200 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
201 | } | 201 | } |
202 | 202 | ||
@@ -1429,13 +1429,13 @@ impl ast::AttrsOwner for ModuleItem {} | |||
1429 | impl ast::VisibilityOwner for ModuleItem {} | 1429 | impl ast::VisibilityOwner for ModuleItem {} |
1430 | 1430 | ||
1431 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1431 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1432 | pub enum ImplItem { | 1432 | pub enum AssocItem { |
1433 | FnDef(FnDef), | 1433 | FnDef(FnDef), |
1434 | TypeAliasDef(TypeAliasDef), | 1434 | TypeAliasDef(TypeAliasDef), |
1435 | ConstDef(ConstDef), | 1435 | ConstDef(ConstDef), |
1436 | } | 1436 | } |
1437 | impl ast::NameOwner for ImplItem {} | 1437 | impl ast::NameOwner for AssocItem {} |
1438 | impl ast::AttrsOwner for ImplItem {} | 1438 | impl ast::AttrsOwner for AssocItem {} |
1439 | 1439 | ||
1440 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1440 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1441 | pub enum ExternItem { | 1441 | pub enum ExternItem { |
@@ -3167,16 +3167,16 @@ impl AstNode for ModuleItem { | |||
3167 | } | 3167 | } |
3168 | } | 3168 | } |
3169 | } | 3169 | } |
3170 | impl From<FnDef> for ImplItem { | 3170 | impl From<FnDef> for AssocItem { |
3171 | fn from(node: FnDef) -> ImplItem { ImplItem::FnDef(node) } | 3171 | fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) } |
3172 | } | 3172 | } |
3173 | impl From<TypeAliasDef> for ImplItem { | 3173 | impl From<TypeAliasDef> for AssocItem { |
3174 | fn from(node: TypeAliasDef) -> ImplItem { ImplItem::TypeAliasDef(node) } | 3174 | fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } |
3175 | } | 3175 | } |
3176 | impl From<ConstDef> for ImplItem { | 3176 | impl From<ConstDef> for AssocItem { |
3177 | fn from(node: ConstDef) -> ImplItem { ImplItem::ConstDef(node) } | 3177 | fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } |
3178 | } | 3178 | } |
3179 | impl AstNode for ImplItem { | 3179 | impl AstNode for AssocItem { |
3180 | fn can_cast(kind: SyntaxKind) -> bool { | 3180 | fn can_cast(kind: SyntaxKind) -> bool { |
3181 | match kind { | 3181 | match kind { |
3182 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, | 3182 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, |
@@ -3185,18 +3185,18 @@ impl AstNode for ImplItem { | |||
3185 | } | 3185 | } |
3186 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3186 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3187 | let res = match syntax.kind() { | 3187 | let res = match syntax.kind() { |
3188 | FN_DEF => ImplItem::FnDef(FnDef { syntax }), | 3188 | FN_DEF => AssocItem::FnDef(FnDef { syntax }), |
3189 | TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }), | 3189 | TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), |
3190 | CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }), | 3190 | CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), |
3191 | _ => return None, | 3191 | _ => return None, |
3192 | }; | 3192 | }; |
3193 | Some(res) | 3193 | Some(res) |
3194 | } | 3194 | } |
3195 | fn syntax(&self) -> &SyntaxNode { | 3195 | fn syntax(&self) -> &SyntaxNode { |
3196 | match self { | 3196 | match self { |
3197 | ImplItem::FnDef(it) => &it.syntax, | 3197 | AssocItem::FnDef(it) => &it.syntax, |
3198 | ImplItem::TypeAliasDef(it) => &it.syntax, | 3198 | AssocItem::TypeAliasDef(it) => &it.syntax, |
3199 | ImplItem::ConstDef(it) => &it.syntax, | 3199 | AssocItem::ConstDef(it) => &it.syntax, |
3200 | } | 3200 | } |
3201 | } | 3201 | } |
3202 | } | 3202 | } |
@@ -3641,7 +3641,7 @@ impl std::fmt::Display for ModuleItem { | |||
3641 | std::fmt::Display::fmt(self.syntax(), f) | 3641 | std::fmt::Display::fmt(self.syntax(), f) |
3642 | } | 3642 | } |
3643 | } | 3643 | } |
3644 | impl std::fmt::Display for ImplItem { | 3644 | impl std::fmt::Display for AssocItem { |
3645 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | 3645 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
3646 | std::fmt::Display::fmt(self.syntax(), f) | 3646 | std::fmt::Display::fmt(self.syntax(), f) |
3647 | } | 3647 | } |
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 2f8065b73..fe3eb85de 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs | |||
@@ -373,7 +373,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
373 | 373 | ||
374 | struct ItemList: ModuleItemOwner { | 374 | struct ItemList: ModuleItemOwner { |
375 | T!['{'], | 375 | T!['{'], |
376 | impl_items: [ImplItem], | 376 | assoc_items: [AssocItem], |
377 | T!['}'] | 377 | T!['}'] |
378 | } | 378 | } |
379 | 379 | ||
@@ -685,7 +685,7 @@ pub(crate) const AST_SRC: AstSrc = AstSrc { | |||
685 | } | 685 | } |
686 | 686 | ||
687 | /* impl blocks can also contain MacroCall */ | 687 | /* impl blocks can also contain MacroCall */ |
688 | enum ImplItem: NameOwner, AttrsOwner { | 688 | enum AssocItem: NameOwner, AttrsOwner { |
689 | FnDef, TypeAliasDef, ConstDef | 689 | FnDef, TypeAliasDef, ConstDef |
690 | } | 690 | } |
691 | 691 | ||