diff options
author | Florian Diebold <[email protected]> | 2020-04-17 21:48:29 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-04-17 23:01:09 +0100 |
commit | d3cb9ea0bfb6c9e6c8b57a46feb1de696084d994 (patch) | |
tree | dec68fc67c90737820b81da02f4f03028d12b43d /crates/ra_hir_ty/src/tests | |
parent | a4cda3efbbabe4c6129de4dc095953fe858d7d3f (diff) |
Fix another crash from wrong binders
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.
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 36 |
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 0a889f805..36f53b264 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] |
1214 | fn dyn_trait_in_impl() { | ||
1215 | assert_snapshot!( | ||
1216 | infer(r#" | ||
1217 | trait Trait<T, U> { | ||
1218 | fn foo(&self) -> (T, U); | ||
1219 | } | ||
1220 | struct S<T, U> {} | ||
1221 | impl<T, U> S<T, U> { | ||
1222 | fn bar(&self) -> &dyn Trait<T, U> { loop {} } | ||
1223 | } | ||
1224 | trait Trait2<T, U> { | ||
1225 | fn baz(&self) -> (T, U); | ||
1226 | } | ||
1227 | impl<T, U> Trait2<T, U> for dyn Trait<T, U> { } | ||
1228 | |||
1229 | fn 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] | ||
1214 | fn dyn_trait_bare() { | 1250 | fn dyn_trait_bare() { |
1215 | assert_snapshot!( | 1251 | assert_snapshot!( |
1216 | infer(r#" | 1252 | infer(r#" |