aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs65
1 files changed, 63 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index 6139adb72..802937cb0 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -1,7 +1,10 @@
1use super::{infer, type_at, type_at_pos};
2use crate::test_db::TestDB;
3use insta::assert_snapshot; 1use insta::assert_snapshot;
2
4use ra_db::fixture::WithFixture; 3use ra_db::fixture::WithFixture;
4use test_utils::covers;
5
6use super::{infer, infer_with_mismatches, type_at, type_at_pos};
7use crate::test_db::TestDB;
5 8
6#[test] 9#[test]
7fn infer_await() { 10fn infer_await() {
@@ -1486,3 +1489,61 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
1486 // this is a legitimate cycle 1489 // this is a legitimate cycle
1487 assert_eq!(t, "{unknown}"); 1490 assert_eq!(t, "{unknown}");
1488} 1491}
1492
1493#[test]
1494fn unify_impl_trait() {
1495 covers!(insert_vars_for_impl_trait);
1496 assert_snapshot!(
1497 infer_with_mismatches(r#"
1498trait Trait<T> {}
1499
1500fn foo(x: impl Trait<u32>) { loop {} }
1501fn bar<T>(x: impl Trait<T>) -> T { loop {} }
1502
1503struct S<T>(T);
1504impl<T> Trait<T> for S<T> {}
1505
1506fn default<T>() -> T { loop {} }
1507
1508fn test() -> impl Trait<i32> {
1509 let s1 = S(default());
1510 foo(s1);
1511 let x: i32 = bar(S(default()));
1512 S(default())
1513}
1514"#, true),
1515 @r###"
1516 [27; 28) 'x': impl Trait<u32>
1517 [47; 58) '{ loop {} }': ()
1518 [49; 56) 'loop {}': !
1519 [54; 56) '{}': ()
1520 [69; 70) 'x': impl Trait<T>
1521 [92; 103) '{ loop {} }': T
1522 [94; 101) 'loop {}': !
1523 [99; 101) '{}': ()
1524 [172; 183) '{ loop {} }': T
1525 [174; 181) 'loop {}': !
1526 [179; 181) '{}': ()
1527 [214; 310) '{ ...t()) }': S<i32>
1528 [224; 226) 's1': S<u32>
1529 [229; 230) 'S': S<u32>(T) -> S<T>
1530 [229; 241) 'S(default())': S<u32>
1531 [231; 238) 'default': fn default<u32>() -> T
1532 [231; 240) 'default()': u32
1533 [247; 250) 'foo': fn foo(impl Trait<u32>) -> ()
1534 [247; 254) 'foo(s1)': ()
1535 [251; 253) 's1': S<u32>
1536 [264; 265) 'x': i32
1537 [273; 276) 'bar': fn bar<i32>(impl Trait<T>) -> T
1538 [273; 290) 'bar(S(...lt()))': i32
1539 [277; 278) 'S': S<i32>(T) -> S<T>
1540 [277; 289) 'S(default())': S<i32>
1541 [279; 286) 'default': fn default<i32>() -> T
1542 [279; 288) 'default()': i32
1543 [296; 297) 'S': S<i32>(T) -> S<T>
1544 [296; 308) 'S(default())': S<i32>
1545 [298; 305) 'default': fn default<i32>() -> T
1546 [298; 307) 'default()': i32
1547 "###
1548 );
1549}