diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 42 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 138 |
2 files changed, 67 insertions, 113 deletions
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 0b6a3a1e9..279a1354a 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -853,12 +853,9 @@ fn test<T>(t: T) { t.foo(); } | |||
853 | fn generic_param_env_deref() { | 853 | fn generic_param_env_deref() { |
854 | check_types( | 854 | check_types( |
855 | r#" | 855 | r#" |
856 | #[lang = "deref"] | 856 | //- minicore: deref |
857 | trait Deref { | ||
858 | type Target; | ||
859 | } | ||
860 | trait Trait {} | 857 | trait Trait {} |
861 | impl<T> Deref for T where T: Trait { | 858 | impl<T> core::ops::Deref for T where T: Trait { |
862 | type Target = i128; | 859 | type Target = i128; |
863 | } | 860 | } |
864 | fn test<T: Trait>(t: T) { (*t); } | 861 | fn test<T: Trait>(t: T) { (*t); } |
@@ -1727,20 +1724,7 @@ fn test() { | |||
1727 | fn fn_trait_deref_with_ty_default() { | 1724 | fn fn_trait_deref_with_ty_default() { |
1728 | check_infer( | 1725 | check_infer( |
1729 | r#" | 1726 | r#" |
1730 | #[lang = "deref"] | 1727 | //- minicore: deref, fn |
1731 | trait Deref { | ||
1732 | type Target; | ||
1733 | |||
1734 | fn deref(&self) -> &Self::Target; | ||
1735 | } | ||
1736 | |||
1737 | #[lang="fn_once"] | ||
1738 | trait FnOnce<Args> { | ||
1739 | type Output; | ||
1740 | |||
1741 | fn call_once(self, args: Args) -> Self::Output; | ||
1742 | } | ||
1743 | |||
1744 | struct Foo; | 1728 | struct Foo; |
1745 | 1729 | ||
1746 | impl Foo { | 1730 | impl Foo { |
@@ -1753,7 +1737,7 @@ impl<T, F> Lazy<T, F> { | |||
1753 | pub fn new(f: F) -> Lazy<T, F> {} | 1737 | pub fn new(f: F) -> Lazy<T, F> {} |
1754 | } | 1738 | } |
1755 | 1739 | ||
1756 | impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { | 1740 | impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> { |
1757 | type Target = T; | 1741 | type Target = T; |
1758 | } | 1742 | } |
1759 | 1743 | ||
@@ -1767,32 +1751,29 @@ fn test() { | |||
1767 | let r2 = lazy2.foo(); | 1751 | let r2 = lazy2.foo(); |
1768 | }"#, | 1752 | }"#, |
1769 | expect![[r#" | 1753 | expect![[r#" |
1770 | 64..68 'self': &Self | 1754 | 36..40 'self': &Foo |
1771 | 165..169 'self': Self | 1755 | 51..53 '{}': () |
1772 | 171..175 'args': Args | 1756 | 131..132 'f': F |
1773 | 239..243 'self': &Foo | 1757 | 151..153 '{}': () |
1774 | 254..256 '{}': () | 1758 | 251..497 '{ ...o(); }': () |
1775 | 334..335 'f': F | 1759 | 261..266 'lazy1': Lazy<Foo, || -> Foo> |
1776 | 354..356 '{}': () | 1760 | 283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> |
1777 | 443..689 '{ ...o(); }': () | 1761 | 283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> |
1778 | 453..458 'lazy1': Lazy<Foo, || -> Foo> | 1762 | 293..299 '|| Foo': || -> Foo |
1779 | 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> | 1763 | 296..299 'Foo': Foo |
1780 | 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> | 1764 | 310..312 'r1': usize |
1781 | 485..491 '|| Foo': || -> Foo | 1765 | 315..320 'lazy1': Lazy<Foo, || -> Foo> |
1782 | 488..491 'Foo': Foo | 1766 | 315..326 'lazy1.foo()': usize |
1783 | 502..504 'r1': usize | 1767 | 368..383 'make_foo_fn_ptr': fn() -> Foo |
1784 | 507..512 'lazy1': Lazy<Foo, || -> Foo> | 1768 | 399..410 'make_foo_fn': fn make_foo_fn() -> Foo |
1785 | 507..518 'lazy1.foo()': usize | 1769 | 420..425 'lazy2': Lazy<Foo, fn() -> Foo> |
1786 | 560..575 'make_foo_fn_ptr': fn() -> Foo | 1770 | 442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> |
1787 | 591..602 'make_foo_fn': fn make_foo_fn() -> Foo | 1771 | 442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> |
1788 | 612..617 'lazy2': Lazy<Foo, fn() -> Foo> | 1772 | 452..467 'make_foo_fn_ptr': fn() -> Foo |
1789 | 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> | 1773 | 478..480 'r2': usize |
1790 | 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> | 1774 | 483..488 'lazy2': Lazy<Foo, fn() -> Foo> |
1791 | 644..659 'make_foo_fn_ptr': fn() -> Foo | 1775 | 483..494 'lazy2.foo()': usize |
1792 | 670..672 'r2': usize | 1776 | 357..359 '{}': () |
1793 | 675..680 'lazy2': Lazy<Foo, fn() -> Foo> | ||
1794 | 675..686 'lazy2.foo()': usize | ||
1795 | 549..551 '{}': () | ||
1796 | "#]], | 1777 | "#]], |
1797 | ); | 1778 | ); |
1798 | } | 1779 | } |
@@ -2941,28 +2922,13 @@ fn infer_box_fn_arg() { | |||
2941 | // 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 |
2942 | check_infer_with_mismatches( | 2923 | check_infer_with_mismatches( |
2943 | r#" | 2924 | r#" |
2944 | //- /lib.rs deps:std | 2925 | //- minicore: fn, deref, option |
2945 | |||
2946 | #[lang = "fn_once"] | ||
2947 | pub trait FnOnce<Args> { | ||
2948 | type Output; | ||
2949 | |||
2950 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
2951 | } | ||
2952 | |||
2953 | #[lang = "deref"] | ||
2954 | pub trait Deref { | ||
2955 | type Target: ?Sized; | ||
2956 | |||
2957 | fn deref(&self) -> &Self::Target; | ||
2958 | } | ||
2959 | |||
2960 | #[lang = "owned_box"] | 2926 | #[lang = "owned_box"] |
2961 | pub struct Box<T: ?Sized> { | 2927 | pub struct Box<T: ?Sized> { |
2962 | inner: *mut T, | 2928 | inner: *mut T, |
2963 | } | 2929 | } |
2964 | 2930 | ||
2965 | impl<T: ?Sized> Deref for Box<T> { | 2931 | impl<T: ?Sized> core::ops::Deref for Box<T> { |
2966 | type Target = T; | 2932 | type Target = T; |
2967 | 2933 | ||
2968 | fn deref(&self) -> &T { | 2934 | fn deref(&self) -> &T { |
@@ -2970,38 +2936,30 @@ impl<T: ?Sized> Deref for Box<T> { | |||
2970 | } | 2936 | } |
2971 | } | 2937 | } |
2972 | 2938 | ||
2973 | enum Option<T> { | ||
2974 | None, | ||
2975 | Some(T) | ||
2976 | } | ||
2977 | |||
2978 | fn foo() { | 2939 | fn foo() { |
2979 | let s = Option::None; | 2940 | let s = None; |
2980 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); | 2941 | let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {}); |
2981 | f(&s); | 2942 | f(&s); |
2982 | }"#, | 2943 | }"#, |
2983 | expect![[r#" | 2944 | expect![[r#" |
2984 | 100..104 'self': Self | 2945 | 154..158 'self': &Box<T> |
2985 | 106..110 'args': Args | 2946 | 166..193 '{ ... }': &T |
2986 | 214..218 'self': &Self | 2947 | 176..187 '&self.inner': &*mut T |
2987 | 384..388 'self': &Box<T> | 2948 | 177..181 'self': &Box<T> |
2988 | 396..423 '{ ... }': &T | 2949 | 177..187 'self.inner': *mut T |
2989 | 406..417 '&self.inner': &*mut T | 2950 | 206..296 '{ ...&s); }': () |
2990 | 407..411 'self': &Box<T> | 2951 | 216..217 's': Option<i32> |
2991 | 407..417 'self.inner': *mut T | 2952 | 220..224 'None': Option<i32> |
2992 | 478..576 '{ ...&s); }': () | 2953 | 234..235 'f': Box<dyn FnOnce(&Option<i32>)> |
2993 | 488..489 's': Option<i32> | 2954 | 269..282 'box (|ps| {})': Box<|{unknown}| -> ()> |
2994 | 492..504 'Option::None': Option<i32> | 2955 | 274..281 '|ps| {}': |{unknown}| -> () |
2995 | 514..515 'f': Box<dyn FnOnce(&Option<i32>)> | 2956 | 275..277 'ps': {unknown} |
2996 | 549..562 'box (|ps| {})': Box<|{unknown}| -> ()> | 2957 | 279..281 '{}': () |
2997 | 554..561 '|ps| {}': |{unknown}| -> () | 2958 | 288..289 'f': Box<dyn FnOnce(&Option<i32>)> |
2998 | 555..557 'ps': {unknown} | 2959 | 288..293 'f(&s)': () |
2999 | 559..561 '{}': () | 2960 | 290..292 '&s': &Option<i32> |
3000 | 568..569 'f': Box<dyn FnOnce(&Option<i32>)> | 2961 | 291..292 's': Option<i32> |
3001 | 568..573 'f(&s)': () | 2962 | 269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> |
3002 | 570..572 '&s': &Option<i32> | ||
3003 | 571..572 's': Option<i32> | ||
3004 | 549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()> | ||
3005 | "#]], | 2963 | "#]], |
3006 | ); | 2964 | ); |
3007 | } | 2965 | } |