diff options
author | Dmitry <[email protected]> | 2020-08-09 14:35:51 +0100 |
---|---|---|
committer | Dmitry <[email protected]> | 2020-08-09 14:39:32 +0100 |
commit | 8068302fefc75440b823f4bf1731a5f347d7c767 (patch) | |
tree | 251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_assists/src/utils.rs | |
parent | 1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff) | |
parent | 8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_assists/src/utils.rs')
-rw-r--r-- | crates/ra_assists/src/utils.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 02de902d6..54d5678d1 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -56,33 +56,34 @@ pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor | |||
56 | 56 | ||
57 | pub fn get_missing_assoc_items( | 57 | pub fn get_missing_assoc_items( |
58 | sema: &Semantics<RootDatabase>, | 58 | sema: &Semantics<RootDatabase>, |
59 | impl_def: &ast::ImplDef, | 59 | impl_def: &ast::Impl, |
60 | ) -> Vec<hir::AssocItem> { | 60 | ) -> Vec<hir::AssocItem> { |
61 | // Names must be unique between constants and functions. However, type aliases | 61 | // Names must be unique between constants and functions. However, type aliases |
62 | // may share the same name as a function or constant. | 62 | // may share the same name as a function or constant. |
63 | let mut impl_fns_consts = FxHashSet::default(); | 63 | let mut impl_fns_consts = FxHashSet::default(); |
64 | let mut impl_type = FxHashSet::default(); | 64 | let mut impl_type = FxHashSet::default(); |
65 | 65 | ||
66 | if let Some(item_list) = impl_def.item_list() { | 66 | if let Some(item_list) = impl_def.assoc_item_list() { |
67 | for item in item_list.assoc_items() { | 67 | for item in item_list.assoc_items() { |
68 | match item { | 68 | match item { |
69 | ast::AssocItem::FnDef(f) => { | 69 | ast::AssocItem::Fn(f) => { |
70 | if let Some(n) = f.name() { | 70 | if let Some(n) = f.name() { |
71 | impl_fns_consts.insert(n.syntax().to_string()); | 71 | impl_fns_consts.insert(n.syntax().to_string()); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | ast::AssocItem::TypeAliasDef(t) => { | 75 | ast::AssocItem::TypeAlias(t) => { |
76 | if let Some(n) = t.name() { | 76 | if let Some(n) = t.name() { |
77 | impl_type.insert(n.syntax().to_string()); | 77 | impl_type.insert(n.syntax().to_string()); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | ast::AssocItem::ConstDef(c) => { | 81 | ast::AssocItem::Const(c) => { |
82 | if let Some(n) = c.name() { | 82 | if let Some(n) = c.name() { |
83 | impl_fns_consts.insert(n.syntax().to_string()); | 83 | impl_fns_consts.insert(n.syntax().to_string()); |
84 | } | 84 | } |
85 | } | 85 | } |
86 | ast::AssocItem::MacroCall(_) => (), | ||
86 | } | 87 | } |
87 | } | 88 | } |
88 | } | 89 | } |
@@ -108,13 +109,10 @@ pub fn get_missing_assoc_items( | |||
108 | 109 | ||
109 | pub(crate) fn resolve_target_trait( | 110 | pub(crate) fn resolve_target_trait( |
110 | sema: &Semantics<RootDatabase>, | 111 | sema: &Semantics<RootDatabase>, |
111 | impl_def: &ast::ImplDef, | 112 | impl_def: &ast::Impl, |
112 | ) -> Option<hir::Trait> { | 113 | ) -> Option<hir::Trait> { |
113 | let ast_path = impl_def | 114 | let ast_path = |
114 | .target_trait() | 115 | impl_def.trait_().map(|it| it.syntax().clone()).and_then(ast::PathType::cast)?.path()?; |
115 | .map(|it| it.syntax().clone()) | ||
116 | .and_then(ast::PathType::cast)? | ||
117 | .path()?; | ||
118 | 116 | ||
119 | match sema.resolve_path(&ast_path) { | 117 | match sema.resolve_path(&ast_path) { |
120 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), | 118 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def), |
@@ -183,10 +181,10 @@ impl TryEnum { | |||
183 | match self { | 181 | match self { |
184 | TryEnum::Result => make::tuple_struct_pat( | 182 | TryEnum::Result => make::tuple_struct_pat( |
185 | make::path_unqualified(make::path_segment(make::name_ref("Err"))), | 183 | make::path_unqualified(make::path_segment(make::name_ref("Err"))), |
186 | iter::once(make::placeholder_pat().into()), | 184 | iter::once(make::wildcard_pat().into()), |
187 | ) | 185 | ) |
188 | .into(), | 186 | .into(), |
189 | TryEnum::Option => make::bind_pat(make::name("None")).into(), | 187 | TryEnum::Option => make::ident_pat(make::name("None")).into(), |
190 | } | 188 | } |
191 | } | 189 | } |
192 | 190 | ||