3165: Fix coercion of &T to itself r=matklad a=flodiebold

The autoderef coercion logic did not handle matching placeholders. This led to
some type mismatches.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2020-02-16 12:03:42 +00:00 committed by GitHub
commit 77d27c67c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -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)))

View File

@ -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: T }
impl<TT> S<TT> {
fn get(&self) -> &TT {
&self.t
}
}
"#, true),
@r###"
[51; 55) 'self': &S<TT>
[64; 87) '{ ... }': &TT
[74; 81) '&self.t': &TT
[75; 79) 'self': &S<TT>
[75; 81) 'self.t': TT
"###
);
}