4023: Fix another crash from wrong binders r=matklad a=flodiebold

Basically, if we had something like `dyn Trait<T>` (where `T` is a type parameter) in an impl we lowered that to `dyn Trait<^0.0>`, when it should be `dyn Trait<^1.0>` because the `dyn` introduces a new binder. With one type parameter, that's just wrong, with two, it'll lead to crashes.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2020-04-18 08:48:08 +00:00 committed by GitHub
commit 162481d5ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 27 deletions

View file

@ -1210,6 +1210,42 @@ fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
);
}
#[test]
fn dyn_trait_in_impl() {
assert_snapshot!(
infer(r#"
trait Trait<T, U> {
fn foo(&self) -> (T, U);
}
struct S<T, U> {}
impl<T, U> S<T, U> {
fn bar(&self) -> &dyn Trait<T, U> { loop {} }
}
trait Trait2<T, U> {
fn baz(&self) -> (T, U);
}
impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
fn test(s: S<u32, i32>) {
s.bar().baz();
}
"#),
@r###"
[33; 37) 'self': &Self
[103; 107) 'self': &S<T, U>
[129; 140) '{ loop {} }': &dyn Trait<T, U>
[131; 138) 'loop {}': !
[136; 138) '{}': ()
[176; 180) 'self': &Self
[252; 253) 's': S<u32, i32>
[268; 290) '{ ...z(); }': ()
[274; 275) 's': S<u32, i32>
[274; 281) 's.bar()': &dyn Trait<u32, i32>
[274; 287) 's.bar().baz()': (u32, i32)
"###
);
}
#[test]
fn dyn_trait_bare() {
assert_snapshot!(