aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/traits.rs')
-rw-r--r--crates/hir_ty/src/tests/traits.rs80
1 files changed, 72 insertions, 8 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 6ad96bfe3..49add4ab9 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -161,7 +161,7 @@ mod result {
161} 161}
162 162
163#[test] 163#[test]
164fn infer_tryv2() { 164fn infer_try_trait_v2() {
165 check_types( 165 check_types(
166 r#" 166 r#"
167//- /main.rs crate:main deps:core 167//- /main.rs crate:main deps:core
@@ -172,26 +172,41 @@ fn test() {
172} //^ i32 172} //^ i32
173 173
174//- /core.rs crate:core 174//- /core.rs crate:core
175#[prelude_import] use ops::*;
176mod ops { 175mod ops {
177 trait Try { 176 mod try_trait {
178 type Output; 177 pub trait Try: FromResidual {
179 type Residual; 178 type Output;
179 type Residual;
180 }
181 pub trait FromResidual<R = <Self as Try>::Residual> {}
180 } 182 }
183
184 pub use self::try_trait::FromResidual;
185 pub use self::try_trait::Try;
186}
187
188mov convert {
189 pub trait From<T> {}
190 impl<T> From<T> for T {}
181} 191}
182 192
183#[prelude_import] use result::*; 193#[prelude_import] use result::*;
184mod result { 194mod result {
185 enum Infallible {} 195 use crate::convert::From;
186 enum Result<O, E> { 196 use crate::ops::{Try, FromResidual};
197
198 pub enum Infallible {}
199 pub enum Result<O, E> {
187 Ok(O), 200 Ok(O),
188 Err(E) 201 Err(E)
189 } 202 }
190 203
191 impl<O, E> crate::ops::Try for Result<O, E> { 204 impl<O, E> Try for Result<O, E> {
192 type Output = O; 205 type Output = O;
193 type Error = Result<Infallible, E>; 206 type Error = Result<Infallible, E>;
194 } 207 }
208
209 impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
195} 210}
196"#, 211"#,
197 ); 212 );
@@ -3660,3 +3675,52 @@ impl foo::Foo for u32 {
3660 "#]], 3675 "#]],
3661 ); 3676 );
3662} 3677}
3678
3679#[test]
3680fn infer_async_ret_type() {
3681 check_types(
3682 r#"
3683//- /main.rs crate:main deps:core
3684
3685enum Result<T, E> {
3686 Ok(T),
3687 Err(E),
3688}
3689
3690use Result::*;
3691
3692
3693struct Fooey;
3694
3695impl Fooey {
3696 fn collect<B: Convert>(self) -> B {
3697 B::new()
3698 }
3699}
3700
3701trait Convert {
3702 fn new() -> Self;
3703}
3704impl Convert for u32 {
3705 fn new() -> Self {
3706 0
3707 }
3708}
3709
3710async fn get_accounts() -> Result<u32, ()> {
3711 let ret = Fooey.collect();
3712 // ^ u32
3713 Ok(ret)
3714}
3715
3716//- /core.rs crate:core
3717#[prelude_import] use future::*;
3718mod future {
3719 #[lang = "future_trait"]
3720 trait Future {
3721 type Output;
3722 }
3723}
3724"#,
3725 );
3726}