diff options
Diffstat (limited to 'crates/hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 124 |
1 files changed, 19 insertions, 105 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index c830e576e..65fed02d2 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -6,10 +6,10 @@ use super::{check_infer, check_infer_with_mismatches, check_types}; | |||
6 | fn infer_await() { | 6 | fn infer_await() { |
7 | check_types( | 7 | check_types( |
8 | r#" | 8 | r#" |
9 | //- /main.rs crate:main deps:core | 9 | //- minicore: future |
10 | struct IntFuture; | 10 | struct IntFuture; |
11 | 11 | ||
12 | impl Future for IntFuture { | 12 | impl core::future::Future for IntFuture { |
13 | type Output = u64; | 13 | type Output = u64; |
14 | } | 14 | } |
15 | 15 | ||
@@ -18,16 +18,6 @@ fn test() { | |||
18 | let v = r.await; | 18 | let v = r.await; |
19 | v; | 19 | v; |
20 | } //^ u64 | 20 | } //^ u64 |
21 | |||
22 | //- /core.rs crate:core | ||
23 | pub mod prelude { | ||
24 | pub mod rust_2018 { | ||
25 | #[lang = "future_trait"] | ||
26 | pub trait Future { | ||
27 | type Output; | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | "#, | 21 | "#, |
32 | ); | 22 | ); |
33 | } | 23 | } |
@@ -36,25 +26,14 @@ pub mod prelude { | |||
36 | fn infer_async() { | 26 | fn infer_async() { |
37 | check_types( | 27 | check_types( |
38 | r#" | 28 | r#" |
39 | //- /main.rs crate:main deps:core | 29 | //- minicore: future |
40 | async fn foo() -> u64 { | 30 | async fn foo() -> u64 { 128 } |
41 | 128 | ||
42 | } | ||
43 | 31 | ||
44 | fn test() { | 32 | fn test() { |
45 | let r = foo(); | 33 | let r = foo(); |
46 | let v = r.await; | 34 | let v = r.await; |
47 | v; | 35 | v; |
48 | } //^ u64 | 36 | } //^ u64 |
49 | |||
50 | //- /core.rs crate:core | ||
51 | #[prelude_import] use future::*; | ||
52 | mod future { | ||
53 | #[lang = "future_trait"] | ||
54 | trait Future { | ||
55 | type Output; | ||
56 | } | ||
57 | } | ||
58 | "#, | 37 | "#, |
59 | ); | 38 | ); |
60 | } | 39 | } |
@@ -63,24 +42,13 @@ mod future { | |||
63 | fn infer_desugar_async() { | 42 | fn infer_desugar_async() { |
64 | check_types( | 43 | check_types( |
65 | r#" | 44 | r#" |
66 | //- /main.rs crate:main deps:core | 45 | //- minicore: future |
67 | async fn foo() -> u64 { | 46 | async fn foo() -> u64 { 128 } |
68 | 128 | ||
69 | } | ||
70 | 47 | ||
71 | fn test() { | 48 | fn test() { |
72 | let r = foo(); | 49 | let r = foo(); |
73 | r; | 50 | r; |
74 | } //^ impl Future<Output = u64> | 51 | } //^ impl Future<Output = u64> |
75 | |||
76 | //- /core.rs crate:core | ||
77 | #[prelude_import] use future::*; | ||
78 | mod future { | ||
79 | trait Future { | ||
80 | type Output; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | "#, | 52 | "#, |
85 | ); | 53 | ); |
86 | } | 54 | } |
@@ -89,7 +57,7 @@ mod future { | |||
89 | fn infer_async_block() { | 57 | fn infer_async_block() { |
90 | check_types( | 58 | check_types( |
91 | r#" | 59 | r#" |
92 | //- /main.rs crate:main deps:core | 60 | //- minicore: future, option |
93 | async fn test() { | 61 | async fn test() { |
94 | let a = async { 42 }; | 62 | let a = async { 42 }; |
95 | a; | 63 | a; |
@@ -101,7 +69,7 @@ async fn test() { | |||
101 | b; | 69 | b; |
102 | // ^ () | 70 | // ^ () |
103 | let c = async { | 71 | let c = async { |
104 | let y = Option::None; | 72 | let y = None; |
105 | y | 73 | y |
106 | // ^ Option<u64> | 74 | // ^ Option<u64> |
107 | }; | 75 | }; |
@@ -109,18 +77,6 @@ async fn test() { | |||
109 | c; | 77 | c; |
110 | // ^ impl Future<Output = Option<u64>> | 78 | // ^ impl Future<Output = Option<u64>> |
111 | } | 79 | } |
112 | |||
113 | enum Option<T> { None, Some(T) } | ||
114 | |||
115 | //- /core.rs crate:core | ||
116 | #[prelude_import] use future::*; | ||
117 | mod future { | ||
118 | #[lang = "future_trait"] | ||
119 | trait Future { | ||
120 | type Output; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | "#, | 80 | "#, |
125 | ); | 81 | ); |
126 | } | 82 | } |
@@ -704,14 +660,9 @@ mod ops { | |||
704 | fn deref_trait() { | 660 | fn deref_trait() { |
705 | check_types( | 661 | check_types( |
706 | r#" | 662 | r#" |
707 | #[lang = "deref"] | 663 | //- minicore: deref |
708 | trait Deref { | ||
709 | type Target; | ||
710 | fn deref(&self) -> &Self::Target; | ||
711 | } | ||
712 | |||
713 | struct Arc<T>; | 664 | struct Arc<T>; |
714 | impl<T> Deref for Arc<T> { | 665 | impl<T> core::ops::Deref for Arc<T> { |
715 | type Target = T; | 666 | type Target = T; |
716 | } | 667 | } |
717 | 668 | ||
@@ -731,16 +682,10 @@ fn test(s: Arc<S>) { | |||
731 | fn deref_trait_with_inference_var() { | 682 | fn deref_trait_with_inference_var() { |
732 | check_types( | 683 | check_types( |
733 | r#" | 684 | r#" |
734 | //- /main.rs | 685 | //- minicore: deref |
735 | #[lang = "deref"] | ||
736 | trait Deref { | ||
737 | type Target; | ||
738 | fn deref(&self) -> &Self::Target; | ||
739 | } | ||
740 | |||
741 | struct Arc<T>; | 686 | struct Arc<T>; |
742 | fn new_arc<T>() -> Arc<T> {} | 687 | fn new_arc<T>() -> Arc<T> {} |
743 | impl<T> Deref for Arc<T> { | 688 | impl<T> core::ops::Deref for Arc<T> { |
744 | type Target = T; | 689 | type Target = T; |
745 | } | 690 | } |
746 | 691 | ||
@@ -761,15 +706,10 @@ fn test() { | |||
761 | fn deref_trait_infinite_recursion() { | 706 | fn deref_trait_infinite_recursion() { |
762 | check_types( | 707 | check_types( |
763 | r#" | 708 | r#" |
764 | #[lang = "deref"] | 709 | //- minicore: deref |
765 | trait Deref { | ||
766 | type Target; | ||
767 | fn deref(&self) -> &Self::Target; | ||
768 | } | ||
769 | |||
770 | struct S; | 710 | struct S; |
771 | 711 | ||
772 | impl Deref for S { | 712 | impl core::ops::Deref for S { |
773 | type Target = S; | 713 | type Target = S; |
774 | } | 714 | } |
775 | 715 | ||
@@ -784,14 +724,9 @@ fn test(s: S) { | |||
784 | fn deref_trait_with_question_mark_size() { | 724 | fn deref_trait_with_question_mark_size() { |
785 | check_types( | 725 | check_types( |
786 | r#" | 726 | r#" |
787 | #[lang = "deref"] | 727 | //- minicore: deref |
788 | trait Deref { | ||
789 | type Target; | ||
790 | fn deref(&self) -> &Self::Target; | ||
791 | } | ||
792 | |||
793 | struct Arc<T>; | 728 | struct Arc<T>; |
794 | impl<T> Deref for Arc<T> { | 729 | impl<T: ?Sized> core::ops::Deref for Arc<T> { |
795 | type Target = T; | 730 | type Target = T; |
796 | } | 731 | } |
797 | 732 | ||
@@ -2625,12 +2560,9 @@ fn test<T: Trait>() { | |||
2625 | fn dyn_trait_through_chalk() { | 2560 | fn dyn_trait_through_chalk() { |
2626 | check_types( | 2561 | check_types( |
2627 | r#" | 2562 | r#" |
2563 | //- minicore: deref | ||
2628 | struct Box<T> {} | 2564 | struct Box<T> {} |
2629 | #[lang = "deref"] | 2565 | impl<T> core::ops::Deref for Box<T> { |
2630 | trait Deref { | ||
2631 | type Target; | ||
2632 | } | ||
2633 | impl<T> Deref for Box<T> { | ||
2634 | type Target = T; | 2566 | type Target = T; |
2635 | } | 2567 | } |
2636 | trait Trait { | 2568 | trait Trait { |
@@ -3695,16 +3627,7 @@ impl foo::Foo for u32 { | |||
3695 | fn infer_async_ret_type() { | 3627 | fn infer_async_ret_type() { |
3696 | check_types( | 3628 | check_types( |
3697 | r#" | 3629 | r#" |
3698 | //- /main.rs crate:main deps:core | 3630 | //- minicore: future, result |
3699 | |||
3700 | enum Result<T, E> { | ||
3701 | Ok(T), | ||
3702 | Err(E), | ||
3703 | } | ||
3704 | |||
3705 | use Result::*; | ||
3706 | |||
3707 | |||
3708 | struct Fooey; | 3631 | struct Fooey; |
3709 | 3632 | ||
3710 | impl Fooey { | 3633 | impl Fooey { |
@@ -3727,15 +3650,6 @@ async fn get_accounts() -> Result<u32, ()> { | |||
3727 | // ^ u32 | 3650 | // ^ u32 |
3728 | Ok(ret) | 3651 | Ok(ret) |
3729 | } | 3652 | } |
3730 | |||
3731 | //- /core.rs crate:core | ||
3732 | #[prelude_import] use future::*; | ||
3733 | mod future { | ||
3734 | #[lang = "future_trait"] | ||
3735 | trait Future { | ||
3736 | type Output; | ||
3737 | } | ||
3738 | } | ||
3739 | "#, | 3653 | "#, |
3740 | ); | 3654 | ); |
3741 | } | 3655 | } |