aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/tests/regression.rs42
-rw-r--r--crates/hir_ty/src/tests/traits.rs183
2 files changed, 74 insertions, 151 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() {
792fn issue_4966() { 792fn 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() {
567fn infer_ops_index() { 567fn infer_ops_index() {
568 check_types( 568 check_types(
569 r#" 569 r#"
570//- /main.rs crate:main deps:std 570//- minicore: index
571struct Bar; 571struct Bar;
572struct Foo; 572struct Foo;
573 573
574impl std::ops::Index<u32> for Bar { 574impl 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::*;
586mod 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 {
597fn infer_ops_index_int() { 588fn infer_ops_index_int() {
598 check_types( 589 check_types(
599 r#" 590 r#"
600//- /main.rs crate:main deps:std 591//- minicore: index
601struct Bar; 592struct Bar;
602struct Foo; 593struct Foo;
603 594
604impl std::ops::Index<u32> for Bar { 595impl core::ops::Index<u32> for Bar {
605 type Output = Foo; 596 type Output = Foo;
606} 597}
607 598
608struct Range; 599struct Range;
609impl std::ops::Index<Range> for Bar { 600impl 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::*;
622mod 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 {
633fn infer_ops_index_autoderef() { 615fn 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
637fn test() { 619fn 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
644impl<T> ops::Index<u32> for [T] {
645 type Output = T;
646}
647
648#[prelude_import] use ops::*;
649mod 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(); }
884fn generic_param_env_deref() { 853fn generic_param_env_deref() {
885 check_types( 854 check_types(
886 r#" 855 r#"
887#[lang = "deref"] 856//- minicore: deref
888trait Deref {
889 type Target;
890}
891trait Trait {} 857trait Trait {}
892impl<T> Deref for T where T: Trait { 858impl<T> core::ops::Deref for T where T: Trait {
893 type Target = i128; 859 type Target = i128;
894} 860}
895fn test<T: Trait>(t: T) { (*t); } 861fn test<T: Trait>(t: T) { (*t); }
@@ -1758,20 +1724,7 @@ fn test() {
1758fn fn_trait_deref_with_ty_default() { 1724fn fn_trait_deref_with_ty_default() {
1759 check_infer( 1725 check_infer(
1760 r#" 1726 r#"
1761#[lang = "deref"] 1727//- minicore: deref, fn
1762trait Deref {
1763 type Target;
1764
1765 fn deref(&self) -> &Self::Target;
1766}
1767
1768#[lang="fn_once"]
1769trait FnOnce<Args> {
1770 type Output;
1771
1772 fn call_once(self, args: Args) -> Self::Output;
1773}
1774
1775struct Foo; 1728struct Foo;
1776 1729
1777impl Foo { 1730impl 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
1787impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> { 1740impl<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"]
2978pub trait FnOnce<Args> {
2979 type Output;
2980
2981 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
2982}
2983
2984#[lang = "deref"]
2985pub trait Deref {
2986 type Target: ?Sized;
2987
2988 fn deref(&self) -> &Self::Target;
2989}
2990
2991#[lang = "owned_box"] 2926#[lang = "owned_box"]
2992pub struct Box<T: ?Sized> { 2927pub struct Box<T: ?Sized> {
2993 inner: *mut T, 2928 inner: *mut T,
2994} 2929}
2995 2930
2996impl<T: ?Sized> Deref for Box<T> { 2931impl<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
3004enum Option<T> {
3005 None,
3006 Some(T)
3007}
3008
3009fn foo() { 2939fn 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}