diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 45 | ||||
-rw-r--r-- | crates/test_utils/src/minicore.rs | 43 |
2 files changed, 50 insertions, 38 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index dd1ea817f..0b6a3a1e9 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -567,11 +567,11 @@ fn indexing_arrays() { | |||
567 | fn infer_ops_index() { | 567 | fn infer_ops_index() { |
568 | check_types( | 568 | check_types( |
569 | r#" | 569 | r#" |
570 | //- /main.rs crate:main deps:std | 570 | //- minicore: index |
571 | struct Bar; | 571 | struct Bar; |
572 | struct Foo; | 572 | struct Foo; |
573 | 573 | ||
574 | impl std::ops::Index<u32> for Bar { | 574 | impl core::ops::Index<u32> for Bar { |
575 | type Output = Foo; | 575 | type Output = Foo; |
576 | } | 576 | } |
577 | 577 | ||
@@ -580,15 +580,6 @@ fn test() { | |||
580 | let b = a[1u32]; | 580 | let b = a[1u32]; |
581 | b; | 581 | b; |
582 | } //^ Foo | 582 | } //^ Foo |
583 | |||
584 | //- /std.rs crate:std | ||
585 | #[prelude_import] use ops::*; | ||
586 | mod ops { | ||
587 | #[lang = "index"] | ||
588 | pub trait Index<Idx> { | ||
589 | type Output; | ||
590 | } | ||
591 | } | ||
592 | "#, | 583 | "#, |
593 | ); | 584 | ); |
594 | } | 585 | } |
@@ -597,16 +588,16 @@ mod ops { | |||
597 | fn infer_ops_index_int() { | 588 | fn infer_ops_index_int() { |
598 | check_types( | 589 | check_types( |
599 | r#" | 590 | r#" |
600 | //- /main.rs crate:main deps:std | 591 | //- minicore: index |
601 | struct Bar; | 592 | struct Bar; |
602 | struct Foo; | 593 | struct Foo; |
603 | 594 | ||
604 | impl std::ops::Index<u32> for Bar { | 595 | impl core::ops::Index<u32> for Bar { |
605 | type Output = Foo; | 596 | type Output = Foo; |
606 | } | 597 | } |
607 | 598 | ||
608 | struct Range; | 599 | struct Range; |
609 | impl std::ops::Index<Range> for Bar { | 600 | impl core::ops::Index<Range> for Bar { |
610 | type Output = Bar; | 601 | type Output = Bar; |
611 | } | 602 | } |
612 | 603 | ||
@@ -616,15 +607,6 @@ fn test() { | |||
616 | b; | 607 | b; |
617 | //^ Foo | 608 | //^ Foo |
618 | } | 609 | } |
619 | |||
620 | //- /std.rs crate:std | ||
621 | #[prelude_import] use ops::*; | ||
622 | mod ops { | ||
623 | #[lang = "index"] | ||
624 | pub trait Index<Idx> { | ||
625 | type Output; | ||
626 | } | ||
627 | } | ||
628 | "#, | 610 | "#, |
629 | ); | 611 | ); |
630 | } | 612 | } |
@@ -633,25 +615,12 @@ mod ops { | |||
633 | fn infer_ops_index_autoderef() { | 615 | fn infer_ops_index_autoderef() { |
634 | check_types( | 616 | check_types( |
635 | r#" | 617 | r#" |
636 | //- /main.rs crate:main deps:std | 618 | //- minicore: index, slice |
637 | fn test() { | 619 | fn test() { |
638 | let a = &[1u32, 2, 3]; | 620 | let a = &[1u32, 2, 3]; |
639 | let b = a[1u32]; | 621 | let b = a[1]; |
640 | b; | 622 | b; |
641 | } //^ u32 | 623 | } //^ u32 |
642 | |||
643 | //- /std.rs crate:std | ||
644 | impl<T> ops::Index<u32> for [T] { | ||
645 | type Output = T; | ||
646 | } | ||
647 | |||
648 | #[prelude_import] use ops::*; | ||
649 | mod ops { | ||
650 | #[lang = "index"] | ||
651 | pub trait Index<Idx> { | ||
652 | type Output; | ||
653 | } | ||
654 | } | ||
655 | "#, | 624 | "#, |
656 | ); | 625 | ); |
657 | } | 626 | } |
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 769028580..71f07d38a 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs | |||
@@ -15,6 +15,7 @@ | |||
15 | //! range: | 15 | //! range: |
16 | //! deref: sized | 16 | //! deref: sized |
17 | //! deref_mut: deref | 17 | //! deref_mut: deref |
18 | //! index: sized | ||
18 | //! fn: | 19 | //! fn: |
19 | //! pin: | 20 | //! pin: |
20 | //! future: pin | 21 | //! future: pin |
@@ -167,6 +168,48 @@ pub mod ops { | |||
167 | }; | 168 | }; |
168 | // endregion:deref | 169 | // endregion:deref |
169 | 170 | ||
171 | // region:index | ||
172 | mod index { | ||
173 | #[lang = "index"] | ||
174 | pub trait Index<Idx: ?Sized> { | ||
175 | type Output: ?Sized; | ||
176 | fn index(&self, index: Idx) -> &Self::Output; | ||
177 | } | ||
178 | #[lang = "index_mut"] | ||
179 | pub trait IndexMut<Idx: ?Sized>: Index<Idx> { | ||
180 | fn index_mut(&mut self, index: Idx) -> &mut Self::Output; | ||
181 | } | ||
182 | |||
183 | // region:slice | ||
184 | impl<T, I> Index<I> for [T] | ||
185 | where | ||
186 | I: SliceIndex<[T]>, | ||
187 | { | ||
188 | type Output = I::Output; | ||
189 | fn index(&self, index: I) -> &I::Output { | ||
190 | loop {} | ||
191 | } | ||
192 | } | ||
193 | impl<T, I> IndexMut<I> for [T] | ||
194 | where | ||
195 | I: SliceIndex<[T]>, | ||
196 | { | ||
197 | fn index_mut(&mut self, index: I) -> &mut I::Output { | ||
198 | loop {} | ||
199 | } | ||
200 | } | ||
201 | |||
202 | pub unsafe trait SliceIndex<T: ?Sized> { | ||
203 | type Output: ?Sized; | ||
204 | } | ||
205 | unsafe impl<T> SliceIndex<[T]> for usize { | ||
206 | type Output = T; | ||
207 | } | ||
208 | // endregion:slice | ||
209 | } | ||
210 | pub use self::index::{Index, IndexMut}; | ||
211 | // endregion:index | ||
212 | |||
170 | // region:range | 213 | // region:range |
171 | mod range { | 214 | mod range { |
172 | #[lang = "RangeFull"] | 215 | #[lang = "RangeFull"] |