From 31171eed5eeab217280237e63ffe6adda62baf96 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 29 Feb 2020 22:48:23 +0100 Subject: Do autoderef for indexing --- crates/ra_hir_ty/src/infer/expr.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') 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> { let base_ty = self.infer_expr_inner(*base, &Expectation::none()); let index_ty = self.infer_expr(*index, &Expectation::none()); - self.resolve_associated_type_with_params( - base_ty, - self.resolve_ops_index_output(), - &[index_ty], - ) + if let (Some(index_trait), Some(krate)) = + (self.resolve_ops_index(), self.resolver.krate()) + { + let canonicalized = self.canonicalizer().canonicalize_ty(base_ty); + let self_ty = method_resolution::resolve_indexing_op( + self.db, + &canonicalized.value, + self.trait_env.clone(), + krate, + index_trait, + ); + let self_ty = + self_ty.map_or(Ty::Unknown, |t| canonicalized.decanonicalize_ty(t.value)); + self.resolve_associated_type_with_params( + self_ty, + self.resolve_ops_index_output(), + &[index_ty], + ) + } else { + Ty::Unknown + } } Expr::Tuple { exprs } => { let mut tys = match &expected.ty { -- cgit v1.2.3