From e14e7ffa34bf9a458681fe7490ac2d51b02ff908 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 16 Feb 2020 12:57:19 +0100 Subject: Fix coercion of &T to itself The autoderef coercion logic did not handle matching placeholders. This led to some type mismatches. --- crates/ra_hir_ty/src/infer/unify.rs | 2 ++ crates/ra_hir_ty/src/tests/coercion.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'crates') diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs index fe05642ae..1dc842f40 100644 --- a/crates/ra_hir_ty/src/infer/unify.rs +++ b/crates/ra_hir_ty/src/infer/unify.rs @@ -249,6 +249,8 @@ impl InferenceTable { match (ty1, ty2) { (Ty::Unknown, _) | (_, Ty::Unknown) => true, + (Ty::Placeholder(p1), Ty::Placeholder(p2)) if *p1 == *p2 => true, + (Ty::Infer(InferTy::TypeVar(tv1)), Ty::Infer(InferTy::TypeVar(tv2))) | (Ty::Infer(InferTy::IntVar(tv1)), Ty::Infer(InferTy::IntVar(tv2))) | (Ty::Infer(InferTy::FloatVar(tv1)), Ty::Infer(InferTy::FloatVar(tv2))) diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index fc5ef36a5..42330b269 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs @@ -526,3 +526,25 @@ fn test() { "### ); } + +#[test] +fn coerce_placeholder_ref() { + // placeholders should unify, even behind references + assert_snapshot!( + infer_with_mismatches(r#" +struct S { t: T } +impl S { + fn get(&self) -> &TT { + &self.t + } +} +"#, true), + @r###" + [51; 55) 'self': &S + [64; 87) '{ ... }': &TT + [74; 81) '&self.t': &TT + [75; 79) 'self': &S + [75; 81) 'self.t': TT + "### + ); +} -- cgit v1.2.3