diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/assists/add_missing_impl_members.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 10 |
2 files changed, 16 insertions, 8 deletions
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs index 22f1157cc..942b34dc1 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs | |||
@@ -207,25 +207,23 @@ fn get_syntactic_substs(impl_block: ast::ImplBlock) -> Option<Vec<ast::TypeRef>> | |||
207 | } | 207 | } |
208 | 208 | ||
209 | // FIXME: This should be a general utility (not even just for assists) | 209 | // FIXME: This should be a general utility (not even just for assists) |
210 | fn substitute_type_params<N: AstNode>( | 210 | fn substitute_type_params<N: AstNode + Clone>( |
211 | db: &impl HirDatabase, | 211 | db: &impl HirDatabase, |
212 | node: hir::InFile<N>, | 212 | node: hir::InFile<N>, |
213 | substs: &HashMap<hir::TypeParam, ast::TypeRef>, | 213 | substs: &HashMap<hir::TypeParam, ast::TypeRef>, |
214 | ) -> N { | 214 | ) -> N { |
215 | let type_param_replacements = node | 215 | let type_param_replacements = node |
216 | .value | 216 | .clone() |
217 | .syntax() | 217 | .descendants::<ast::TypeRef>() |
218 | .descendants() | ||
219 | .filter_map(ast::TypeRef::cast) | ||
220 | .filter_map(|n| { | 218 | .filter_map(|n| { |
221 | let path = match &n { | 219 | let path = match &n.value { |
222 | ast::TypeRef::PathType(path_type) => path_type.path()?, | 220 | ast::TypeRef::PathType(path_type) => path_type.path()?, |
223 | _ => return None, | 221 | _ => return None, |
224 | }; | 222 | }; |
225 | let analyzer = hir::SourceAnalyzer::new(db, node.with_value(n.syntax()), None); | 223 | let analyzer = hir::SourceAnalyzer::new(db, n.syntax(), None); |
226 | let resolution = analyzer.resolve_path(db, &path)?; | 224 | let resolution = analyzer.resolve_path(db, &path)?; |
227 | match resolution { | 225 | match resolution { |
228 | hir::PathResolution::TypeParam(tp) => Some((n, substs.get(&tp)?.clone())), | 226 | hir::PathResolution::TypeParam(tp) => Some((n.value, substs.get(&tp)?.clone())), |
229 | _ => None, | 227 | _ => None, |
230 | } | 228 | } |
231 | }) | 229 | }) |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 2fa5d5140..51c5f9623 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -322,3 +322,13 @@ impl InFile<SyntaxNode> { | |||
322 | }) | 322 | }) |
323 | } | 323 | } |
324 | } | 324 | } |
325 | |||
326 | impl<N: AstNode> InFile<N> { | ||
327 | pub fn descendants<T: AstNode>(self) -> impl Iterator<Item = InFile<T>> { | ||
328 | self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n)) | ||
329 | } | ||
330 | |||
331 | pub fn syntax(&self) -> InFile<&SyntaxNode> { | ||
332 | self.with_value(self.value.syntax()) | ||
333 | } | ||
334 | } | ||