rust/crates/hir_def/src
bors[bot] 0d03fe6ef5
Merge #5971
5971: Implement async blocks r=flodiebold a=oxalica

Fix #4018

@flodiebold already gave a generic guide in the issue. Here's some concern about implementation detail:
- Chalk doesn't support generator type yet.
- Adding generator type as a brand new type (ctor) can be complex and need to *re-introduced* builtin impls. (Like how we implement closures before native closure support of chalk, which is already removed in #5401 )
- The output type of async block should be known after type inference of the whole body.
  - We cannot directly get the type from source like return-positon-impl-trait. But we still need to provide trait bounds when chalk asking for `opaque_ty_data`.
  - During the inference, the output type of async block can be temporary unknown and participate the later inference.
    `let a = async { None }; let _: i32 = a.await.unwrap();`

So in this PR, the type of async blocks is inferred as an opaque type parameterized by the `Future::Output` type it should be, like what we do with closure type.
And it really works now.

Well, I still have some questions:
- The bounds `AsyncBlockImplType<T>: Future<Output = T>` is currently generated in `opaque_ty_data`. I'm not sure if we should put this code here.
- Type of async block is now rendered as `impl Future<Output = OutputType>`. Do we need to special display to hint that it's a async block? Note that closure type has its special format, instead of `impl Fn(..) -> ..` or function type.



Co-authored-by: oxalica <oxalicc@pm.me>
2020-09-13 17:28:22 +00:00
..
body Merge #5971 2020-09-13 17:28:22 +00:00
item_tree Support extern types 2020-08-24 22:02:55 +02:00
nameres Support extern types 2020-08-24 22:02:55 +02:00
path Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
adt.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
attr.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
body.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
builtin_type.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
child_by_source.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
data.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
db.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
diagnostics.rs Add type safety to diagnostic codes 2020-08-18 18:39:43 +02:00
docs.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
dyn_map.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
expr.rs Merge #5971 2020-09-13 17:28:22 +00:00
find_path.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
generics.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
import_map.rs Switch to expect_test from crates.io 2020-08-21 13:19:31 +02:00
item_scope.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
item_tree.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
keys.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
lang_item.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
lib.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
nameres.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
path.rs Remove deprecated Path::from_ast 2020-08-15 18:22:16 +02:00
per_ns.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
resolver.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
src.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
test_db.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
trace.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
type_ref.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
visibility.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00