diff options
author | Florian Diebold <[email protected]> | 2020-02-29 21:48:23 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-02-29 21:48:53 +0000 |
commit | 31171eed5eeab217280237e63ffe6adda62baf96 (patch) | |
tree | 0597ebf09ac6c3216477c4993a8f16686f0ca452 /crates/ra_hir_ty/src/infer/expr.rs | |
parent | e313efb9926be80a5d7614d800e425b6891cf7d9 (diff) |
Do autoderef for indexing
Diffstat (limited to 'crates/ra_hir_ty/src/infer/expr.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 3db5b2b51..e89cc7298 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -429,11 +429,27 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
429 | let base_ty = self.infer_expr_inner(*base, &Expectation::none()); | 429 | let base_ty = self.infer_expr_inner(*base, &Expectation::none()); |
430 | let index_ty = self.infer_expr(*index, &Expectation::none()); | 430 | let index_ty = self.infer_expr(*index, &Expectation::none()); |
431 | 431 | ||
432 | self.resolve_associated_type_with_params( | 432 | if let (Some(index_trait), Some(krate)) = |
433 | base_ty, | 433 | (self.resolve_ops_index(), self.resolver.krate()) |
434 | self.resolve_ops_index_output(), | 434 | { |
435 | &[index_ty], | 435 | let canonicalized = self.canonicalizer().canonicalize_ty(base_ty); |
436 | ) | 436 | let self_ty = method_resolution::resolve_indexing_op( |
437 | self.db, | ||
438 | &canonicalized.value, | ||
439 | self.trait_env.clone(), | ||
440 | krate, | ||
441 | index_trait, | ||
442 | ); | ||
443 | let self_ty = | ||
444 | self_ty.map_or(Ty::Unknown, |t| canonicalized.decanonicalize_ty(t.value)); | ||
445 | self.resolve_associated_type_with_params( | ||
446 | self_ty, | ||
447 | self.resolve_ops_index_output(), | ||
448 | &[index_ty], | ||
449 | ) | ||
450 | } else { | ||
451 | Ty::Unknown | ||
452 | } | ||
437 | } | 453 | } |
438 | Expr::Tuple { exprs } => { | 454 | Expr::Tuple { exprs } => { |
439 | let mut tys = match &expected.ty { | 455 | let mut tys = match &expected.ty { |