diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-31 17:50:43 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-31 17:50:43 +0100 |
commit | 5d9145ce10c7dff6caa397b7a6c561848399e4f9 (patch) | |
tree | 8db83308ee58e07dcfd5071462460a8a50f1ce91 /crates/ra_hir_def/src/path | |
parent | 0392a894b7284b13a88a13171e6b8b29764921be (diff) | |
parent | c1c97b289662501cea93fdc10760e08702ff5950 (diff) |
Merge #5629
5629: Finalize Path grammar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/path')
-rw-r--r-- | crates/ra_hir_def/src/path/lower.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 257f9a033..d09fc66e4 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs | |||
@@ -41,7 +41,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> | |||
41 | match hygiene.name_ref_to_name(name_ref) { | 41 | match hygiene.name_ref_to_name(name_ref) { |
42 | Either::Left(name) => { | 42 | Either::Left(name) => { |
43 | let args = segment | 43 | let args = segment |
44 | .type_arg_list() | 44 | .generic_arg_list() |
45 | .and_then(|it| lower_generic_args(&ctx, it)) | 45 | .and_then(|it| lower_generic_args(&ctx, it)) |
46 | .or_else(|| { | 46 | .or_else(|| { |
47 | lower_generic_args_from_fn_path( | 47 | lower_generic_args_from_fn_path( |
@@ -148,33 +148,37 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> | |||
148 | 148 | ||
149 | pub(super) fn lower_generic_args( | 149 | pub(super) fn lower_generic_args( |
150 | lower_ctx: &LowerCtx, | 150 | lower_ctx: &LowerCtx, |
151 | node: ast::TypeArgList, | 151 | node: ast::GenericArgList, |
152 | ) -> Option<GenericArgs> { | 152 | ) -> Option<GenericArgs> { |
153 | let mut args = Vec::new(); | 153 | let mut args = Vec::new(); |
154 | for type_arg in node.type_args() { | ||
155 | let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty()); | ||
156 | args.push(GenericArg::Type(type_ref)); | ||
157 | } | ||
158 | // lifetimes ignored for now | ||
159 | let mut bindings = Vec::new(); | 154 | let mut bindings = Vec::new(); |
160 | for assoc_type_arg in node.assoc_type_args() { | 155 | for generic_arg in node.generic_args() { |
161 | let assoc_type_arg: ast::AssocTypeArg = assoc_type_arg; | 156 | match generic_arg { |
162 | if let Some(name_ref) = assoc_type_arg.name_ref() { | 157 | ast::GenericArg::TypeArg(type_arg) => { |
163 | let name = name_ref.as_name(); | 158 | let type_ref = TypeRef::from_ast_opt(lower_ctx, type_arg.ty()); |
164 | let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); | 159 | args.push(GenericArg::Type(type_ref)); |
165 | let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { | 160 | } |
166 | l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() | 161 | ast::GenericArg::AssocTypeArg(assoc_type_arg) => { |
167 | } else { | 162 | if let Some(name_ref) = assoc_type_arg.name_ref() { |
168 | Vec::new() | 163 | let name = name_ref.as_name(); |
169 | }; | 164 | let type_ref = assoc_type_arg.ty().map(|it| TypeRef::from_ast(lower_ctx, it)); |
170 | bindings.push(AssociatedTypeBinding { name, type_ref, bounds }); | 165 | let bounds = if let Some(l) = assoc_type_arg.type_bound_list() { |
166 | l.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() | ||
167 | } else { | ||
168 | Vec::new() | ||
169 | }; | ||
170 | bindings.push(AssociatedTypeBinding { name, type_ref, bounds }); | ||
171 | } | ||
172 | } | ||
173 | // Lifetimes and constants are ignored for now. | ||
174 | ast::GenericArg::LifetimeArg(_) | ast::GenericArg::ConstArg(_) => (), | ||
171 | } | 175 | } |
172 | } | 176 | } |
177 | |||
173 | if args.is_empty() && bindings.is_empty() { | 178 | if args.is_empty() && bindings.is_empty() { |
174 | None | 179 | return None; |
175 | } else { | ||
176 | Some(GenericArgs { args, has_self_type: false, bindings }) | ||
177 | } | 180 | } |
181 | Some(GenericArgs { args, has_self_type: false, bindings }) | ||
178 | } | 182 | } |
179 | 183 | ||
180 | /// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y) | 184 | /// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y) |