aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-12-06 11:45:00 +0000
committerFlorian Diebold <[email protected]>2019-12-15 16:45:32 +0000
commitac961b261458bfeb23f7d4e896d5f957b0854a3a (patch)
treeda8ce27cbc5a056c8a58cb839aeacaebbfa83963 /crates/ra_hir_ty/src/tests
parent4e24b25c669965cf6a68c4b8e775cc83615d978a (diff)
Add test for unifying impl Trait
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs28
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 @@
1use super::{infer, type_at, type_at_pos}; 1use super::{infer, infer_with_mismatches, type_at, type_at_pos};
2use crate::test_db::TestDB; 2use crate::test_db::TestDB;
3use insta::assert_snapshot; 3use insta::assert_snapshot;
4use ra_db::fixture::WithFixture; 4use 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]
1491fn unify_impl_trait() {
1492 assert_snapshot!(
1493 infer_with_mismatches(r#"
1494trait Trait<T> {}
1495
1496fn foo(x: impl Trait<u32>) { loop {} }
1497fn bar<T>(x: impl Trait<T>) -> T { loop {} }
1498
1499struct S<T>(T);
1500impl<T> Trait<T> for S<T> {}
1501
1502fn default<T>() -> T { loop {} }
1503
1504fn 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}