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/ast_transform.rs | |
parent | 1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff) | |
parent | 8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_assists/src/ast_transform.rs')
-rw-r--r-- | crates/ra_assists/src/ast_transform.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs index 01adb834c..15ec75c95 100644 --- a/crates/ra_assists/src/ast_transform.rs +++ b/crates/ra_assists/src/ast_transform.rs | |||
@@ -32,7 +32,7 @@ impl<'a> AstTransform<'a> for NullTransformer { | |||
32 | 32 | ||
33 | pub struct SubstituteTypeParams<'a> { | 33 | pub struct SubstituteTypeParams<'a> { |
34 | source_scope: &'a SemanticsScope<'a>, | 34 | source_scope: &'a SemanticsScope<'a>, |
35 | substs: FxHashMap<hir::TypeParam, ast::TypeRef>, | 35 | substs: FxHashMap<hir::TypeParam, ast::Type>, |
36 | previous: Box<dyn AstTransform<'a> + 'a>, | 36 | previous: Box<dyn AstTransform<'a> + 'a>, |
37 | } | 37 | } |
38 | 38 | ||
@@ -41,7 +41,7 @@ impl<'a> SubstituteTypeParams<'a> { | |||
41 | source_scope: &'a SemanticsScope<'a>, | 41 | source_scope: &'a SemanticsScope<'a>, |
42 | // FIXME: there's implicit invariant that `trait_` and `source_scope` match... | 42 | // FIXME: there's implicit invariant that `trait_` and `source_scope` match... |
43 | trait_: hir::Trait, | 43 | trait_: hir::Trait, |
44 | impl_def: ast::ImplDef, | 44 | impl_def: ast::Impl, |
45 | ) -> SubstituteTypeParams<'a> { | 45 | ) -> SubstituteTypeParams<'a> { |
46 | let substs = get_syntactic_substs(impl_def).unwrap_or_default(); | 46 | let substs = get_syntactic_substs(impl_def).unwrap_or_default(); |
47 | let generic_def: hir::GenericDef = trait_.into(); | 47 | let generic_def: hir::GenericDef = trait_.into(); |
@@ -63,7 +63,7 @@ impl<'a> SubstituteTypeParams<'a> { | |||
63 | let default = k.default(source_scope.db)?; | 63 | let default = k.default(source_scope.db)?; |
64 | Some(( | 64 | Some(( |
65 | k, | 65 | k, |
66 | ast::make::type_ref( | 66 | ast::make::ty( |
67 | &default | 67 | &default |
68 | .display_source_code(source_scope.db, source_scope.module()?.into()) | 68 | .display_source_code(source_scope.db, source_scope.module()?.into()) |
69 | .ok()?, | 69 | .ok()?, |
@@ -79,19 +79,25 @@ impl<'a> SubstituteTypeParams<'a> { | |||
79 | }; | 79 | }; |
80 | 80 | ||
81 | // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the | 81 | // FIXME: It would probably be nicer if we could get this via HIR (i.e. get the |
82 | // trait ref, and then go from the types in the substs back to the syntax) | 82 | // 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::Type>> { |
84 | let target_trait = impl_def.target_trait()?; | 84 | let target_trait = impl_def.trait_()?; |
85 | let path_type = match target_trait { | 85 | let path_type = match target_trait { |
86 | ast::TypeRef::PathType(path) => path, | 86 | ast::Type::PathType(path) => path, |
87 | _ => return None, | 87 | _ => return None, |
88 | }; | 88 | }; |
89 | let type_arg_list = path_type.path()?.segment()?.type_arg_list()?; | 89 | let generic_arg_list = path_type.path()?.segment()?.generic_arg_list()?; |
90 | |||
90 | let mut result = Vec::new(); | 91 | let mut result = Vec::new(); |
91 | for type_arg in type_arg_list.type_args() { | 92 | for generic_arg in generic_arg_list.generic_args() { |
92 | let type_arg: ast::TypeArg = type_arg; | 93 | match generic_arg { |
93 | result.push(type_arg.type_ref()?); | 94 | ast::GenericArg::TypeArg(type_arg) => result.push(type_arg.ty()?), |
95 | ast::GenericArg::AssocTypeArg(_) | ||
96 | | ast::GenericArg::LifetimeArg(_) | ||
97 | | ast::GenericArg::ConstArg(_) => (), | ||
98 | } | ||
94 | } | 99 | } |
100 | |||
95 | Some(result) | 101 | Some(result) |
96 | } | 102 | } |
97 | } | 103 | } |
@@ -99,9 +105,9 @@ impl<'a> SubstituteTypeParams<'a> { | |||
99 | &self, | 105 | &self, |
100 | node: &ra_syntax::SyntaxNode, | 106 | node: &ra_syntax::SyntaxNode, |
101 | ) -> Option<ra_syntax::SyntaxNode> { | 107 | ) -> Option<ra_syntax::SyntaxNode> { |
102 | let type_ref = ast::TypeRef::cast(node.clone())?; | 108 | let type_ref = ast::Type::cast(node.clone())?; |
103 | let path = match &type_ref { | 109 | let path = match &type_ref { |
104 | ast::TypeRef::PathType(path_type) => path_type.path()?, | 110 | ast::Type::PathType(path_type) => path_type.path()?, |
105 | _ => return None, | 111 | _ => return None, |
106 | }; | 112 | }; |
107 | // FIXME: use `hir::Path::from_src` instead. | 113 | // FIXME: use `hir::Path::from_src` instead. |
@@ -157,7 +163,7 @@ impl<'a> QualifyPaths<'a> { | |||
157 | 163 | ||
158 | let type_args = p | 164 | let type_args = p |
159 | .segment() | 165 | .segment() |
160 | .and_then(|s| s.type_arg_list()) | 166 | .and_then(|s| s.generic_arg_list()) |
161 | .map(|arg_list| apply(self, arg_list)); | 167 | .map(|arg_list| apply(self, arg_list)); |
162 | if let Some(type_args) = type_args { | 168 | if let Some(type_args) = type_args { |
163 | let last_segment = path.segment().unwrap(); | 169 | let last_segment = path.segment().unwrap(); |