diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/patterns.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 100 |
3 files changed, 102 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index 6e5d2247c..07cbc521a 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use super::{infer, infer_with_mismatches}; | ||
2 | use insta::assert_snapshot; | 1 | use insta::assert_snapshot; |
3 | use test_utils::covers; | 2 | use test_utils::covers; |
4 | 3 | ||
4 | use super::{infer, infer_with_mismatches}; | ||
5 | |||
5 | #[test] | 6 | #[test] |
6 | fn infer_pattern() { | 7 | fn infer_pattern() { |
7 | assert_snapshot!( | 8 | assert_snapshot!( |
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 3402e0cb5..d69115a2f 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -451,8 +451,7 @@ pub mod str { | |||
451 | "#, | 451 | "#, |
452 | ); | 452 | ); |
453 | 453 | ||
454 | // should be Option<char>, but currently not because of Chalk ambiguity problem | 454 | assert_eq!("(Option<char>, Option<char>)", super::type_at_pos(&db, pos)); |
455 | assert_eq!("(Option<{unknown}>, Option<{unknown}>)", super::type_at_pos(&db, pos)); | ||
456 | } | 455 | } |
457 | 456 | ||
458 | #[test] | 457 | #[test] |
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 22ae6ca90..b3a2fc439 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1803,7 +1803,7 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | |||
1803 | } | 1803 | } |
1804 | 1804 | ||
1805 | #[test] | 1805 | #[test] |
1806 | fn unselected_projection_on_trait_self() { | 1806 | fn unselected_projection_on_impl_self() { |
1807 | assert_snapshot!(infer( | 1807 | assert_snapshot!(infer( |
1808 | r#" | 1808 | r#" |
1809 | //- /main.rs | 1809 | //- /main.rs |
@@ -1844,6 +1844,30 @@ impl Trait for S2 { | |||
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | #[test] | 1846 | #[test] |
1847 | fn unselected_projection_on_trait_self() { | ||
1848 | let t = type_at( | ||
1849 | r#" | ||
1850 | //- /main.rs | ||
1851 | trait Trait { | ||
1852 | type Item; | ||
1853 | |||
1854 | fn f(&self) -> Self::Item { loop {} } | ||
1855 | } | ||
1856 | |||
1857 | struct S; | ||
1858 | impl Trait for S { | ||
1859 | type Item = u32; | ||
1860 | } | ||
1861 | |||
1862 | fn test() { | ||
1863 | S.f()<|>; | ||
1864 | } | ||
1865 | "#, | ||
1866 | ); | ||
1867 | assert_eq!(t, "u32"); | ||
1868 | } | ||
1869 | |||
1870 | #[test] | ||
1847 | fn trait_impl_self_ty() { | 1871 | fn trait_impl_self_ty() { |
1848 | let t = type_at( | 1872 | let t = type_at( |
1849 | r#" | 1873 | r#" |
@@ -1924,6 +1948,53 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { | |||
1924 | } | 1948 | } |
1925 | 1949 | ||
1926 | #[test] | 1950 | #[test] |
1951 | fn inline_assoc_type_bounds_1() { | ||
1952 | let t = type_at( | ||
1953 | r#" | ||
1954 | //- /main.rs | ||
1955 | trait Iterator { | ||
1956 | type Item; | ||
1957 | } | ||
1958 | trait OtherTrait<T> { | ||
1959 | fn foo(&self) -> T; | ||
1960 | } | ||
1961 | |||
1962 | // workaround for Chalk assoc type normalization problems | ||
1963 | pub struct S<T>; | ||
1964 | impl<T: Iterator> Iterator for S<T> { | ||
1965 | type Item = <T as Iterator>::Item; | ||
1966 | } | ||
1967 | |||
1968 | fn test<I: Iterator<Item: OtherTrait<u32>>>() { | ||
1969 | let x: <S<I> as Iterator>::Item; | ||
1970 | x.foo()<|>; | ||
1971 | } | ||
1972 | "#, | ||
1973 | ); | ||
1974 | assert_eq!(t, "u32"); | ||
1975 | } | ||
1976 | |||
1977 | #[test] | ||
1978 | fn inline_assoc_type_bounds_2() { | ||
1979 | let t = type_at( | ||
1980 | r#" | ||
1981 | //- /main.rs | ||
1982 | trait Iterator { | ||
1983 | type Item; | ||
1984 | } | ||
1985 | |||
1986 | fn test<I: Iterator<Item: Iterator<Item = u32>>>() { | ||
1987 | let x: <<I as Iterator>::Item as Iterator>::Item; | ||
1988 | x<|>; | ||
1989 | } | ||
1990 | "#, | ||
1991 | ); | ||
1992 | // assert_eq!(t, "u32"); | ||
1993 | // doesn't currently work, Chalk #234 | ||
1994 | assert_eq!(t, "{unknown}"); | ||
1995 | } | ||
1996 | |||
1997 | #[test] | ||
1927 | fn unify_impl_trait() { | 1998 | fn unify_impl_trait() { |
1928 | assert_snapshot!( | 1999 | assert_snapshot!( |
1929 | infer_with_mismatches(r#" | 2000 | infer_with_mismatches(r#" |
@@ -2023,6 +2094,33 @@ fn main() { | |||
2023 | } | 2094 | } |
2024 | 2095 | ||
2025 | #[test] | 2096 | #[test] |
2097 | fn associated_type_bound() { | ||
2098 | let t = type_at( | ||
2099 | r#" | ||
2100 | //- /main.rs | ||
2101 | pub trait Trait { | ||
2102 | type Item: OtherTrait<u32>; | ||
2103 | } | ||
2104 | pub trait OtherTrait<T> { | ||
2105 | fn foo(&self) -> T; | ||
2106 | } | ||
2107 | |||
2108 | // this is just a workaround for chalk#234 | ||
2109 | pub struct S<T>; | ||
2110 | impl<T: Trait> Trait for S<T> { | ||
2111 | type Item = <T as Trait>::Item; | ||
2112 | } | ||
2113 | |||
2114 | fn test<T: Trait>() { | ||
2115 | let y: <S<T> as Trait>::Item = no_matter; | ||
2116 | y.foo()<|>; | ||
2117 | } | ||
2118 | "#, | ||
2119 | ); | ||
2120 | assert_eq!(t, "u32"); | ||
2121 | } | ||
2122 | |||
2123 | #[test] | ||
2026 | fn dyn_trait_through_chalk() { | 2124 | fn dyn_trait_through_chalk() { |
2027 | let t = type_at( | 2125 | let t = type_at( |
2028 | r#" | 2126 | r#" |