Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/traits.rs')
-rw-r--r--crates/hir-ty/src/tests/traits.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs
index 003ae60e8e..d270328605 100644
--- a/crates/hir-ty/src/tests/traits.rs
+++ b/crates/hir-ty/src/tests/traits.rs
@@ -4506,3 +4506,50 @@ fn ttt() {
"#,
);
}
+
+#[test]
+fn infer_borrow() {
+ check_types(
+ r#"
+//- minicore: index
+pub struct SomeMap<K>;
+
+pub trait Borrow<Borrowed: ?Sized> {
+ fn borrow(&self) -> &Borrowed;
+}
+
+impl<T: ?Sized> Borrow<T> for T {
+ fn borrow(&self) -> &T {
+ self
+ }
+}
+
+impl<T: ?Sized> Borrow<T> for &T {
+ fn borrow(&self) -> &T {
+ &**self
+ }
+}
+
+impl<K, KB: Borrow<K>> core::ops::Index<KB> for SomeMap<K> {
+ type Output = ();
+
+ fn index(&self, _: KB) -> &() {
+ &()
+ }
+}
+
+impl<K> core::ops::IndexMut<K> for SomeMap<K> {
+ fn index_mut(&mut self, _: K) -> &mut () {
+ &mut ()
+ }
+}
+
+fn foo() {
+ let mut map = SomeMap;
+ map["a"] = ();
+ map;
+ //^^^ SomeMap<&str>
+}
+"#,
+ );
+}