diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/base_db/src/fixture.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 42 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 183 | ||||
-rw-r--r-- | crates/ide/src/hover.rs | 4 | ||||
-rw-r--r-- | crates/ide_completion/src/render.rs | 20 | ||||
-rw-r--r-- | crates/test_utils/src/minicore.rs | 43 |
6 files changed, 131 insertions, 165 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index d56b20b83..d0c946d83 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -114,6 +114,9 @@ impl ChangeFixture { | |||
114 | 114 | ||
115 | let meta = FileMeta::from(entry); | 115 | let meta = FileMeta::from(entry); |
116 | assert!(meta.path.starts_with(&source_root_prefix)); | 116 | assert!(meta.path.starts_with(&source_root_prefix)); |
117 | if !meta.deps.is_empty() { | ||
118 | assert!(meta.krate.is_some(), "can't specify deps without naming the crate") | ||
119 | } | ||
117 | 120 | ||
118 | if meta.introduce_new_source_root { | 121 | if meta.introduce_new_source_root { |
119 | roots.push(SourceRoot::new_local(mem::take(&mut file_set))); | 122 | roots.push(SourceRoot::new_local(mem::take(&mut file_set))); |
@@ -199,6 +202,7 @@ impl ChangeFixture { | |||
199 | } | 202 | } |
200 | } | 203 | } |
201 | 204 | ||
205 | #[derive(Debug)] | ||
202 | struct FileMeta { | 206 | struct FileMeta { |
203 | path: String, | 207 | path: String, |
204 | krate: Option<String>, | 208 | krate: Option<String>, |
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 94b628fb8..0f418ea49 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -792,6 +792,7 @@ fn issue_4800() { | |||
792 | fn issue_4966() { | 792 | fn issue_4966() { |
793 | check_infer( | 793 | check_infer( |
794 | r#" | 794 | r#" |
795 | //- minicore: deref | ||
795 | pub trait IntoIterator { | 796 | pub trait IntoIterator { |
796 | type Item; | 797 | type Item; |
797 | } | 798 | } |
@@ -802,12 +803,7 @@ fn issue_4966() { | |||
802 | 803 | ||
803 | struct Vec<T> {} | 804 | struct Vec<T> {} |
804 | 805 | ||
805 | #[lang = "deref"] | 806 | impl<T> core::ops::Deref for Vec<T> { |
806 | pub trait Deref { | ||
807 | type Target; | ||
808 | } | ||
809 | |||
810 | impl<T> Deref for Vec<T> { | ||
811 | type Target = [T]; | 807 | type Target = [T]; |
812 | } | 808 | } |
813 | 809 | ||
@@ -824,23 +820,23 @@ fn issue_4966() { | |||
824 | } | 820 | } |
825 | "#, | 821 | "#, |
826 | expect![[r#" | 822 | expect![[r#" |
827 | 270..274 'iter': T | 823 | 225..229 'iter': T |
828 | 289..291 '{}': () | 824 | 244..246 '{}': () |
829 | 303..447 '{ ...r(); }': () | 825 | 258..402 '{ ...r(); }': () |
830 | 313..318 'inner': Map<|&f64| -> f64> | 826 | 268..273 'inner': Map<|&f64| -> f64> |
831 | 321..345 'Map { ... 0.0 }': Map<|&f64| -> f64> | 827 | 276..300 'Map { ... 0.0 }': Map<|&f64| -> f64> |
832 | 330..343 '|_: &f64| 0.0': |&f64| -> f64 | 828 | 285..298 '|_: &f64| 0.0': |&f64| -> f64 |
833 | 331..332 '_': &f64 | 829 | 286..287 '_': &f64 |
834 | 340..343 '0.0': f64 | 830 | 295..298 '0.0': f64 |
835 | 356..362 'repeat': Repeat<Map<|&f64| -> f64>> | 831 | 311..317 'repeat': Repeat<Map<|&f64| -> f64>> |
836 | 365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>> | 832 | 320..345 'Repeat...nner }': Repeat<Map<|&f64| -> f64>> |
837 | 383..388 'inner': Map<|&f64| -> f64> | 833 | 338..343 'inner': Map<|&f64| -> f64> |
838 | 401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 834 | 356..359 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
839 | 407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 835 | 362..371 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
840 | 407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 836 | 362..379 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
841 | 417..423 'repeat': Repeat<Map<|&f64| -> f64>> | 837 | 372..378 'repeat': Repeat<Map<|&f64| -> f64>> |
842 | 431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> | 838 | 386..389 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>> |
843 | 431..444 'vec.foo_bar()': {unknown} | 839 | 386..399 'vec.foo_bar()': {unknown} |
844 | "#]], | 840 | "#]], |
845 | ); | 841 | ); |
846 | } | 842 | } |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index dd1ea817f..279a1354a 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 | } |
@@ -884,12 +853,9 @@ fn test<T>(t: T) { t.foo(); } | |||
884 | fn generic_param_env_deref() { | 853 | fn generic_param_env_deref() { |
885 | check_types( | 854 | check_types( |
886 | r#" | 855 | r#" |
887 | #[lang = "deref"] | 856 | //- minicore: deref |
888 | trait Deref { | ||
889 | type Target; | ||
890 | } | ||
891 | trait Trait {} | 857 | trait Trait {} |
892 | impl<T> Deref for T where T: Trait { | 858 | impl<T> core::ops::Deref for T where T: Trait { |
893 | type Target = i128; | 859 | type Target = i128; |
894 | } | 860 | } |
895 | fn test<T: Trait>(t: T) { (*t); } | 861 | fn test<T: Trait>(t: T) { (*t); } |
@@ -1758,20 +1724,7 @@ fn test() { | |||
1758 | fn fn_trait_deref_with_ty_default() { | 1724 | fn fn_trait_deref_with_ty_default() { |
1759 | check_infer( | 1725 | check_infer( |
1760 | r#" | 1726 | r#" |
1761 | #[lang = "deref"] | 1727 | //- minicore: deref, fn |
1762 | trait Deref { | ||
1763 | type Target; | ||
1764 | |||
1765 | fn deref(&self) -> &Self::Target; | ||
1766 | } | ||
1767 | |||
1768 | #[lang="fn_once"] | ||
1769 | trait FnOnce<Args> { | ||
1770 | type Output; | ||
1771 | |||
1772 | fn call_once(self, args: Args) -> Self::Output; | ||
1773 | } | ||
1774 | |||
1775 | struct Foo; | 1728 | struct Foo; |
1776 | 1729 | ||
1777 | impl Foo { | 1730 | impl Foo { |
@@ -1784,7 +1737,7 @@ impl<T, F> Lazy<T, F> { | |||
1784 | pub fn new(f: F) -> Lazy<T, F> {} | 1737 | pub fn new(f: F) -> Lazy<T, F> {} |
1785 | } | 1738 | } |
1786 | 1739 | ||
1787 | impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { | 1740 | impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> { |
1788 | type Target = T; | 1741 | type Target = T; |
1789 | } | 1742 | } |
1790 | 1743 | ||
@@ -1798,32 +1751,29 @@ fn test() { | |||
1798 | let r2 = lazy2.foo(); | 1751 | let r2 = lazy2.foo(); |
1799 | }"#, | 1752 | }"#, |
1800 | expect![[r#" | 1753 | expect![[r#" |
1801 | 64..68 'self': &Self | 1754 | 36..40 'self': &Foo |
1802 | 165..169 'self': Self | 1755 | 51..53 '{}': () |
1803 | 171..175 'args': Args | 1756 | 131..132 'f': F |
1804 | 239..243 'self': &Foo | 1757 | 151..153 '{}': () |
1805 | 254..256 '{}': () | 1758 | 251..497 '{ ...o(); }': () |
1806 | 334..335 'f': F | 1759 | 261..266 'lazy1': Lazy<Foo, || -> Foo> |
1807 | 354..356 '{}': () | 1760 | 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> |
1808 | 443..689 '{ ...o(); }': () | 1761 | 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> |
1809 | 453..458 'lazy1': Lazy<Foo, || -> Foo> | 1762 | 293..299 '|| Foo': || -> Foo |
1810 | 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> | 1763 | 296..299 'Foo': Foo |
1811 | 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> | 1764 | 310..312 'r1': usize |
1812 | 485..491 '|| Foo': || -> Foo | 1765 | 315..320 'lazy1': Lazy<Foo, || -> Foo> |
1813 | 488..491 'Foo': Foo | 1766 | 315..326 'lazy1.foo()': usize |
1814 | 502..504 'r1': usize | 1767 | 368..383 'make_foo_fn_ptr': fn() -> Foo |
1815 | 507..512 'lazy1': Lazy<Foo, || -> Foo> | 1768 | 399..410 'make_foo_fn': fn make_foo_fn() -> Foo |
1816 | 507..518 'lazy1.foo()': usize | 1769 | 420..425 'lazy2': Lazy<Foo, fn() -> Foo> |
1817 | 560..575 'make_foo_fn_ptr': fn() -> Foo | 1770 | 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> |
1818 | 591..602 'make_foo_fn': fn make_foo_fn() -> Foo | 1771 | 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> |
1819 | 612..617 'lazy2': Lazy<Foo, fn() -> Foo> | 1772 | 452..467 'make_foo_fn_ptr': fn() -> Foo |
1820 | 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> | 1773 | 478..480 'r2': usize |
1821 | 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> | 1774 | 483..488 'lazy2': Lazy<Foo, fn() -> Foo> |
1822 | 644..659 'make_foo_fn_ptr': fn() -> Foo | 1775 | 483..494 'lazy2.foo()': usize |
1823 | 670..672 'r2': usize | 1776 | 357..359 '{}': () |
1824 | 675..680 'lazy2': Lazy<Foo, fn() -> Foo> | ||
1825 | 675..686 'lazy2.foo()': usize | ||
1826 | 549..551 '{}': () | ||
1827 | "#]], | 1777 | "#]], |
1828 | ); | 1778 | ); |
1829 | } | 1779 | } |
@@ -2972,28 +2922,13 @@ fn infer_box_fn_arg() { | |||
2972 | // The type mismatch is because we don't define Unsize and CoerceUnsized | 2922 | // The type mismatch is because we don't define Unsize and CoerceUnsized |
2973 | check_infer_with_mismatches( | 2923 | check_infer_with_mismatches( |
2974 | r#" | 2924 | r#" |
2975 | //- /lib.rs deps:std | 2925 | //- minicore: fn, deref, option |
2976 | |||
2977 | #[lang = "fn_once"] | ||
2978 | pub trait FnOnce<Args> { | ||
2979 | type Output; | ||
2980 | |||
2981 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
2982 | } | ||
2983 | |||
2984 | #[lang = "deref"] | ||
2985 | pub trait Deref { | ||
2986 | type Target: ?Sized; | ||
2987 | |||
2988 | fn deref(&self) -> &Self::Target; | ||
2989 | } | ||
2990 | |||
2991 | #[lang = "owned_box"] | 2926 | #[lang = "owned_box"] |
2992 | pub struct Box<T: ?Sized> { | 2927 | pub struct Box<T: ?Sized> { |
2993 | inner: *mut T, | 2928 | inner: *mut T, |
2994 | } | 2929 | } |
2995 | 2930 | ||
2996 | impl<T: ?Sized> Deref for Box<T> { | 2931 | impl<T: ?Sized> core::ops::Deref for Box<T> { |
2997 | type Target = T; | 2932 | type Target = T; |
2998 | 2933 | ||
2999 | fn deref(&self) -> &T { | 2934 | fn deref(&self) -> &T { |
@@ -3001,38 +2936,30 @@ impl<T: ?Sized> Deref for Box<T> { | |||
3001 | } | 2936 | } |
3002 | } | 2937 | } |
3003 | 2938 | ||
3004 | enum Option<T> { | ||
3005 | None, | ||
3006 | Some(T) | ||
3007 | } | ||
3008 | |||
3009 | fn foo() { | 2939 | fn foo() { |
3010 | let s = Option::None; | 2940 | let s = None; |
3011 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); | 2941 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); |
3012 | f(&s); | 2942 | f(&s); |
3013 | }"#, | 2943 | }"#, |
3014 | expect![[r#" | 2944 | expect![[r#" |
3015 | 100..104 'self': Self | 2945 | 154..158 'self': &Box<T> |
3016 | 106..110 'args': Args | 2946 | 166..193 '{ ... }': &T |
3017 | 214..218 'self': &Self | 2947 | 176..187 '&self.inner': &*mut T |
3018 | 384..388 'self': &Box<T> | 2948 | 177..181 'self': &Box<T> |
3019 | 396..423 '{ ... }': &T | 2949 | 177..187 'self.inner': *mut T |
3020 | 406..417 '&self.inner': &*mut T | 2950 | 206..296 '{ ...&s); }': () |
3021 | 407..411 'self': &Box<T> | 2951 | 216..217 's': Option<i32> |
3022 | 407..417 'self.inner': *mut T | 2952 | 220..224 'None': Option<i32> |
3023 | 478..576 '{ ...&s); }': () | 2953 | 234..235 'f': Box<dyn FnOnce(&Option<i32>)> |
3024 | 488..489 's': Option<i32> | 2954 | 269..282 'box (|ps| {})': Box<|{unknown}| -> ()> |
3025 | 492..504 'Option::None': Option<i32> | 2955 | 274..281 '|ps| {}': |{unknown}| -> () |
3026 | 514..515 'f': Box<dyn FnOnce(&Option<i32>)> | 2956 | 275..277 'ps': {unknown} |
3027 | 549..562 'box (|ps| {})': Box<|{unknown}| -> ()> | 2957 | 279..281 '{}': () |
3028 | 554..561 '|ps| {}': |{unknown}| -> () | 2958 | 288..289 'f': Box<dyn FnOnce(&Option<i32>)> |
3029 | 555..557 'ps': {unknown} | 2959 | 288..293 'f(&s)': () |
3030 | 559..561 '{}': () | 2960 | 290..292 '&s': &Option<i32> |
3031 | 568..569 'f': Box<dyn FnOnce(&Option<i32>)> | 2961 | 291..292 's': Option<i32> |
3032 | 568..573 'f(&s)': () | 2962 | 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> |
3033 | 570..572 '&s': &Option<i32> | ||
3034 | 571..572 's': Option<i32> | ||
3035 | 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> | ||
3036 | "#]], | 2963 | "#]], |
3037 | ); | 2964 | ); |
3038 | } | 2965 | } |
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 4705fae08..05a2b1293 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs | |||
@@ -3014,8 +3014,8 @@ fn foo() { | |||
3014 | file_id: FileId( | 3014 | file_id: FileId( |
3015 | 1, | 3015 | 1, |
3016 | ), | 3016 | ), |
3017 | full_range: 250..432, | 3017 | full_range: 251..433, |
3018 | focus_range: 289..295, | 3018 | focus_range: 290..296, |
3019 | name: "Future", | 3019 | name: "Future", |
3020 | kind: Trait, | 3020 | kind: Trait, |
3021 | description: "pub trait Future", | 3021 | description: "pub trait Future", |
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 4b55f7504..9bec03e17 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -1269,16 +1269,11 @@ fn bar(t: &Foo) {} | |||
1269 | fn suggest_deref_fn_ret() { | 1269 | fn suggest_deref_fn_ret() { |
1270 | check_relevance( | 1270 | check_relevance( |
1271 | r#" | 1271 | r#" |
1272 | #[lang = "deref"] | 1272 | //- minicore: deref |
1273 | trait Deref { | ||
1274 | type Target; | ||
1275 | fn deref(&self) -> &Self::Target; | ||
1276 | } | ||
1277 | |||
1278 | struct S; | 1273 | struct S; |
1279 | struct T(S); | 1274 | struct T(S); |
1280 | 1275 | ||
1281 | impl Deref for T { | 1276 | impl core::ops::Deref for T { |
1282 | type Target = S; | 1277 | type Target = S; |
1283 | 1278 | ||
1284 | fn deref(&self) -> &Self::Target { | 1279 | fn deref(&self) -> &Self::Target { |
@@ -1292,15 +1287,16 @@ fn bar() -> T {} | |||
1292 | fn main() { | 1287 | fn main() { |
1293 | foo($0); | 1288 | foo($0); |
1294 | } | 1289 | } |
1295 | "#, | 1290 | "#, |
1296 | expect![[r#" | 1291 | expect![[r#" |
1297 | tt Deref [] | ||
1298 | fn bar() [] | ||
1299 | fn &bar() [type] | ||
1300 | fn foo(…) [] | ||
1301 | st T [] | 1292 | st T [] |
1302 | st S [] | 1293 | st S [] |
1303 | fn main() [] | 1294 | fn main() [] |
1295 | fn bar() [] | ||
1296 | fn &bar() [type] | ||
1297 | fn foo(…) [] | ||
1298 | md core [] | ||
1299 | tt Sized [] | ||
1304 | "#]], | 1300 | "#]], |
1305 | ) | 1301 | ) |
1306 | } | 1302 | } |
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"] |