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 d684b89d0..d3fe1ce1e 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -341,8 +341,8 @@ impl Ctx { | |||
341 | let visibility = self.lower_visibility(func); | 341 | let visibility = self.lower_visibility(func); |
342 | let name = func.name()?.as_name(); | 342 | let name = func.name()?.as_name(); |
343 | 343 | ||
344 | let mut params = Vec::new(); | ||
345 | let mut has_self_param = false; | 344 | let mut has_self_param = false; |
345 | let start_param = self.next_param_idx(); | ||
346 | if let Some(param_list) = func.param_list() { | 346 | if let Some(param_list) = func.param_list() { |
347 | if let Some(self_param) = param_list.self_param() { | 347 | if let Some(self_param) = param_list.self_param() { |
348 | let self_type = match self_param.ty() { | 348 | let self_type = match self_param.ty() { |
@@ -364,22 +364,25 @@ impl Ctx { | |||
364 | } | 364 | } |
365 | } | 365 | } |
366 | }; | 366 | }; |
367 | params.push(self_type); | 367 | let ty = self.data().type_refs.intern(self_type); |
368 | let idx = self.data().params.alloc(Param::Normal(ty)); | ||
369 | self.add_attrs(idx.into(), RawAttrs::new(&self_param, &self.hygiene)); | ||
368 | has_self_param = true; | 370 | has_self_param = true; |
369 | } | 371 | } |
370 | for param in param_list.params() { | 372 | for param in param_list.params() { |
371 | let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); | 373 | let idx = match param.dotdotdot_token() { |
372 | params.push(type_ref); | 374 | Some(_) => self.data().params.alloc(Param::Varargs), |
373 | } | 375 | None => { |
374 | } | 376 | let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); |
375 | let params = params.into_iter().map(|param| self.data().type_refs.intern(param)).collect(); | 377 | let ty = self.data().type_refs.intern(type_ref); |
376 | 378 | self.data().params.alloc(Param::Normal(ty)) | |
377 | let mut is_varargs = false; | 379 | } |
378 | if let Some(params) = func.param_list() { | 380 | }; |
379 | if let Some(last) = params.params().last() { | 381 | self.add_attrs(idx.into(), RawAttrs::new(¶m, &self.hygiene)); |
380 | is_varargs = last.dotdotdot_token().is_some(); | ||
381 | } | 382 | } |
382 | } | 383 | } |
384 | let end_param = self.next_param_idx(); | ||
385 | let params = IdRange::new(start_param..end_param); | ||
383 | 386 | ||
384 | let ret_type = match func.ret_type().and_then(|rt| rt.ty()) { | 387 | let ret_type = match func.ret_type().and_then(|rt| rt.ty()) { |
385 | Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), | 388 | Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), |
@@ -427,7 +430,6 @@ impl Ctx { | |||
427 | qualifier, | 430 | qualifier, |
428 | is_in_extern_block: false, | 431 | is_in_extern_block: false, |
429 | params, | 432 | params, |
430 | is_varargs, | ||
431 | ret_type, | 433 | ret_type, |
432 | ast_id, | 434 | ast_id, |
433 | }; | 435 | }; |
@@ -690,9 +692,11 @@ impl Ctx { | |||
690 | GenericsOwner::Function(func) => { | 692 | GenericsOwner::Function(func) => { |
691 | generics.fill(&self.body_ctx, sm, node); | 693 | generics.fill(&self.body_ctx, sm, node); |
692 | // lower `impl Trait` in arguments | 694 | // lower `impl Trait` in arguments |
693 | for param in &*func.params { | 695 | for id in func.params.clone() { |
694 | let param = self.data().type_refs.lookup(*param); | 696 | if let Param::Normal(ty) = self.data().params[id] { |
695 | generics.fill_implicit_impl_trait_args(param); | 697 | let ty = self.data().type_refs.lookup(ty); |
698 | generics.fill_implicit_impl_trait_args(ty); | ||
699 | } | ||
696 | } | 700 | } |
697 | } | 701 | } |
698 | GenericsOwner::Struct | 702 | GenericsOwner::Struct |
@@ -777,6 +781,11 @@ impl Ctx { | |||
777 | self.tree.data.as_ref().map_or(0, |data| data.variants.len() as u32), | 781 | self.tree.data.as_ref().map_or(0, |data| data.variants.len() as u32), |
778 | )) | 782 | )) |
779 | } | 783 | } |
784 | fn next_param_idx(&self) -> Idx<Param> { | ||
785 | Idx::from_raw(RawIdx::from( | ||
786 | self.tree.data.as_ref().map_or(0, |data| data.params.len() as u32), | ||
787 | )) | ||
788 | } | ||
780 | } | 789 | } |
781 | 790 | ||
782 | fn desugar_future_path(orig: TypeRef) -> Path { | 791 | fn desugar_future_path(orig: TypeRef) -> Path { |