hir_ty: use async ret type for inference inside async bodies

This commit is contained in:
cynecx 2021-05-29 18:16:20 +02:00
parent 3fa3343e47
commit 54d60fdee9
6 changed files with 65 additions and 4 deletions

View file

@ -558,7 +558,13 @@ impl<'a> InferenceContext<'a> {
self.infer_pat(*pat, &ty, BindingMode::default());
}
let return_ty = self.make_ty_with_mode(&data.ret_type, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT
let error_ty = &TypeRef::Error;
let return_ty = if data.is_async() {
data.async_ret_type.as_deref().unwrap_or(error_ty)
} else {
&*data.ret_type
};
let return_ty = self.make_ty_with_mode(return_ty, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT
self.return_ty = return_ty;
}

View file

@ -3660,3 +3660,52 @@ impl foo::Foo for u32 {
"#]],
);
}
#[test]
fn infer_async_ret_type() {
check_types(
r#"
//- /main.rs crate:main deps:core
enum Result<T, E> {
Ok(T),
Err(E),
}
use Result::*;
struct Fooey;
impl Fooey {
fn collect<B: Convert>(self) -> B {
B::new()
}
}
trait Convert {
fn new() -> Self;
}
impl Convert for u32 {
fn new() -> Self {
0
}
}
async fn get_accounts() -> Result<u32, ()> {
let ret = Fooey.collect();
// ^ u32
Ok(ret)
}
//- /core.rs crate:core
#[prelude_import] use future::*;
mod future {
#[lang = "future_trait"]
trait Future {
type Output;
}
}
"#,
);
}