diff options
author | Florian Diebold <[email protected]> | 2020-03-01 13:31:35 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-03-01 13:31:35 +0000 |
commit | 336a3c6121edf54a19728dbbd880f62bc835d7c8 (patch) | |
tree | 7cfbf56ccaf53e8e008798a3569c70e21516c5c9 /crates/ra_hir_ty/src/method_resolution.rs | |
parent | 6db2da4993d3956fc7c8ebf152963a132611426a (diff) |
Fix #3373
Basically, we need to allow variables in the caller self type to unify with the
impl's declared self type. That requires some more contortions in the variable
handling. I'm looking forward to (hopefully) handling this in a cleaner way when
we switch to Chalk's types and unification code.
Diffstat (limited to 'crates/ra_hir_ty/src/method_resolution.rs')
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 74b908c2e..b7e8855fb 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -508,10 +508,17 @@ pub(crate) fn inherent_impl_substs( | |||
508 | impl_id: ImplId, | 508 | impl_id: ImplId, |
509 | self_ty: &Canonical<Ty>, | 509 | self_ty: &Canonical<Ty>, |
510 | ) -> Option<Substs> { | 510 | ) -> Option<Substs> { |
511 | let vars = Substs::build_for_def(db, impl_id).fill_with_bound_vars(0).build(); | 511 | // we create a var for each type parameter of the impl; we need to keep in |
512 | // mind here that `self_ty` might have vars of its own | ||
513 | let vars = | ||
514 | Substs::build_for_def(db, impl_id).fill_with_bound_vars(self_ty.num_vars as u32).build(); | ||
512 | let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); | 515 | let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); |
513 | let self_ty_with_vars = Canonical { num_vars: vars.len(), value: self_ty_with_vars }; | 516 | let self_ty_with_vars = |
514 | super::infer::unify(&self_ty_with_vars, self_ty) | 517 | Canonical { num_vars: vars.len() + self_ty.num_vars, value: self_ty_with_vars }; |
518 | let substs = super::infer::unify(&self_ty_with_vars, self_ty); | ||
519 | // we only want the substs for the vars we added, not the ones from self_ty | ||
520 | let result = substs.map(|s| s.suffix(vars.len())); | ||
521 | result | ||
515 | } | 522 | } |
516 | 523 | ||
517 | fn transform_receiver_ty( | 524 | fn transform_receiver_ty( |