diff options
Diffstat (limited to 'crates/hir_def/src/item_tree/lower.rs')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 7e91b991d..3f558edd8 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -333,8 +333,8 @@ impl Ctx { | |||
333 | let visibility = self.lower_visibility(func); | 333 | let visibility = self.lower_visibility(func); |
334 | let name = func.name()?.as_name(); | 334 | let name = func.name()?.as_name(); |
335 | 335 | ||
336 | let mut params = Vec::new(); | ||
337 | let mut has_self_param = false; | 336 | let mut has_self_param = false; |
337 | let start_param = self.next_param_idx(); | ||
338 | if let Some(param_list) = func.param_list() { | 338 | if let Some(param_list) = func.param_list() { |
339 | if let Some(self_param) = param_list.self_param() { | 339 | if let Some(self_param) = param_list.self_param() { |
340 | let self_type = match self_param.ty() { | 340 | let self_type = match self_param.ty() { |
@@ -356,22 +356,25 @@ impl Ctx { | |||
356 | } | 356 | } |
357 | } | 357 | } |
358 | }; | 358 | }; |
359 | params.push(self_type); | 359 | let ty = self.data().type_refs.intern(self_type); |
360 | let idx = self.data().params.alloc(Param::Normal(ty)); | ||
361 | self.add_attrs(idx.into(), RawAttrs::new(&self_param, &self.hygiene)); | ||
360 | has_self_param = true; | 362 | has_self_param = true; |
361 | } | 363 | } |
362 | for param in param_list.params() { | 364 | for param in param_list.params() { |
363 | let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); | 365 | let idx = match param.dotdotdot_token() { |
364 | params.push(type_ref); | 366 | Some(_) => self.data().params.alloc(Param::Varargs), |
365 | } | 367 | None => { |
366 | } | 368 | let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); |
367 | let params = params.into_iter().map(|param| self.data().type_refs.intern(param)).collect(); | 369 | let ty = self.data().type_refs.intern(type_ref); |
368 | 370 | self.data().params.alloc(Param::Normal(ty)) | |
369 | let mut is_varargs = false; | 371 | } |
370 | if let Some(params) = func.param_list() { | 372 | }; |
371 | if let Some(last) = params.params().last() { | 373 | self.add_attrs(idx.into(), RawAttrs::new(¶m, &self.hygiene)); |
372 | is_varargs = last.dotdotdot_token().is_some(); | ||
373 | } | 374 | } |
374 | } | 375 | } |
376 | let end_param = self.next_param_idx(); | ||
377 | let params = IdRange::new(start_param..end_param); | ||
375 | 378 | ||
376 | let ret_type = match func.ret_type().and_then(|rt| rt.ty()) { | 379 | let ret_type = match func.ret_type().and_then(|rt| rt.ty()) { |
377 | Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), | 380 | Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), |
@@ -419,7 +422,6 @@ impl Ctx { | |||
419 | qualifier, | 422 | qualifier, |
420 | is_in_extern_block: false, | 423 | is_in_extern_block: false, |
421 | params, | 424 | params, |
422 | is_varargs, | ||
423 | ret_type, | 425 | ret_type, |
424 | ast_id, | 426 | ast_id, |
425 | }; | 427 | }; |
@@ -682,9 +684,11 @@ impl Ctx { | |||
682 | GenericsOwner::Function(func) => { | 684 | GenericsOwner::Function(func) => { |
683 | generics.fill(&self.body_ctx, sm, node); | 685 | generics.fill(&self.body_ctx, sm, node); |
684 | // lower `impl Trait` in arguments | 686 | // lower `impl Trait` in arguments |
685 | for param in &*func.params { | 687 | for id in func.params.clone() { |
686 | let param = self.data().type_refs.lookup(*param); | 688 | if let Param::Normal(ty) = self.data().params[id] { |
687 | generics.fill_implicit_impl_trait_args(param); | 689 | let ty = self.data().type_refs.lookup(ty); |
690 | generics.fill_implicit_impl_trait_args(ty); | ||
691 | } | ||
688 | } | 692 | } |
689 | } | 693 | } |
690 | GenericsOwner::Struct | 694 | GenericsOwner::Struct |
@@ -769,6 +773,11 @@ impl Ctx { | |||
769 | self.tree.data.as_ref().map_or(0, |data| data.variants.len() as u32), | 773 | self.tree.data.as_ref().map_or(0, |data| data.variants.len() as u32), |
770 | )) | 774 | )) |
771 | } | 775 | } |
776 | fn next_param_idx(&self) -> Idx<Param> { | ||
777 | Idx::from_raw(RawIdx::from( | ||
778 | self.tree.data.as_ref().map_or(0, |data| data.params.len() as u32), | ||
779 | )) | ||
780 | } | ||
772 | } | 781 | } |
773 | 782 | ||
774 | fn desugar_future_path(orig: TypeRef) -> Path { | 783 | fn desugar_future_path(orig: TypeRef) -> Path { |