diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/coercion.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/method_resolution.rs | 33 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/patterns.rs | 43 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 46 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 107 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 292 |
6 files changed, 509 insertions, 18 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 6dc4b2cd1..2cc4f4bf9 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use super::infer_with_mismatches; | 1 | use super::infer_with_mismatches; |
2 | use insta::assert_snapshot; | 2 | use insta::assert_snapshot; |
3 | use test_utils::covers; | 3 | use test_utils::mark; |
4 | 4 | ||
5 | // Infer with some common definitions and impls. | 5 | // Infer with some common definitions and impls. |
6 | fn infer(source: &str) -> String { | 6 | fn infer(source: &str) -> String { |
@@ -339,7 +339,7 @@ fn test(i: i32) { | |||
339 | 339 | ||
340 | #[test] | 340 | #[test] |
341 | fn coerce_merge_one_by_one1() { | 341 | fn coerce_merge_one_by_one1() { |
342 | covers!(coerce_merge_fail_fallback); | 342 | mark::check!(coerce_merge_fail_fallback); |
343 | 343 | ||
344 | assert_snapshot!( | 344 | assert_snapshot!( |
345 | infer(r#" | 345 | infer(r#" |
@@ -547,7 +547,7 @@ fn test() { | |||
547 | 547 | ||
548 | #[test] | 548 | #[test] |
549 | fn coerce_fn_items_in_match_arms() { | 549 | fn coerce_fn_items_in_match_arms() { |
550 | covers!(coerce_fn_reification); | 550 | mark::check!(coerce_fn_reification); |
551 | assert_snapshot!( | 551 | assert_snapshot!( |
552 | infer_with_mismatches(r#" | 552 | infer_with_mismatches(r#" |
553 | fn foo1(x: u32) -> isize { 1 } | 553 | fn foo1(x: u32) -> isize { 1 } |
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index 67f964ab5..558a70022 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs | |||
@@ -984,7 +984,7 @@ fn test() { S2.into()<|>; } | |||
984 | 984 | ||
985 | #[test] | 985 | #[test] |
986 | fn method_resolution_overloaded_method() { | 986 | fn method_resolution_overloaded_method() { |
987 | test_utils::covers!(impl_self_type_match_without_receiver); | 987 | test_utils::mark::check!(impl_self_type_match_without_receiver); |
988 | let t = type_at( | 988 | let t = type_at( |
989 | r#" | 989 | r#" |
990 | //- main.rs | 990 | //- main.rs |
@@ -1096,3 +1096,34 @@ fn test() { (S {}).method()<|>; } | |||
1096 | ); | 1096 | ); |
1097 | assert_eq!(t, "()"); | 1097 | assert_eq!(t, "()"); |
1098 | } | 1098 | } |
1099 | |||
1100 | #[test] | ||
1101 | fn dyn_trait_super_trait_not_in_scope() { | ||
1102 | assert_snapshot!( | ||
1103 | infer(r#" | ||
1104 | mod m { | ||
1105 | pub trait SuperTrait { | ||
1106 | fn foo(&self) -> u32 { 0 } | ||
1107 | } | ||
1108 | } | ||
1109 | trait Trait: m::SuperTrait {} | ||
1110 | |||
1111 | struct S; | ||
1112 | impl m::SuperTrait for S {} | ||
1113 | impl Trait for S {} | ||
1114 | |||
1115 | fn test(d: &dyn Trait) { | ||
1116 | d.foo(); | ||
1117 | } | ||
1118 | "#), | ||
1119 | @r###" | ||
1120 | 52..56 'self': &Self | ||
1121 | 65..70 '{ 0 }': u32 | ||
1122 | 67..68 '0': u32 | ||
1123 | 177..178 'd': &dyn Trait | ||
1124 | 192..208 '{ ...o(); }': () | ||
1125 | 198..199 'd': &dyn Trait | ||
1126 | 198..205 'd.foo()': u32 | ||
1127 | "### | ||
1128 | ); | ||
1129 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index af291092d..0c5f972a2 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use insta::assert_snapshot; | 1 | use insta::assert_snapshot; |
2 | use test_utils::covers; | 2 | use test_utils::mark; |
3 | 3 | ||
4 | use super::{infer, infer_with_mismatches}; | 4 | use super::{infer, infer_with_mismatches}; |
5 | 5 | ||
@@ -197,7 +197,7 @@ fn test() { | |||
197 | 197 | ||
198 | #[test] | 198 | #[test] |
199 | fn infer_pattern_match_ergonomics_ref() { | 199 | fn infer_pattern_match_ergonomics_ref() { |
200 | covers!(match_ergonomics_ref); | 200 | mark::check!(match_ergonomics_ref); |
201 | assert_snapshot!( | 201 | assert_snapshot!( |
202 | infer(r#" | 202 | infer(r#" |
203 | fn test() { | 203 | fn test() { |
@@ -369,6 +369,45 @@ fn test() { | |||
369 | } | 369 | } |
370 | 370 | ||
371 | #[test] | 371 | #[test] |
372 | fn enum_variant_through_self_in_pattern() { | ||
373 | assert_snapshot!( | ||
374 | infer(r#" | ||
375 | enum E { | ||
376 | A { x: usize }, | ||
377 | B(usize), | ||
378 | C | ||
379 | } | ||
380 | |||
381 | impl E { | ||
382 | fn test() { | ||
383 | match (loop {}) { | ||
384 | Self::A { x } => { x; }, | ||
385 | Self::B(x) => { x; }, | ||
386 | Self::C => {}, | ||
387 | }; | ||
388 | } | ||
389 | } | ||
390 | "#), | ||
391 | @r###" | ||
392 | 76..218 '{ ... }': () | ||
393 | 86..211 'match ... }': () | ||
394 | 93..100 'loop {}': ! | ||
395 | 98..100 '{}': () | ||
396 | 116..129 'Self::A { x }': E | ||
397 | 126..127 'x': usize | ||
398 | 133..139 '{ x; }': () | ||
399 | 135..136 'x': usize | ||
400 | 153..163 'Self::B(x)': E | ||
401 | 161..162 'x': usize | ||
402 | 167..173 '{ x; }': () | ||
403 | 169..170 'x': usize | ||
404 | 187..194 'Self::C': E | ||
405 | 198..200 '{}': () | ||
406 | "### | ||
407 | ); | ||
408 | } | ||
409 | |||
410 | #[test] | ||
372 | fn infer_generics_in_patterns() { | 411 | fn infer_generics_in_patterns() { |
373 | assert_snapshot!( | 412 | assert_snapshot!( |
374 | infer(r#" | 413 | infer(r#" |
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 115ad8328..1f004bd63 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -1,9 +1,10 @@ | |||
1 | use insta::assert_snapshot; | 1 | use insta::assert_snapshot; |
2 | use test_utils::covers; | 2 | use ra_db::fixture::WithFixture; |
3 | use test_utils::mark; | ||
3 | 4 | ||
4 | use super::infer; | ||
5 | use crate::test_db::TestDB; | 5 | use crate::test_db::TestDB; |
6 | use ra_db::fixture::WithFixture; | 6 | |
7 | use super::infer; | ||
7 | 8 | ||
8 | #[test] | 9 | #[test] |
9 | fn bug_484() { | 10 | fn bug_484() { |
@@ -89,8 +90,8 @@ fn quux() { | |||
89 | 90 | ||
90 | #[test] | 91 | #[test] |
91 | fn recursive_vars() { | 92 | fn recursive_vars() { |
92 | covers!(type_var_cycles_resolve_completely); | 93 | mark::check!(type_var_cycles_resolve_completely); |
93 | covers!(type_var_cycles_resolve_as_possible); | 94 | mark::check!(type_var_cycles_resolve_as_possible); |
94 | assert_snapshot!( | 95 | assert_snapshot!( |
95 | infer(r#" | 96 | infer(r#" |
96 | fn test() { | 97 | fn test() { |
@@ -112,8 +113,6 @@ fn test() { | |||
112 | 113 | ||
113 | #[test] | 114 | #[test] |
114 | fn recursive_vars_2() { | 115 | fn recursive_vars_2() { |
115 | covers!(type_var_cycles_resolve_completely); | ||
116 | covers!(type_var_cycles_resolve_as_possible); | ||
117 | assert_snapshot!( | 116 | assert_snapshot!( |
118 | infer(r#" | 117 | infer(r#" |
119 | fn test() { | 118 | fn test() { |
@@ -170,7 +169,7 @@ fn write() { | |||
170 | 169 | ||
171 | #[test] | 170 | #[test] |
172 | fn infer_std_crash_2() { | 171 | fn infer_std_crash_2() { |
173 | covers!(type_var_resolves_to_int_var); | 172 | mark::check!(type_var_resolves_to_int_var); |
174 | // caused "equating two type variables, ...", taken from std | 173 | // caused "equating two type variables, ...", taken from std |
175 | assert_snapshot!( | 174 | assert_snapshot!( |
176 | infer(r#" | 175 | infer(r#" |
@@ -564,6 +563,37 @@ fn main() { | |||
564 | } | 563 | } |
565 | 564 | ||
566 | #[test] | 565 | #[test] |
566 | fn issue_4465_dollar_crate_at_type() { | ||
567 | assert_snapshot!( | ||
568 | infer(r#" | ||
569 | pub struct Foo {} | ||
570 | pub fn anything<T>() -> T { | ||
571 | loop {} | ||
572 | } | ||
573 | macro_rules! foo { | ||
574 | () => {{ | ||
575 | let r: $crate::Foo = anything(); | ||
576 | r | ||
577 | }}; | ||
578 | } | ||
579 | fn main() { | ||
580 | let _a = foo!(); | ||
581 | } | ||
582 | "#), @r###" | ||
583 | 45..60 '{ loop {} }': T | ||
584 | 51..58 'loop {}': ! | ||
585 | 56..58 '{}': () | ||
586 | !0..31 '{letr:...g();r}': Foo | ||
587 | !4..5 'r': Foo | ||
588 | !18..26 'anything': fn anything<Foo>() -> Foo | ||
589 | !18..28 'anything()': Foo | ||
590 | !29..30 'r': Foo | ||
591 | 164..188 '{ ...!(); }': () | ||
592 | 174..176 '_a': Foo | ||
593 | "###); | ||
594 | } | ||
595 | |||
596 | #[test] | ||
567 | fn issue_4053_diesel_where_clauses() { | 597 | fn issue_4053_diesel_where_clauses() { |
568 | assert_snapshot!( | 598 | assert_snapshot!( |
569 | infer(r#" | 599 | infer(r#" |
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 322838f02..fd2208af2 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -576,6 +576,50 @@ impl S { | |||
576 | } | 576 | } |
577 | 577 | ||
578 | #[test] | 578 | #[test] |
579 | fn infer_self_as_path() { | ||
580 | assert_snapshot!( | ||
581 | infer(r#" | ||
582 | struct S1; | ||
583 | struct S2(isize); | ||
584 | enum E { | ||
585 | V1, | ||
586 | V2(u32), | ||
587 | } | ||
588 | |||
589 | impl S1 { | ||
590 | fn test() { | ||
591 | Self; | ||
592 | } | ||
593 | } | ||
594 | impl S2 { | ||
595 | fn test() { | ||
596 | Self(1); | ||
597 | } | ||
598 | } | ||
599 | impl E { | ||
600 | fn test() { | ||
601 | Self::V1; | ||
602 | Self::V2(1); | ||
603 | } | ||
604 | } | ||
605 | "#), | ||
606 | @r###" | ||
607 | 87..108 '{ ... }': () | ||
608 | 97..101 'Self': S1 | ||
609 | 135..159 '{ ... }': () | ||
610 | 145..149 'Self': S2(isize) -> S2 | ||
611 | 145..152 'Self(1)': S2 | ||
612 | 150..151 '1': isize | ||
613 | 185..231 '{ ... }': () | ||
614 | 195..203 'Self::V1': E | ||
615 | 213..221 'Self::V2': V2(u32) -> E | ||
616 | 213..224 'Self::V2(1)': E | ||
617 | 222..223 '1': u32 | ||
618 | "### | ||
619 | ); | ||
620 | } | ||
621 | |||
622 | #[test] | ||
579 | fn infer_binary_op() { | 623 | fn infer_binary_op() { |
580 | assert_snapshot!( | 624 | assert_snapshot!( |
581 | infer(r#" | 625 | infer(r#" |
@@ -1816,3 +1860,66 @@ fn test() { | |||
1816 | "### | 1860 | "### |
1817 | ); | 1861 | ); |
1818 | } | 1862 | } |
1863 | |||
1864 | #[test] | ||
1865 | fn infer_loop_break_with_val() { | ||
1866 | assert_snapshot!( | ||
1867 | infer(r#" | ||
1868 | enum Option<T> { Some(T), None } | ||
1869 | use Option::*; | ||
1870 | |||
1871 | fn test() { | ||
1872 | let x = loop { | ||
1873 | if false { | ||
1874 | break None; | ||
1875 | } | ||
1876 | |||
1877 | break Some(true); | ||
1878 | }; | ||
1879 | } | ||
1880 | "#), | ||
1881 | @r###" | ||
1882 | 60..169 '{ ... }; }': () | ||
1883 | 70..71 'x': Option<bool> | ||
1884 | 74..166 'loop {... }': Option<bool> | ||
1885 | 79..166 '{ ... }': () | ||
1886 | 89..133 'if fal... }': () | ||
1887 | 92..97 'false': bool | ||
1888 | 98..133 '{ ... }': () | ||
1889 | 112..122 'break None': ! | ||
1890 | 118..122 'None': Option<bool> | ||
1891 | 143..159 'break ...(true)': ! | ||
1892 | 149..153 'Some': Some<bool>(bool) -> Option<bool> | ||
1893 | 149..159 'Some(true)': Option<bool> | ||
1894 | 154..158 'true': bool | ||
1895 | "### | ||
1896 | ); | ||
1897 | } | ||
1898 | |||
1899 | #[test] | ||
1900 | fn infer_loop_break_without_val() { | ||
1901 | assert_snapshot!( | ||
1902 | infer(r#" | ||
1903 | enum Option<T> { Some(T), None } | ||
1904 | use Option::*; | ||
1905 | |||
1906 | fn test() { | ||
1907 | let x = loop { | ||
1908 | if false { | ||
1909 | break; | ||
1910 | } | ||
1911 | }; | ||
1912 | } | ||
1913 | "#), | ||
1914 | @r###" | ||
1915 | 60..137 '{ ... }; }': () | ||
1916 | 70..71 'x': () | ||
1917 | 74..134 'loop {... }': () | ||
1918 | 79..134 '{ ... }': () | ||
1919 | 89..128 'if fal... }': () | ||
1920 | 92..97 'false': bool | ||
1921 | 98..128 '{ ... }': () | ||
1922 | 112..117 'break': ! | ||
1923 | "### | ||
1924 | ); | ||
1925 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 9d32cbc7a..0419bc751 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use insta::assert_snapshot; | 1 | use insta::assert_snapshot; |
2 | |||
3 | use ra_db::fixture::WithFixture; | 2 | use ra_db::fixture::WithFixture; |
3 | use test_utils::mark; | ||
4 | 4 | ||
5 | use super::{infer, infer_with_mismatches, type_at, type_at_pos}; | ||
6 | use crate::test_db::TestDB; | 5 | use crate::test_db::TestDB; |
7 | 6 | ||
7 | use super::{infer, infer_with_mismatches, type_at, type_at_pos}; | ||
8 | |||
8 | #[test] | 9 | #[test] |
9 | fn infer_await() { | 10 | fn infer_await() { |
10 | let (db, pos) = TestDB::with_position( | 11 | let (db, pos) = TestDB::with_position( |
@@ -301,7 +302,7 @@ fn test() { | |||
301 | 302 | ||
302 | #[test] | 303 | #[test] |
303 | fn trait_default_method_self_bound_implements_trait() { | 304 | fn trait_default_method_self_bound_implements_trait() { |
304 | test_utils::covers!(trait_self_implements_self); | 305 | mark::check!(trait_self_implements_self); |
305 | assert_snapshot!( | 306 | assert_snapshot!( |
306 | infer(r#" | 307 | infer(r#" |
307 | trait Trait { | 308 | trait Trait { |
@@ -324,7 +325,6 @@ trait Trait { | |||
324 | 325 | ||
325 | #[test] | 326 | #[test] |
326 | fn trait_default_method_self_bound_implements_super_trait() { | 327 | fn trait_default_method_self_bound_implements_super_trait() { |
327 | test_utils::covers!(trait_self_implements_self); | ||
328 | assert_snapshot!( | 328 | assert_snapshot!( |
329 | infer(r#" | 329 | infer(r#" |
330 | trait SuperTrait { | 330 | trait SuperTrait { |
@@ -1617,6 +1617,138 @@ fn test<F: FnOnce(u32, u64) -> u128>(f: F) { | |||
1617 | } | 1617 | } |
1618 | 1618 | ||
1619 | #[test] | 1619 | #[test] |
1620 | fn fn_ptr_and_item() { | ||
1621 | assert_snapshot!( | ||
1622 | infer(r#" | ||
1623 | #[lang="fn_once"] | ||
1624 | trait FnOnce<Args> { | ||
1625 | type Output; | ||
1626 | |||
1627 | fn call_once(self, args: Args) -> Self::Output; | ||
1628 | } | ||
1629 | |||
1630 | trait Foo<T> { | ||
1631 | fn foo(&self) -> T; | ||
1632 | } | ||
1633 | |||
1634 | struct Bar<T>(T); | ||
1635 | |||
1636 | impl<A1, R, F: FnOnce(A1) -> R> Foo<(A1, R)> for Bar<F> { | ||
1637 | fn foo(&self) -> (A1, R) {} | ||
1638 | } | ||
1639 | |||
1640 | enum Opt<T> { None, Some(T) } | ||
1641 | impl<T> Opt<T> { | ||
1642 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Opt<U> {} | ||
1643 | } | ||
1644 | |||
1645 | fn test() { | ||
1646 | let bar: Bar<fn(u8) -> u32>; | ||
1647 | bar.foo(); | ||
1648 | |||
1649 | let opt: Opt<u8>; | ||
1650 | let f: fn(u8) -> u32; | ||
1651 | opt.map(f); | ||
1652 | } | ||
1653 | "#), | ||
1654 | @r###" | ||
1655 | 75..79 'self': Self | ||
1656 | 81..85 'args': Args | ||
1657 | 140..144 'self': &Self | ||
1658 | 244..248 'self': &Bar<F> | ||
1659 | 261..263 '{}': () | ||
1660 | 347..351 'self': Opt<T> | ||
1661 | 353..354 'f': F | ||
1662 | 369..371 '{}': () | ||
1663 | 385..501 '{ ...(f); }': () | ||
1664 | 395..398 'bar': Bar<fn(u8) -> u32> | ||
1665 | 424..427 'bar': Bar<fn(u8) -> u32> | ||
1666 | 424..433 'bar.foo()': {unknown} | ||
1667 | 444..447 'opt': Opt<u8> | ||
1668 | 466..467 'f': fn(u8) -> u32 | ||
1669 | 488..491 'opt': Opt<u8> | ||
1670 | 488..498 'opt.map(f)': Opt<FnOnce::Output<fn(u8) -> u32, (u8,)>> | ||
1671 | 496..497 'f': fn(u8) -> u32 | ||
1672 | "### | ||
1673 | ); | ||
1674 | } | ||
1675 | |||
1676 | #[test] | ||
1677 | fn fn_trait_deref_with_ty_default() { | ||
1678 | assert_snapshot!( | ||
1679 | infer(r#" | ||
1680 | #[lang = "deref"] | ||
1681 | trait Deref { | ||
1682 | type Target; | ||
1683 | |||
1684 | fn deref(&self) -> &Self::Target; | ||
1685 | } | ||
1686 | |||
1687 | #[lang="fn_once"] | ||
1688 | trait FnOnce<Args> { | ||
1689 | type Output; | ||
1690 | |||
1691 | fn call_once(self, args: Args) -> Self::Output; | ||
1692 | } | ||
1693 | |||
1694 | struct Foo; | ||
1695 | |||
1696 | impl Foo { | ||
1697 | fn foo(&self) -> usize {} | ||
1698 | } | ||
1699 | |||
1700 | struct Lazy<T, F = fn() -> T>(F); | ||
1701 | |||
1702 | impl<T, F> Lazy<T, F> { | ||
1703 | pub fn new(f: F) -> Lazy<T, F> {} | ||
1704 | } | ||
1705 | |||
1706 | impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { | ||
1707 | type Target = T; | ||
1708 | } | ||
1709 | |||
1710 | fn test() { | ||
1711 | let lazy1: Lazy<Foo, _> = Lazy::new(|| Foo); | ||
1712 | let r1 = lazy1.foo(); | ||
1713 | |||
1714 | fn make_foo_fn() -> Foo {} | ||
1715 | let make_foo_fn_ptr: fn() -> Foo = make_foo_fn; | ||
1716 | let lazy2: Lazy<Foo, _> = Lazy::new(make_foo_fn_ptr); | ||
1717 | let r2 = lazy2.foo(); | ||
1718 | } | ||
1719 | "#), | ||
1720 | @r###" | ||
1721 | 65..69 'self': &Self | ||
1722 | 166..170 'self': Self | ||
1723 | 172..176 'args': Args | ||
1724 | 240..244 'self': &Foo | ||
1725 | 255..257 '{}': () | ||
1726 | 335..336 'f': F | ||
1727 | 355..357 '{}': () | ||
1728 | 444..690 '{ ...o(); }': () | ||
1729 | 454..459 'lazy1': Lazy<Foo, fn() -> T> | ||
1730 | 476..485 'Lazy::new': fn new<Foo, fn() -> T>(fn() -> T) -> Lazy<Foo, fn() -> T> | ||
1731 | 476..493 'Lazy::...| Foo)': Lazy<Foo, fn() -> T> | ||
1732 | 486..492 '|| Foo': || -> T | ||
1733 | 489..492 'Foo': Foo | ||
1734 | 503..505 'r1': {unknown} | ||
1735 | 508..513 'lazy1': Lazy<Foo, fn() -> T> | ||
1736 | 508..519 'lazy1.foo()': {unknown} | ||
1737 | 561..576 'make_foo_fn_ptr': fn() -> Foo | ||
1738 | 592..603 'make_foo_fn': fn make_foo_fn() -> Foo | ||
1739 | 613..618 'lazy2': Lazy<Foo, fn() -> T> | ||
1740 | 635..644 'Lazy::new': fn new<Foo, fn() -> T>(fn() -> T) -> Lazy<Foo, fn() -> T> | ||
1741 | 635..661 'Lazy::...n_ptr)': Lazy<Foo, fn() -> T> | ||
1742 | 645..660 'make_foo_fn_ptr': fn() -> Foo | ||
1743 | 671..673 'r2': {unknown} | ||
1744 | 676..681 'lazy2': Lazy<Foo, fn() -> T> | ||
1745 | 676..687 'lazy2.foo()': {unknown} | ||
1746 | 550..552 '{}': () | ||
1747 | "### | ||
1748 | ); | ||
1749 | } | ||
1750 | |||
1751 | #[test] | ||
1620 | fn closure_1() { | 1752 | fn closure_1() { |
1621 | assert_snapshot!( | 1753 | assert_snapshot!( |
1622 | infer(r#" | 1754 | infer(r#" |
@@ -2470,3 +2602,155 @@ fn test(x: &dyn Foo) { | |||
2470 | "### | 2602 | "### |
2471 | ); | 2603 | ); |
2472 | } | 2604 | } |
2605 | |||
2606 | #[test] | ||
2607 | fn builtin_copy() { | ||
2608 | assert_snapshot!( | ||
2609 | infer_with_mismatches(r#" | ||
2610 | #[lang = "copy"] | ||
2611 | trait Copy {} | ||
2612 | |||
2613 | struct IsCopy; | ||
2614 | impl Copy for IsCopy {} | ||
2615 | struct NotCopy; | ||
2616 | |||
2617 | trait Test { fn test(&self) -> bool; } | ||
2618 | impl<T: Copy> Test for T {} | ||
2619 | |||
2620 | fn test() { | ||
2621 | IsCopy.test(); | ||
2622 | NotCopy.test(); | ||
2623 | (IsCopy, IsCopy).test(); | ||
2624 | (IsCopy, NotCopy).test(); | ||
2625 | } | ||
2626 | "#, true), | ||
2627 | @r###" | ||
2628 | 111..115 'self': &Self | ||
2629 | 167..268 '{ ...t(); }': () | ||
2630 | 173..179 'IsCopy': IsCopy | ||
2631 | 173..186 'IsCopy.test()': bool | ||
2632 | 192..199 'NotCopy': NotCopy | ||
2633 | 192..206 'NotCopy.test()': {unknown} | ||
2634 | 212..228 '(IsCop...sCopy)': (IsCopy, IsCopy) | ||
2635 | 212..235 '(IsCop...test()': bool | ||
2636 | 213..219 'IsCopy': IsCopy | ||
2637 | 221..227 'IsCopy': IsCopy | ||
2638 | 241..258 '(IsCop...tCopy)': (IsCopy, NotCopy) | ||
2639 | 241..265 '(IsCop...test()': {unknown} | ||
2640 | 242..248 'IsCopy': IsCopy | ||
2641 | 250..257 'NotCopy': NotCopy | ||
2642 | "### | ||
2643 | ); | ||
2644 | } | ||
2645 | |||
2646 | #[test] | ||
2647 | fn builtin_fn_def_copy() { | ||
2648 | assert_snapshot!( | ||
2649 | infer_with_mismatches(r#" | ||
2650 | #[lang = "copy"] | ||
2651 | trait Copy {} | ||
2652 | |||
2653 | fn foo() {} | ||
2654 | fn bar<T: Copy>(T) -> T {} | ||
2655 | struct Struct(usize); | ||
2656 | enum Enum { Variant(usize) } | ||
2657 | |||
2658 | trait Test { fn test(&self) -> bool; } | ||
2659 | impl<T: Copy> Test for T {} | ||
2660 | |||
2661 | fn test() { | ||
2662 | foo.test(); | ||
2663 | bar.test(); | ||
2664 | Struct.test(); | ||
2665 | Enum::Variant.test(); | ||
2666 | } | ||
2667 | "#, true), | ||
2668 | // wrong result, because the built-in Copy impl for fn defs doesn't exist in Chalk yet | ||
2669 | @r###" | ||
2670 | 42..44 '{}': () | ||
2671 | 61..62 'T': {unknown} | ||
2672 | 69..71 '{}': () | ||
2673 | 69..71: expected T, got () | ||
2674 | 146..150 'self': &Self | ||
2675 | 202..282 '{ ...t(); }': () | ||
2676 | 208..211 'foo': fn foo() | ||
2677 | 208..218 'foo.test()': {unknown} | ||
2678 | 224..227 'bar': fn bar<{unknown}>({unknown}) -> {unknown} | ||
2679 | 224..234 'bar.test()': {unknown} | ||
2680 | 240..246 'Struct': Struct(usize) -> Struct | ||
2681 | 240..253 'Struct.test()': {unknown} | ||
2682 | 259..272 'Enum::Variant': Variant(usize) -> Enum | ||
2683 | 259..279 'Enum::...test()': {unknown} | ||
2684 | "### | ||
2685 | ); | ||
2686 | } | ||
2687 | |||
2688 | #[test] | ||
2689 | fn builtin_fn_ptr_copy() { | ||
2690 | assert_snapshot!( | ||
2691 | infer_with_mismatches(r#" | ||
2692 | #[lang = "copy"] | ||
2693 | trait Copy {} | ||
2694 | |||
2695 | trait Test { fn test(&self) -> bool; } | ||
2696 | impl<T: Copy> Test for T {} | ||
2697 | |||
2698 | fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) { | ||
2699 | f1.test(); | ||
2700 | f2.test(); | ||
2701 | f3.test(); | ||
2702 | } | ||
2703 | "#, true), | ||
2704 | @r###" | ||
2705 | 55..59 'self': &Self | ||
2706 | 109..111 'f1': fn() | ||
2707 | 119..121 'f2': fn(usize) -> u8 | ||
2708 | 140..142 'f3': fn(u8, u8) -> &u8 | ||
2709 | 163..211 '{ ...t(); }': () | ||
2710 | 169..171 'f1': fn() | ||
2711 | 169..178 'f1.test()': bool | ||
2712 | 184..186 'f2': fn(usize) -> u8 | ||
2713 | 184..193 'f2.test()': bool | ||
2714 | 199..201 'f3': fn(u8, u8) -> &u8 | ||
2715 | 199..208 'f3.test()': bool | ||
2716 | "### | ||
2717 | ); | ||
2718 | } | ||
2719 | |||
2720 | #[test] | ||
2721 | fn builtin_sized() { | ||
2722 | assert_snapshot!( | ||
2723 | infer_with_mismatches(r#" | ||
2724 | #[lang = "sized"] | ||
2725 | trait Sized {} | ||
2726 | |||
2727 | trait Test { fn test(&self) -> bool; } | ||
2728 | impl<T: Sized> Test for T {} | ||
2729 | |||
2730 | fn test() { | ||
2731 | 1u8.test(); | ||
2732 | (*"foo").test(); // not Sized | ||
2733 | (1u8, 1u8).test(); | ||
2734 | (1u8, *"foo").test(); // not Sized | ||
2735 | } | ||
2736 | "#, true), | ||
2737 | @r###" | ||
2738 | 57..61 'self': &Self | ||
2739 | 114..229 '{ ...ized }': () | ||
2740 | 120..123 '1u8': u8 | ||
2741 | 120..130 '1u8.test()': bool | ||
2742 | 136..151 '(*"foo").test()': {unknown} | ||
2743 | 137..143 '*"foo"': str | ||
2744 | 138..143 '"foo"': &str | ||
2745 | 170..180 '(1u8, 1u8)': (u8, u8) | ||
2746 | 170..187 '(1u8, ...test()': bool | ||
2747 | 171..174 '1u8': u8 | ||
2748 | 176..179 '1u8': u8 | ||
2749 | 193..206 '(1u8, *"foo")': (u8, str) | ||
2750 | 193..213 '(1u8, ...test()': {unknown} | ||
2751 | 194..197 '1u8': u8 | ||
2752 | 199..205 '*"foo"': str | ||
2753 | 200..205 '"foo"': &str | ||
2754 | "### | ||
2755 | ); | ||
2756 | } | ||