aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-18 09:48:08 +0100
committerGitHub <[email protected]>2020-04-18 09:48:08 +0100
commit162481d5ce87a250c3144e7d9a7c72a6032b023d (patch)
tree25056d4c632ef9b149514a72a169e46b13d6b777 /crates/ra_hir_ty/src/tests
parent746b2e003e695753efb71981548e99a95661f13f (diff)
parentd3cb9ea0bfb6c9e6c8b57a46feb1de696084d994 (diff)
Merge #4023
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 <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index f6e3e07cd..a46f03b7f 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -1211,6 +1211,42 @@ fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1211} 1211}
1212 1212
1213#[test] 1213#[test]
1214fn dyn_trait_in_impl() {
1215 assert_snapshot!(
1216 infer(r#"
1217trait Trait<T, U> {
1218 fn foo(&self) -> (T, U);
1219}
1220struct S<T, U> {}
1221impl<T, U> S<T, U> {
1222 fn bar(&self) -> &dyn Trait<T, U> { loop {} }
1223}
1224trait Trait2<T, U> {
1225 fn baz(&self) -> (T, U);
1226}
1227impl<T, U> Trait2<T, U> for dyn Trait<T, U> { }
1228
1229fn test(s: S<u32, i32>) {
1230 s.bar().baz();
1231}
1232"#),
1233 @r###"
1234 [33; 37) 'self': &Self
1235 [103; 107) 'self': &S<T, U>
1236 [129; 140) '{ loop {} }': &dyn Trait<T, U>
1237 [131; 138) 'loop {}': !
1238 [136; 138) '{}': ()
1239 [176; 180) 'self': &Self
1240 [252; 253) 's': S<u32, i32>
1241 [268; 290) '{ ...z(); }': ()
1242 [274; 275) 's': S<u32, i32>
1243 [274; 281) 's.bar()': &dyn Trait<u32, i32>
1244 [274; 287) 's.bar().baz()': (u32, i32)
1245 "###
1246 );
1247}
1248
1249#[test]
1214fn dyn_trait_bare() { 1250fn dyn_trait_bare() {
1215 assert_snapshot!( 1251 assert_snapshot!(
1216 infer(r#" 1252 infer(r#"