diff options
author | Florian Diebold <[email protected]> | 2019-12-06 11:45:00 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-12-15 16:45:32 +0000 |
commit | ac961b261458bfeb23f7d4e896d5f957b0854a3a (patch) | |
tree | da8ce27cbc5a056c8a58cb839aeacaebbfa83963 /crates | |
parent | 4e24b25c669965cf6a68c4b8e775cc83615d978a (diff) |
Add test for unifying impl Trait
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 6139adb72..a926d01e5 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use super::{infer, type_at, type_at_pos}; | 1 | use super::{infer, infer_with_mismatches, type_at, type_at_pos}; |
2 | use crate::test_db::TestDB; | 2 | use crate::test_db::TestDB; |
3 | use insta::assert_snapshot; | 3 | use insta::assert_snapshot; |
4 | use ra_db::fixture::WithFixture; | 4 | use ra_db::fixture::WithFixture; |
@@ -1486,3 +1486,29 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { | |||
1486 | // this is a legitimate cycle | 1486 | // this is a legitimate cycle |
1487 | assert_eq!(t, "{unknown}"); | 1487 | assert_eq!(t, "{unknown}"); |
1488 | } | 1488 | } |
1489 | |||
1490 | #[test] | ||
1491 | fn unify_impl_trait() { | ||
1492 | assert_snapshot!( | ||
1493 | infer_with_mismatches(r#" | ||
1494 | trait Trait<T> {} | ||
1495 | |||
1496 | fn foo(x: impl Trait<u32>) { loop {} } | ||
1497 | fn bar<T>(x: impl Trait<T>) -> T { loop {} } | ||
1498 | |||
1499 | struct S<T>(T); | ||
1500 | impl<T> Trait<T> for S<T> {} | ||
1501 | |||
1502 | fn default<T>() -> T { loop {} } | ||
1503 | |||
1504 | fn test() -> impl Trait<i32> { | ||
1505 | let s1 = S(default()); | ||
1506 | foo(s1); | ||
1507 | let x: i32 = bar(S(default())); | ||
1508 | S(default()) | ||
1509 | } | ||
1510 | "#, true), | ||
1511 | @r###" | ||
1512 | "### | ||
1513 | ); | ||
1514 | } | ||