diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-29 18:39:15 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-29 18:39:15 +0100 |
commit | f6da603c7fe56c19a275dc7bab1f30fe1ad39707 (patch) | |
tree | 222351c552f11aed7e8f18a5447fc9c15afa42e0 /crates/hir_ty/src | |
parent | 0438e2ceaa89959fe3a1b21e5311a17b08b6fc6d (diff) | |
parent | 54d60fdee9a49e2081837cc6445c61dec0b303af (diff) |
Merge #9050
9050: hir_ty: use async ret type for inference inside async bodies r=flodiebold a=cynecx
Fixes #9004.
Co-authored-by: cynecx <[email protected]>
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/infer.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 49 |
2 files changed, 56 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 8cefd80f3..7a4268819 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -558,7 +558,13 @@ impl<'a> InferenceContext<'a> { | |||
558 | 558 | ||
559 | self.infer_pat(*pat, &ty, BindingMode::default()); | 559 | self.infer_pat(*pat, &ty, BindingMode::default()); |
560 | } | 560 | } |
561 | let return_ty = self.make_ty_with_mode(&data.ret_type, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT | 561 | let error_ty = &TypeRef::Error; |
562 | let return_ty = if data.is_async() { | ||
563 | data.async_ret_type.as_deref().unwrap_or(error_ty) | ||
564 | } else { | ||
565 | &*data.ret_type | ||
566 | }; | ||
567 | let return_ty = self.make_ty_with_mode(return_ty, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT | ||
562 | self.return_ty = return_ty; | 568 | self.return_ty = return_ty; |
563 | } | 569 | } |
564 | 570 | ||
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 6ad96bfe3..7c0ff2170 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -3660,3 +3660,52 @@ impl foo::Foo for u32 { | |||
3660 | "#]], | 3660 | "#]], |
3661 | ); | 3661 | ); |
3662 | } | 3662 | } |
3663 | |||
3664 | #[test] | ||
3665 | fn infer_async_ret_type() { | ||
3666 | check_types( | ||
3667 | r#" | ||
3668 | //- /main.rs crate:main deps:core | ||
3669 | |||
3670 | enum Result<T, E> { | ||
3671 | Ok(T), | ||
3672 | Err(E), | ||
3673 | } | ||
3674 | |||
3675 | use Result::*; | ||
3676 | |||
3677 | |||
3678 | struct Fooey; | ||
3679 | |||
3680 | impl Fooey { | ||
3681 | fn collect<B: Convert>(self) -> B { | ||
3682 | B::new() | ||
3683 | } | ||
3684 | } | ||
3685 | |||
3686 | trait Convert { | ||
3687 | fn new() -> Self; | ||
3688 | } | ||
3689 | impl Convert for u32 { | ||
3690 | fn new() -> Self { | ||
3691 | 0 | ||
3692 | } | ||
3693 | } | ||
3694 | |||
3695 | async fn get_accounts() -> Result<u32, ()> { | ||
3696 | let ret = Fooey.collect(); | ||
3697 | // ^ u32 | ||
3698 | Ok(ret) | ||
3699 | } | ||
3700 | |||
3701 | //- /core.rs crate:core | ||
3702 | #[prelude_import] use future::*; | ||
3703 | mod future { | ||
3704 | #[lang = "future_trait"] | ||
3705 | trait Future { | ||
3706 | type Output; | ||
3707 | } | ||
3708 | } | ||
3709 | "#, | ||
3710 | ); | ||
3711 | } | ||