Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/regression.rs')
| -rw-r--r-- | crates/hir-ty/src/tests/regression.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index b371e5856b..ac2dfea101 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -2075,3 +2075,50 @@ impl<'a, T> Trait<'a> for &'a T { "#, ) } + +#[test] +fn issue_17738() { + check_types( + r#" +//- minicore: index +use core::ops::{Index, IndexMut}; + +struct Foo<K, V>(K, V); + +struct Bar; + +impl Bar { + fn bar(&mut self) {} +} + +impl<K, V> Foo<K, V> { + fn new(_v: V) -> Self { + loop {} + } +} + +impl<K, B, V> Index<B> for Foo<K, V> { + type Output = V; + fn index(&self, _index: B) -> &Self::Output { + loop {} + } +} + +impl<K, V> IndexMut<K> for Foo<K, V> { + fn index_mut(&mut self, _index: K) -> &mut Self::Output { + loop {} + } +} + +fn test() { + let mut t1 = Foo::new(Bar); + // ^^^^^^ Foo<&'? (), Bar> + t1[&()] = Bar; + + let mut t2 = Foo::new(Bar); + // ^^^^^^ Foo<&'? (), Bar> + t2[&()].bar(); +} +"#, + ) +} |