diff options
author | Florian Diebold <[email protected]> | 2020-03-06 17:08:10 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-03-06 17:14:39 +0000 |
commit | d17c5416af3d90b4c827224d4cd73366fa5a294b (patch) | |
tree | e67ea28da54f3ff428fdfeab1689f2a334f362a8 /crates/ra_hir_ty/src/tests | |
parent | ce7496ec2227746cfcd2147fadf58fa71f65e35b (diff) |
Resolve `Self::AssocTy` in impls
To do this we need to carry around the original resolution a bit, because `Self`
gets resolved to the actual type immediately, but you're not allowed to write
the equivalent type in a projection. (I tried just comparing the projection base
type with the impl self type, but that seemed too dirty.) This is basically how
rustc does it as well.
Fixes #3249.
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 547010b35..f009a708c 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1803,6 +1803,47 @@ 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() { | ||
1807 | assert_snapshot!(infer( | ||
1808 | r#" | ||
1809 | //- /main.rs | ||
1810 | trait Trait { | ||
1811 | type Item; | ||
1812 | |||
1813 | fn f(&self, x: Self::Item); | ||
1814 | } | ||
1815 | |||
1816 | struct S; | ||
1817 | |||
1818 | impl Trait for S { | ||
1819 | type Item = u32; | ||
1820 | fn f(&self, x: Self::Item) { let y = x; } | ||
1821 | } | ||
1822 | |||
1823 | struct S2; | ||
1824 | |||
1825 | impl Trait for S2 { | ||
1826 | type Item = i32; | ||
1827 | fn f(&self, x: <Self>::Item) { let y = x; } | ||
1828 | } | ||
1829 | "#, | ||
1830 | ), @r###" | ||
1831 | [54; 58) 'self': &Self | ||
1832 | [60; 61) 'x': {unknown} | ||
1833 | [140; 144) 'self': &S | ||
1834 | [146; 147) 'x': u32 | ||
1835 | [161; 175) '{ let y = x; }': () | ||
1836 | [167; 168) 'y': u32 | ||
1837 | [171; 172) 'x': u32 | ||
1838 | [242; 246) 'self': &S2 | ||
1839 | [248; 249) 'x': i32 | ||
1840 | [265; 279) '{ let y = x; }': () | ||
1841 | [271; 272) 'y': i32 | ||
1842 | [275; 276) 'x': i32 | ||
1843 | "###); | ||
1844 | } | ||
1845 | |||
1846 | #[test] | ||
1806 | fn trait_impl_self_ty() { | 1847 | fn trait_impl_self_ty() { |
1807 | let t = type_at( | 1848 | let t = type_at( |
1808 | r#" | 1849 | r#" |